diff --git a/.dockerignore b/.dockerignore index 9678d19e5..e14324810 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,3 @@ -.git* bin/* tmp/* +misc/docker/release/* diff --git a/Dockerfile b/Dockerfile index ac481c72e..ba93313a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/app/hello/main.go b/app/hello/main.go index 46c6f69f2..e2e028900 100644 --- a/app/hello/main.go +++ b/app/hello/main.go @@ -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() diff --git a/app/publisher/main.go b/app/publisher/main.go index 5356b30da..59aaf4011 100644 --- a/app/publisher/main.go +++ b/app/publisher/main.go @@ -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() diff --git a/app/scanningcabinet/main.go b/app/scanningcabinet/main.go index b77f82dcb..24399083b 100644 --- a/app/scanningcabinet/main.go +++ b/app/scanningcabinet/main.go @@ -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() diff --git a/app/scanningcabinet/scancab/scancab.go b/app/scanningcabinet/scancab/scancab.go index 2e8e33f2d..56547c10f 100644 --- a/app/scanningcabinet/scancab/scancab.go +++ b/app/scanningcabinet/scancab/scancab.go @@ -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 } diff --git a/cmd/pk-get/get.go b/cmd/pk-get/get.go index 07b46477f..b7f325e9a 100644 --- a/cmd/pk-get/get.go +++ b/cmd/pk-get/get.go @@ -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 } diff --git a/make.go b/make.go index 1c7ca105d..fd792477f 100644 --- a/make.go +++ b/make.go @@ -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 diff --git a/pkg/buildinfo/buildinfo.go b/pkg/buildinfo/buildinfo.go index c3cfa01d0..859c880dc 100644 --- a/pkg/buildinfo/buildinfo.go +++ b/pkg/buildinfo/buildinfo.go @@ -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" } diff --git a/pkg/client/client.go b/pkg/client/client.go index 3c19c2f30..679b1fda3 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -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 diff --git a/pkg/server/root.go b/pkg/server/root.go index 1c00d62a7..d6335e0ac 100644 --- a/pkg/server/root.go +++ b/pkg/server/root.go @@ -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("

This is perkeepd (%s), a "+ - "Perkeep server.

", buildinfo.Version()) + "Perkeep server.

", + html.EscapeString(buildinfo.Summary())) if rh.ui != nil { f("

To manage your content, access the %s.

", rh.ui.prefix, rh.ui.prefix) } diff --git a/pkg/server/status.go b/pkg/server/status.go index 7453d96f5..87b6ceded 100644 --- a/pkg/server/status.go +++ b/pkg/server/status.go @@ -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("
  • Perkeep: %s%s
  • ", html.EscapeString(buildinfo.Version()), envStr) + f("
  • Perkeep: %s%s
  • ", html.EscapeString(buildinfo.Summary()), envStr) f("
  • Go: %s/%s %s, cgo=%v
  • ", runtime.GOOS, runtime.GOARCH, runtime.Version(), cgoEnabled) f("
  • djpeg: %s", html.EscapeString(buildinfo.DjpegStatus())) f("") diff --git a/server/perkeepd/camlistored.go b/server/perkeepd/camlistored.go index 1be56a6e0..2a2b939ba 100644 --- a/server/perkeepd/camlistored.go +++ b/server/perkeepd/camlistored.go @@ -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