buildinfo: track Version and Dockerfile separately

And don't hard-code VERSION info in the Dockerfile.

Change-Id: I35cb22fbb56cd634be4f1342c54ca86ce0e79901
This commit is contained in:
Brad Fitzpatrick 2018-05-02 13:35:23 -07:00
parent 9f65efad5a
commit 46bb719dc5
13 changed files with 56 additions and 28 deletions

View File

@ -1,3 +1,3 @@
.git*
bin/*
tmp/*
misc/docker/release/*

View File

@ -39,7 +39,8 @@ WORKDIR $GOPATH
# Add each directory separately, so our context doesn't include the
# Dockerfile itself, to permit quicker iteration with docker's
# caching.
ADD app /go/src/perkeep.org/app
ADD .git /go/src/perkeep.org/.git
add app /go/src/perkeep.org/app
ADD clients /go/src/perkeep.org/clients
ADD cmd /go/src/perkeep.org/cmd
ADD config /go/src/perkeep.org/config
@ -51,15 +52,19 @@ ADD server /go/src/perkeep.org/server
ADD vendor /go/src/perkeep.org/vendor
ADD website /go/src/perkeep.org/website
ADD make.go /go/src/perkeep.org/make.go
ADD VERSION /go/src/perkeep.org/VERSION
WORKDIR /go/src/perkeep.org
RUN echo "0.10" > VERSION
RUN go run make.go --sqlite=true -v
FROM debian:stretch
RUN apt-get update && apt-get install -y --no-install-recommends \
libsqlite3-dev && rm -rf /var/lib/apt/lists/*
RUN mkdir -p /home/keepy/bin
ENV HOME /home/keepy
ENV PATH /home/keepy/bin:$PATH

View File

@ -73,11 +73,11 @@ func main() {
if *flagVersion {
fmt.Fprintf(os.Stderr, "hello version: %s\nGo version: %s (%s/%s)\n",
buildinfo.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
buildinfo.Summary(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
return
}
log.Printf("Starting hello version %s; Go %s (%s/%s)", buildinfo.Version(), runtime.Version(),
log.Printf("Starting hello version %s; Go %s (%s/%s)", buildinfo.Summary(), runtime.Version(),
runtime.GOOS, runtime.GOARCH)
listenAddr, err := app.ListenAddress()

View File

@ -270,11 +270,11 @@ func main() {
if *flagVersion {
fmt.Fprintf(os.Stderr, "publisher version: %s\nGo version: %s (%s/%s)\n",
buildinfo.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
buildinfo.Summary(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
return
}
logf("Starting publisher version %s; Go %s (%s/%s)", buildinfo.Version(), runtime.Version(),
logf("Starting publisher version %s; Go %s (%s/%s)", buildinfo.Summary(), runtime.Version(),
runtime.GOOS, runtime.GOARCH)
listenAddr, err := app.ListenAddress()

View File

@ -60,12 +60,12 @@ func main() {
if *flagVersion {
fmt.Fprintf(os.Stderr, "WARNING: THIS APP IS STILL EXPERIMENTAL, AND EVEN ITS DATA SCHEMA MIGHT CHANGE. DO NOT USE IN PRODUCTION.")
fmt.Fprintf(os.Stderr, "scanningcabinet version: %s\nGo version: %s (%s/%s)\n",
buildinfo.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
buildinfo.Summary(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
return
}
logf("WARNING: THIS APP IS STILL EXPERIMENTAL, AND EVEN ITS DATA SCHEMA MIGHT CHANGE. DO NOT USE IN PRODUCTION.")
logf("Starting scanning cabinet version %s; Go %s (%s/%s)", buildinfo.Version(), runtime.Version(),
logf("Starting scanning cabinet version %s; Go %s (%s/%s)", buildinfo.Summary(), runtime.Version(),
runtime.GOOS, runtime.GOARCH)
listenAddr, err := app.ListenAddress()

View File

@ -479,7 +479,7 @@ func main() {
checkSanity()
if *flagVersion {
fmt.Fprintf(os.Stderr, "scancab version: %s\n", buildinfo.Version())
fmt.Fprintf(os.Stderr, "scancab version: %s\n", buildinfo.Summary())
return
}

View File

@ -70,7 +70,7 @@ func main() {
}
if *flagVersion {
fmt.Fprintf(os.Stderr, "pk-get version: %s\n", buildinfo.Version())
fmt.Fprintf(os.Stderr, "pk-get version: %s\n", buildinfo.Summary())
return
}

28
make.go
View File

@ -95,10 +95,11 @@ func main() {
verifyGoVersion()
verifyPerkeepRoot()
version := getVersion()
gitRev := getGitVersion()
sql := withSQLite()
if *verbose {
log.Printf("Perkeep version = %s", version)
log.Printf("Perkeep version = %q, git = %q", version, gitRev)
log.Printf("SQLite included: %v", sql)
log.Printf("Project source: %s", pkRoot)
log.Printf("Output binaries: %s", actualBinDir())
@ -184,7 +185,7 @@ func main() {
baseArgs = append(baseArgs, "-race")
}
if *verbose {
log.Printf("version to stamp is %q", version)
log.Printf("version to stamp is %q, %q", version, gitRev)
}
var ldFlags string
if *static {
@ -194,7 +195,8 @@ func main() {
if ldFlags != "" {
ldFlags += " "
}
ldFlags += "-X \"perkeep.org/pkg/buildinfo.GitInfo=" + version + "\""
ldFlags += "-X \"perkeep.org/pkg/buildinfo.GitInfo=" + gitRev + "\""
ldFlags += "-X \"perkeep.org/pkg/buildinfo.Version=" + version + "\""
}
if ldFlags != "" {
baseArgs = append(baseArgs, "--ldflags="+ldFlags)
@ -646,18 +648,28 @@ func buildBin(pkg string) error {
// or from git.
func getVersion() string {
slurp, err := ioutil.ReadFile(filepath.Join(pkRoot, "VERSION"))
if err == nil {
return strings.TrimSpace(string(slurp))
v := strings.TrimSpace(string(slurp))
if err != nil && !os.IsNotExist(err) {
log.Fatal(err)
}
return gitVersion()
if v == "" {
return "unknown"
}
return v
}
var gitVersionRx = regexp.MustCompile(`\b\d\d\d\d-\d\d-\d\d-[0-9a-f]{10,10}\b`)
// gitVersion returns the git version of the git repo at pkRoot as a
// getGitVersion returns the git version of the git repo at pkRoot as a
// string of the form "yyyy-mm-dd-xxxxxxx", with an optional trailing
// '+' if there are any local uncommitted modifications to the tree.
func gitVersion() string {
func getGitVersion() string {
if _, err := exec.LookPath("git"); err != nil {
return ""
}
if _, err := os.Stat(filepath.Join(pkRoot, ".git")); os.IsNotExist(err) {
return ""
}
cmd := exec.Command("git", "rev-list", "--max-count=1", "--pretty=format:'%ad-%h'",
"--date=short", "--abbrev=10", "HEAD")
cmd.Dir = pkRoot

View File

@ -25,12 +25,21 @@ import "flag"
// $ go install --ldflags="-X camlistore.org/pkg/buildinfo.GitInfo "`./misc/gitversion` camlistore.org/server/perkeepd
var GitInfo string
// Version returns the git version of this binary.
// Version is a string like "0.10" or "1.0", if applicable.
var Version string
// Summary returns the version and/or git version of this binary.
// If the linker flags were not provided, the return value is "unknown".
func Version() string {
func Summary() string {
if Version != "" && GitInfo != "" {
return Version + ", " + GitInfo
}
if GitInfo != "" {
return GitInfo
}
if Version != "" {
return Version
}
return "unknown"
}

View File

@ -879,8 +879,8 @@ func (c *Client) SearchExistingFileSchema(ctx context.Context, wholeRef ...blob.
// the client was built at or after 2018-01-13.
func (c *Client) versionMismatch(ctx context.Context) (bool, error) {
const shortRFC3339 = "2006-01-02"
version := buildinfo.Version()
if version == "unknown" {
version := buildinfo.GitInfo
if version == "" {
return false, errors.New("unknown client version")
}
version = version[:10] // keep only the date part

View File

@ -19,6 +19,7 @@ package server
import (
"encoding/json"
"fmt"
"html"
"log"
"net/http"
"sort"
@ -208,7 +209,8 @@ func (rh *RootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, p, a...)
}
f("<html><body><p>This is perkeepd (%s), a "+
"<a href='http://perkeep.org'>Perkeep</a> server.</p>", buildinfo.Version())
"<a href='http://perkeep.org'>Perkeep</a> server.</p>",
html.EscapeString(buildinfo.Summary()))
if rh.ui != nil {
f("<p>To manage your content, access the <a href='%s'>%s</a>.</p>", rh.ui.prefix, rh.ui.prefix)
}

View File

@ -156,7 +156,7 @@ type storageStatus struct {
func (sh *StatusHandler) currentStatus() *status {
res := &status{
Version: buildinfo.Version(),
Version: buildinfo.Summary(),
GoInfo: fmt.Sprintf("%s %s/%s cgo=%v", runtime.Version(), runtime.GOOS, runtime.GOARCH, cgoEnabled),
Storage: make(map[string]storageStatus),
Sync: make(map[string]syncStatus),
@ -246,7 +246,7 @@ func (sh *StatusHandler) serveStatusHTML(rw http.ResponseWriter, req *http.Reque
if env.OnGCE() {
envStr = " (on GCE)"
}
f("<li><b>Perkeep</b>: %s%s</li>", html.EscapeString(buildinfo.Version()), envStr)
f("<li><b>Perkeep</b>: %s%s</li>", html.EscapeString(buildinfo.Summary()), envStr)
f("<li><b>Go</b>: %s/%s %s, cgo=%v</li>", runtime.GOOS, runtime.GOARCH, runtime.Version(), cgoEnabled)
f("<li><b>djpeg</b>: %s", html.EscapeString(buildinfo.DjpegStatus()))
f("</ul>")

View File

@ -901,7 +901,7 @@ func Main(up chan<- struct{}, down <-chan struct{}) {
if *flagVersion {
fmt.Fprintf(os.Stderr, "perkeepd version: %s\nGo version: %s (%s/%s)\n",
buildinfo.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
buildinfo.Summary(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
return
}
if *flagHelp {
@ -932,7 +932,7 @@ func Main(up chan<- struct{}, down <-chan struct{}) {
}
}()
log.Printf("Starting perkeepd version %s; Go %s (%s/%s)", buildinfo.Version(), runtime.Version(),
log.Printf("Starting perkeepd version %s; Go %s (%s/%s)", buildinfo.Summary(), runtime.Version(),
runtime.GOOS, runtime.GOARCH)
shutdownc := make(chan io.Closer, 1) // receives io.Closer to cleanly shut down