From ef486c66301274afc749d61f6b7f08da68230a04 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 11 Feb 2014 16:05:45 -0800 Subject: [PATCH 1/4] Move docker version introspection to a sub-package. This facilitates the refactoring of commands.go. Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: ae3c7dec3b075a263da8d1e1cc510275b281e799 Component: engine --- components/engine/commands.go | 5 ----- components/engine/docker/docker.go | 12 +++--------- components/engine/dockerversion/dockerversion.go | 11 +++++++++++ components/engine/hack/make.sh | 2 +- components/engine/version.go | 9 +++++++++ 5 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 components/engine/dockerversion/dockerversion.go diff --git a/components/engine/commands.go b/components/engine/commands.go index cc019f8c10..55cb3e21c7 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -38,11 +38,6 @@ import ( "time" ) -var ( - GITCOMMIT string - VERSION string -) - var ( ErrConnectionRefused = errors.New("Can't connect to docker daemon. Is 'docker -d' running on this host?") ) diff --git a/components/engine/docker/docker.go b/components/engine/docker/docker.go index d92f4d98ea..df99a20450 100644 --- a/components/engine/docker/docker.go +++ b/components/engine/docker/docker.go @@ -8,17 +8,13 @@ import ( "github.com/dotcloud/docker" "github.com/dotcloud/docker/api" + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/engine" flag "github.com/dotcloud/docker/pkg/mflag" "github.com/dotcloud/docker/sysinit" "github.com/dotcloud/docker/utils" ) -var ( - GITCOMMIT string - VERSION string -) - func main() { if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" { // Running in init mode @@ -71,8 +67,6 @@ func main() { if *flDebug { os.Setenv("DEBUG", "1") } - docker.GITCOMMIT = GITCOMMIT - docker.VERSION = VERSION if *flDaemon { if flag.NArg() != 0 { flag.Usage() @@ -104,7 +98,7 @@ func main() { job = eng.Job("serveapi", flHosts.GetAll()...) job.SetenvBool("Logging", true) job.SetenvBool("EnableCors", *flEnableCors) - job.Setenv("Version", VERSION) + job.Setenv("Version", dockerversion.VERSION) if err := job.Run(); err != nil { log.Fatal(err) } @@ -126,5 +120,5 @@ func main() { } func showVersion() { - fmt.Printf("Docker version %s, build %s\n", VERSION, GITCOMMIT) + fmt.Printf("Docker version %s, build %s\n", dockerversion.VERSION, dockerversion.GITCOMMIT) } diff --git a/components/engine/dockerversion/dockerversion.go b/components/engine/dockerversion/dockerversion.go new file mode 100644 index 0000000000..1872691ed2 --- /dev/null +++ b/components/engine/dockerversion/dockerversion.go @@ -0,0 +1,11 @@ +package dockerversion + +// FIXME: this should be embedded in the docker/docker.go, +// but we can't because distro policy requires us to +// package a separate dockerinit binary, and that binary needs +// to know its version too. + +var ( + GITCOMMIT string + VERSION string +) diff --git a/components/engine/hack/make.sh b/components/engine/hack/make.sh index d73b33a4fa..011b796201 100755 --- a/components/engine/hack/make.sh +++ b/components/engine/hack/make.sh @@ -82,7 +82,7 @@ if [ ! "$GOPATH" ]; then fi # Use these flags when compiling the tests and final binary -LDFLAGS='-X main.GITCOMMIT "'$GITCOMMIT'" -X main.VERSION "'$VERSION'" -w' +LDFLAGS='-X github.com/dotcloud/docker/dockerversion.GITCOMMIT "'$GITCOMMIT'" -X github.com/dotcloud/docker/dockerversion.VERSION "'$VERSION'" -w' LDFLAGS_STATIC='-X github.com/dotcloud/docker/utils.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"' BUILDFLAGS='-tags netgo -a' diff --git a/components/engine/version.go b/components/engine/version.go index a4288245f7..2eee68c2f2 100644 --- a/components/engine/version.go +++ b/components/engine/version.go @@ -1,11 +1,20 @@ package docker import ( + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/engine" "github.com/dotcloud/docker/utils" "runtime" ) +var ( + // FIXME: this is a convenience indirection to preserve legacy + // code. It can be removed by using dockerversion.VERSION and + // dockerversion.GITCOMMIT directly + GITCOMMIT string = dockerversion.GITCOMMIT + VERSION string = dockerversion.VERSION +) + func init() { engine.Register("version", jobVersion) } From 9ed97b673b0a73d0703c8b999d0a780c117b0be7 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Tue, 11 Feb 2014 17:26:54 -0700 Subject: [PATCH 2/4] Move even more stuff into dockerversion Also, use it in all the places. :) Docker-DCO-1.1-Signed-off-by: Andrew Page (github: tianon) Upstream-commit: da04f49b383c02ee28c32f948048b9e9a402bb4f Component: engine --- components/engine/commands.go | 17 +++++++++-------- components/engine/dockerinit/dockerinit.go | 5 ----- .../engine/dockerversion/dockerversion.go | 4 ++++ components/engine/graph.go | 3 ++- components/engine/hack/make/dynbinary | 2 +- components/engine/runtime.go | 3 ++- components/engine/server.go | 3 ++- components/engine/utils/utils.go | 13 ++++--------- components/engine/version.go | 12 ++---------- 9 files changed, 26 insertions(+), 36 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index 55cb3e21c7..651173555e 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -11,6 +11,7 @@ import ( "github.com/dotcloud/docker/api" "github.com/dotcloud/docker/archive" "github.com/dotcloud/docker/auth" + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/engine" flag "github.com/dotcloud/docker/pkg/mflag" "github.com/dotcloud/docker/pkg/sysinfo" @@ -383,12 +384,12 @@ func (cli *DockerCli) CmdVersion(args ...string) error { cmd.Usage() return nil } - if VERSION != "" { - fmt.Fprintf(cli.out, "Client version: %s\n", VERSION) + if dockerversion.VERSION != "" { + fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION) } fmt.Fprintf(cli.out, "Go version (client): %s\n", runtime.Version()) - if GITCOMMIT != "" { - fmt.Fprintf(cli.out, "Git commit (client): %s\n", GITCOMMIT) + if dockerversion.GITCOMMIT != "" { + fmt.Fprintf(cli.out, "Git commit (client): %s\n", dockerversion.GITCOMMIT) } body, _, err := readBody(cli.call("GET", "/version", nil, false)) @@ -413,7 +414,7 @@ func (cli *DockerCli) CmdVersion(args ...string) error { release := utils.GetReleaseVersion() if release != "" { fmt.Fprintf(cli.out, "Last stable version: %s", release) - if (VERSION != "" || remoteVersion.Exists("Version")) && (strings.Trim(VERSION, "-dev") != release || strings.Trim(remoteVersion.Get("Version"), "-dev") != release) { + if (dockerversion.VERSION != "" || remoteVersion.Exists("Version")) && (strings.Trim(dockerversion.VERSION, "-dev") != release || strings.Trim(remoteVersion.Get("Version"), "-dev") != release) { fmt.Fprintf(cli.out, ", please update docker") } fmt.Fprintf(cli.out, "\n") @@ -2298,7 +2299,7 @@ func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo b } } } - req.Header.Set("User-Agent", "Docker-Client/"+VERSION) + req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION) req.Host = cli.addr if data != nil { req.Header.Set("Content-Type", "application/json") @@ -2355,7 +2356,7 @@ func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer, h if err != nil { return err } - req.Header.Set("User-Agent", "Docker-Client/"+VERSION) + req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION) req.Host = cli.addr if method == "POST" { req.Header.Set("Content-Type", "plain/text") @@ -2419,7 +2420,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea if err != nil { return err } - req.Header.Set("User-Agent", "Docker-Client/"+VERSION) + req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION) req.Header.Set("Content-Type", "plain/text") req.Host = cli.addr diff --git a/components/engine/dockerinit/dockerinit.go b/components/engine/dockerinit/dockerinit.go index 0c363f4ac3..1d0689387a 100644 --- a/components/engine/dockerinit/dockerinit.go +++ b/components/engine/dockerinit/dockerinit.go @@ -4,11 +4,6 @@ import ( "github.com/dotcloud/docker/sysinit" ) -var ( - GITCOMMIT string - VERSION string -) - func main() { // Running in init mode sysinit.SysInit() diff --git a/components/engine/dockerversion/dockerversion.go b/components/engine/dockerversion/dockerversion.go index 1872691ed2..c130ac2810 100644 --- a/components/engine/dockerversion/dockerversion.go +++ b/components/engine/dockerversion/dockerversion.go @@ -8,4 +8,8 @@ package dockerversion var ( GITCOMMIT string VERSION string + + IAMSTATIC bool // whether or not Docker itself was compiled statically via ./hack/make.sh binary + INITSHA1 string // sha1sum of separate static dockerinit, if Docker itself was compiled dynamically via ./hack/make.sh dynbinary + INITPATH string // custom location to search for a valid dockerinit binary (available for packagers as a last resort escape hatch) ) diff --git a/components/engine/graph.go b/components/engine/graph.go index 42da42c8af..138c7b8613 100644 --- a/components/engine/graph.go +++ b/components/engine/graph.go @@ -3,6 +3,7 @@ package docker import ( "fmt" "github.com/dotcloud/docker/archive" + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/graphdriver" "github.com/dotcloud/docker/utils" "io" @@ -130,7 +131,7 @@ func (graph *Graph) Create(layerData archive.Archive, container *Container, comm ID: GenerateID(), Comment: comment, Created: time.Now().UTC(), - DockerVersion: VERSION, + DockerVersion: dockerversion.VERSION, Author: author, Config: config, Architecture: runtime.GOARCH, diff --git a/components/engine/hack/make/dynbinary b/components/engine/hack/make/dynbinary index c02094c0c5..7de3a6cb59 100644 --- a/components/engine/hack/make/dynbinary +++ b/components/engine/hack/make/dynbinary @@ -12,6 +12,6 @@ export DOCKER_INITSHA1="$(sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)" # exported so that "dyntest" can easily access it later without recalculating it ( - export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/utils.INITPATH \"$DOCKER_INITPATH\"" + export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\"" source "$(dirname "$BASH_SOURCE")/binary" ) diff --git a/components/engine/runtime.go b/components/engine/runtime.go index 176f51b0b1..cec5444090 100644 --- a/components/engine/runtime.go +++ b/components/engine/runtime.go @@ -4,6 +4,7 @@ import ( "container/list" "fmt" "github.com/dotcloud/docker/archive" + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/engine" "github.com/dotcloud/docker/execdriver" "github.com/dotcloud/docker/execdriver/chroot" @@ -678,7 +679,7 @@ func NewRuntimeFromDirectory(config *DaemonConfig, eng *engine.Engine) (*Runtime return nil, err } - localCopy := path.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", VERSION)) + localCopy := path.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", dockerversion.VERSION)) sysInitPath := utils.DockerInitPath(localCopy) if sysInitPath == "" { return nil, fmt.Errorf("Could not locate dockerinit: This usually means docker was built incorrectly. See http://docs.docker.io/en/latest/contributing/devenvironment for official build instructions.") diff --git a/components/engine/server.go b/components/engine/server.go index f108f61740..cb677266e5 100644 --- a/components/engine/server.go +++ b/components/engine/server.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/dotcloud/docker/archive" "github.com/dotcloud/docker/auth" + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/engine" "github.com/dotcloud/docker/pkg/graphdb" "github.com/dotcloud/docker/registry" @@ -827,7 +828,7 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status { v.SetInt("NEventsListener", len(srv.events)) v.Set("KernelVersion", kernelVersion) v.Set("IndexServerAddress", auth.IndexServerAddress()) - v.Set("InitSha1", utils.INITSHA1) + v.Set("InitSha1", dockerversion.INITSHA1) v.Set("InitPath", initPath) if _, err := v.WriteTo(job.Stdout); err != nil { return job.Error(err) diff --git a/components/engine/utils/utils.go b/components/engine/utils/utils.go index 5caf792549..60952606d5 100644 --- a/components/engine/utils/utils.go +++ b/components/engine/utils/utils.go @@ -8,6 +8,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/dotcloud/docker/dockerversion" "index/suffixarray" "io" "io/ioutil" @@ -23,12 +24,6 @@ import ( "time" ) -var ( - IAMSTATIC bool // whether or not Docker itself was compiled statically via ./hack/make.sh binary - INITSHA1 string // sha1sum of separate static dockerinit, if Docker itself was compiled dynamically via ./hack/make.sh dynbinary - INITPATH string // custom location to search for a valid dockerinit binary (available for packagers as a last resort escape hatch) -) - // A common interface to access the Fatal method of // both testing.B and testing.T. type Fataler interface { @@ -201,7 +196,7 @@ func isValidDockerInitPath(target string, selfPath string) bool { // target and if target == "" { return false } - if IAMSTATIC { + if dockerversion.IAMSTATIC { if selfPath == "" { return false } @@ -218,7 +213,7 @@ func isValidDockerInitPath(target string, selfPath string) bool { // target and } return os.SameFile(targetFileInfo, selfPathFileInfo) } - return INITSHA1 != "" && dockerInitSha1(target) == INITSHA1 + return dockerversion.INITSHA1 != "" && dockerInitSha1(target) == dockerversion.INITSHA1 } // Figure out the path of our dockerinit (which may be SelfPath()) @@ -230,7 +225,7 @@ func DockerInitPath(localCopy string) string { } var possibleInits = []string{ localCopy, - INITPATH, + dockerversion.INITPATH, filepath.Join(filepath.Dir(selfPath), "dockerinit"), // FHS 3.0 Draft: "/usr/libexec includes internal binaries that are not intended to be executed directly by users or shell scripts. Applications may use a single subdirectory under /usr/libexec." diff --git a/components/engine/version.go b/components/engine/version.go index 2eee68c2f2..88298a16cb 100644 --- a/components/engine/version.go +++ b/components/engine/version.go @@ -7,14 +7,6 @@ import ( "runtime" ) -var ( - // FIXME: this is a convenience indirection to preserve legacy - // code. It can be removed by using dockerversion.VERSION and - // dockerversion.GITCOMMIT directly - GITCOMMIT string = dockerversion.GITCOMMIT - VERSION string = dockerversion.VERSION -) - func init() { engine.Register("version", jobVersion) } @@ -31,8 +23,8 @@ func jobVersion(job *engine.Job) engine.Status { // environment. func dockerVersion() *engine.Env { v := &engine.Env{} - v.Set("Version", VERSION) - v.Set("GitCommit", GITCOMMIT) + v.Set("Version", dockerversion.VERSION) + v.Set("GitCommit", dockerversion.GITCOMMIT) v.Set("GoVersion", runtime.Version()) v.Set("Os", runtime.GOOS) v.Set("Arch", runtime.GOARCH) From 2b6a0d82a2ad45cccee2e2c0c642aaf0159d85bb Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Tue, 11 Feb 2014 18:23:17 -0700 Subject: [PATCH 3/4] Fix the one spot I missed dockerversion Docker-DCO-1.1-Signed-off-by: Andrew Page (github: tianon) Upstream-commit: 7ea725fdc530e989516fae60f5dafecb139d75b8 Component: engine --- components/engine/hack/make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/hack/make.sh b/components/engine/hack/make.sh index 011b796201..55409c55fc 100755 --- a/components/engine/hack/make.sh +++ b/components/engine/hack/make.sh @@ -83,7 +83,7 @@ fi # Use these flags when compiling the tests and final binary LDFLAGS='-X github.com/dotcloud/docker/dockerversion.GITCOMMIT "'$GITCOMMIT'" -X github.com/dotcloud/docker/dockerversion.VERSION "'$VERSION'" -w' -LDFLAGS_STATIC='-X github.com/dotcloud/docker/utils.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"' +LDFLAGS_STATIC='-X github.com/dotcloud/docker/dockerversion.IAMSTATIC true -linkmode external -extldflags "-lpthread -static -Wl,--unresolved-symbols=ignore-in-object-files"' BUILDFLAGS='-tags netgo -a' HAVE_GO_TEST_COVER= From e8ca8bfeb882447056f7c568e3813cec2be5e068 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Tue, 11 Feb 2014 19:10:23 -0700 Subject: [PATCH 4/4] Fix the tests, too Seriously. There's not much codebase left we haven't touched. Docker-DCO-1.1-Signed-off-by: Andrew Page (github: tianon) Upstream-commit: 0d871840b202fc31418990bbcbe0df1c4ad689fb Component: engine --- components/engine/integration/api_test.go | 3 ++- components/engine/integration/graph_test.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/engine/integration/api_test.go b/components/engine/integration/api_test.go index 82de56a8ba..d3efb75969 100644 --- a/components/engine/integration/api_test.go +++ b/components/engine/integration/api_test.go @@ -8,6 +8,7 @@ import ( "fmt" "github.com/dotcloud/docker" "github.com/dotcloud/docker/api" + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/engine" "github.com/dotcloud/docker/utils" "io" @@ -45,7 +46,7 @@ func TestGetVersion(t *testing.T) { t.Fatal(err) } out.Close() - expected := docker.VERSION + expected := dockerversion.VERSION if result := v.Get("Version"); result != expected { t.Errorf("Expected version %s, %s found", expected, result) } diff --git a/components/engine/integration/graph_test.go b/components/engine/integration/graph_test.go index eec4c5c7dc..ff1c0d9361 100644 --- a/components/engine/integration/graph_test.go +++ b/components/engine/integration/graph_test.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/dotcloud/docker" "github.com/dotcloud/docker/archive" + "github.com/dotcloud/docker/dockerversion" "github.com/dotcloud/docker/graphdriver" "github.com/dotcloud/docker/utils" "io" @@ -105,8 +106,8 @@ func TestGraphCreate(t *testing.T) { if image.Comment != "Testing" { t.Fatalf("Wrong comment: should be '%s', not '%s'", "Testing", image.Comment) } - if image.DockerVersion != docker.VERSION { - t.Fatalf("Wrong docker_version: should be '%s', not '%s'", docker.VERSION, image.DockerVersion) + if image.DockerVersion != dockerversion.VERSION { + t.Fatalf("Wrong docker_version: should be '%s', not '%s'", dockerversion.VERSION, image.DockerVersion) } images, err := graph.Map() if err != nil {