Skip to content

Commit

Permalink
Move docker version introspection to a sub-package.
Browse files Browse the repository at this point in the history
This facilitates the refactoring of commands.go.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <[email protected]> (github: shykes)
  • Loading branch information
Solomon Hykes committed Feb 12, 2014
1 parent 9176b6f commit ae3c7de
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
5 changes: 0 additions & 5 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
)
Expand Down
12 changes: 3 additions & 9 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
11 changes: 11 additions & 0 deletions dockerversion/dockerversion.go
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion hack/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
9 changes: 9 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down

0 comments on commit ae3c7de

Please sign in to comment.