From c4406baf8abfb699e3b9283e9476b3b9a5a52060 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 29 Jan 2015 15:30:53 -0800 Subject: [PATCH 1/5] Update AUTHORS file Signed-off-by: Stephen J Day --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 842a13bf..007d001a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,4 @@ Brian Bland Josh Hawn Olivier Gambier Stephen J Day +Tianon Gravi From d0abfe0b92f865ee991a3124d40c15aea31eff3b Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 29 Jan 2015 15:32:49 -0800 Subject: [PATCH 2/5] Report version in registry binary We've added support to the registry command to report the current version of the distribution package. The version package is generated with a shell script that gets the latest tag and add "+unknown". This allows builds from "go get" and "go install" to have a rough version number. Generated periodically, it will provide a decent indication of what code built the binary. For more accurate versioning, one can build with the "binaries" make target. Linker flags are used to replace the version string with the actual current tag at build time. Signed-off-by: Stephen J Day --- .gitignore | 3 +++ Makefile | 23 +++++++++++++++++------ cmd/registry/main.go | 17 +++++++++++++++++ version/version.go | 11 +++++++++++ version/version.sh | 22 ++++++++++++++++++++++ 5 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 version/version.go create mode 100755 version/version.sh diff --git a/.gitignore b/.gitignore index daf913b1..306a8fba 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ _testmain.go *.exe *.test *.prof + +# never checkin from the bin file (for now) +bin/* diff --git a/Makefile b/Makefile index d853daca..e3477e83 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,26 @@ -# This project makefile is around for generating peices of documentation and -# code. For most purposes, running it is not necessary. +# Set an output prefix, which is the local directory if not specified +PREFIX?=$(shell pwd) -.PHONY: clean +# Used to populate version variable in main package. +GO_LDFLAGS=-ldflags "-X `go list ./version`.Version `git describe --match 'v[0-9]*' --dirty='.m' --always`" + +.PHONY: clean binaries .DEFAULT: default default: - @echo Please read the make targets before using this Makefile. It is \ - currently only used for documentation and autogenerated files. + @echo Please read the make targets before using this Makefile. AUTHORS: .mailmap .git/ORIG_HEAD .git/FETCH_HEAD .git/HEAD git log --format='%aN <%aE>' | sort -fu >> $@ +# This only needs to be generated by hand when cutting full releases. +version/version.go: + ./version/version.sh > $@ + +${PREFIX}/bin/registry: version/version.go $(shell find . -type f -name '*.go') + go build -o $@ ${GO_LDFLAGS} ./cmd/registry + +binaries: ${PREFIX}/bin/registry + clean: - rm -rf AUTHORS \ No newline at end of file + rm -rf ${PREFIX}/bin/registry diff --git a/cmd/registry/main.go b/cmd/registry/main.go index 436b8f77..c19a122f 100644 --- a/cmd/registry/main.go +++ b/cmd/registry/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "io" "net/http" _ "net/http/pprof" "os" @@ -19,12 +20,24 @@ import ( _ "github.com/docker/distribution/storagedriver/filesystem" _ "github.com/docker/distribution/storagedriver/inmemory" _ "github.com/docker/distribution/storagedriver/s3" + "github.com/docker/distribution/version" ) +var showVersion bool + +func init() { + flag.BoolVar(&showVersion, "version", false, "show the version and exit") +} + func main() { flag.Usage = usage flag.Parse() + if showVersion { + printVersion(os.Stdout) + return + } + config, err := resolveConfiguration() if err != nil { fatalf("configuration error: %v", err) @@ -46,6 +59,10 @@ func usage() { flag.PrintDefaults() } +func printVersion(w io.Writer) { + fmt.Fprintln(w, os.Args[0], version.Package, version.Version) +} + func fatalf(format string, args ...interface{}) { fmt.Fprintf(os.Stderr, format+"\n", args...) usage() diff --git a/version/version.go b/version/version.go new file mode 100644 index 00000000..2e96cd68 --- /dev/null +++ b/version/version.go @@ -0,0 +1,11 @@ +package version + +// Package is the overall, canonical project import path under which the +// package was built. +var Package = "github.com/docker/distribution" + +// Version indicates which version of the binary is running. This is set to +// the latest release tag by hand, always suffixed by "+unknown". During +// build, it will be replaced by the actual version. The value here will be +// used if the registry is run after a go get based install. +var Version = "v2.0.0-alpha.1+unknown" diff --git a/version/version.sh b/version/version.sh new file mode 100755 index 00000000..53e29ce9 --- /dev/null +++ b/version/version.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# This bash script outputs the current, desired content of version.go, using +# git describe. For best effect, pipe this to the target file. Generally, this +# only needs to updated for releases. The actual value of will be replaced +# during build time if the makefile is used. + +set -e + +cat < Date: Thu, 29 Jan 2015 15:37:22 -0800 Subject: [PATCH 3/5] Update Dockerfile to use Makefile to build binary Signed-off-by: Stephen J Day --- Dockerfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30363eae..881bb90d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,13 @@ FROM golang:1.4 ENV CONFIG_PATH /etc/docker/registry/config.yml -RUN mkdir -pv "$(dirname $CONFIG_PATH)" - ENV DISTRIBUTION_DIR /go/src/github.com/docker/distribution +ENV GOPATH $DISTRIBUTION_DIR/Godeps/_workspace:$GOPATH + WORKDIR $DISTRIBUTION_DIR COPY . $DISTRIBUTION_DIR -ENV GOPATH $GOPATH:$DISTRIBUTION_DIR/Godeps/_workspace - -RUN go install -v ./cmd/registry - +RUN make PREFIX=/go clean binaries +RUN mkdir -pv "$(dirname $CONFIG_PATH)" RUN cp -lv ./cmd/registry/config.yml $CONFIG_PATH EXPOSE 5000 From b75455d2bd09b48cf55952562eeb82d6a516199c Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Thu, 29 Jan 2015 15:53:26 -0800 Subject: [PATCH 4/5] Move version printing to version package Signed-off-by: Stephen J Day --- cmd/registry/main.go | 7 +------ version/print.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 version/print.go diff --git a/cmd/registry/main.go b/cmd/registry/main.go index c19a122f..c3c5d728 100644 --- a/cmd/registry/main.go +++ b/cmd/registry/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "io" "net/http" _ "net/http/pprof" "os" @@ -34,7 +33,7 @@ func main() { flag.Parse() if showVersion { - printVersion(os.Stdout) + version.PrintVersion() return } @@ -59,10 +58,6 @@ func usage() { flag.PrintDefaults() } -func printVersion(w io.Writer) { - fmt.Fprintln(w, os.Args[0], version.Package, version.Version) -} - func fatalf(format string, args ...interface{}) { fmt.Fprintf(os.Stderr, format+"\n", args...) usage() diff --git a/version/print.go b/version/print.go new file mode 100644 index 00000000..a82bce39 --- /dev/null +++ b/version/print.go @@ -0,0 +1,26 @@ +package version + +import ( + "fmt" + "io" + "os" +) + +// FprintVersion outputs the version string to the writer, in the following +// format, followed by a newline: +// +// +// +// For example, a binary "registry" built from github.com/docker/distribution +// with version "v2.0" would print the following: +// +// registry github.com/docker/distribution v2.0 +// +func FprintVersion(w io.Writer) { + fmt.Fprintln(w, os.Args[0], Package, Version) +} + +// PrintVersion outputs the version information, from Fprint, to stdout. +func PrintVersion() { + FprintVersion(os.Stdout) +} From 9abefef2a39a6be7a1a9c2b3f068b789e7b75e0c Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Fri, 30 Jan 2015 11:13:45 -0800 Subject: [PATCH 5/5] Quote argument in Makefile clean target Signed-off-by: Stephen J Day --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e3477e83..b324e3fe 100644 --- a/Makefile +++ b/Makefile @@ -23,4 +23,4 @@ ${PREFIX}/bin/registry: version/version.go $(shell find . -type f -name '*.go') binaries: ${PREFIX}/bin/registry clean: - rm -rf ${PREFIX}/bin/registry + rm -rf "${PREFIX}/bin/registry"