diff --git a/Dockerfile b/Dockerfile index 220a5bf3a6..c2435f473a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ COPY . /go/src/github.com/docker/swarm WORKDIR /go/src/github.com/docker/swarm ENV GOPATH /go/src/github.com/docker/swarm/Godeps/_workspace:$GOPATH -RUN CGO_ENABLED=0 go install -v -a -tags netgo -ldflags "-w -X github.com/docker/swarm/api.GITCOMMIT `git rev-parse --short HEAD`" +RUN CGO_ENABLED=0 go install -v -a -tags netgo -ldflags "-w -X github.com/docker/swarm/version.GITCOMMIT `git rev-parse --short HEAD`" EXPOSE 2375 VOLUME $HOME/.swarm diff --git a/api/api.go b/api/api.go index fbd350a87f..e003faffa0 100644 --- a/api/api.go +++ b/api/api.go @@ -17,22 +17,18 @@ import ( "github.com/docker/swarm/cluster" "github.com/docker/swarm/scheduler" "github.com/docker/swarm/scheduler/filter" + "github.com/docker/swarm/version" "github.com/gorilla/mux" "github.com/samalba/dockerclient" ) const APIVERSION = "1.16" -var ( - GITCOMMIT string -) - type context struct { cluster *cluster.Cluster scheduler *scheduler.Scheduler eventsHandler *eventsHandler debug bool - version string tlsConfig *tls.Config } @@ -72,10 +68,10 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) { Os string Arch string }{ - Version: "swarm/" + c.version, + Version: "swarm/" + version.VERSION, ApiVersion: APIVERSION, GoVersion: runtime.Version(), - GitCommit: GITCOMMIT, + GitCommit: version.GITCOMMIT, Os: runtime.GOOS, Arch: runtime.GOARCH, } diff --git a/api/api_test.go b/api/api_test.go index c453898bc8..96c0f6da75 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -8,6 +8,7 @@ import ( "github.com/docker/swarm/cluster" "github.com/docker/swarm/scheduler" + "github.com/docker/swarm/version" "github.com/stretchr/testify/assert" ) @@ -15,7 +16,6 @@ func serveRequest(c *cluster.Cluster, s *scheduler.Scheduler, w http.ResponseWri context := &context{ cluster: c, scheduler: s, - version: "test-version", } r := createRouter(context, false) @@ -31,10 +31,10 @@ func TestGetVersion(t *testing.T) { assert.NoError(t, serveRequest(nil, nil, r, req)) assert.Equal(t, r.Code, http.StatusOK) - version := struct { + v := struct { Version string }{} - json.NewDecoder(r.Body).Decode(&version) - assert.Equal(t, version.Version, "swarm/test-version") + json.NewDecoder(r.Body).Decode(&v) + assert.Equal(t, v.Version, "swarm/"+version.VERSION) } diff --git a/api/server.go b/api/server.go index 3332f5b507..b4c7778636 100644 --- a/api/server.go +++ b/api/server.go @@ -29,11 +29,10 @@ func newListener(proto, addr string, tlsConfig *tls.Config) (net.Listener, error return l, nil } -func ListenAndServe(c *cluster.Cluster, s *scheduler.Scheduler, hosts []string, version string, enableCors bool, tlsConfig *tls.Config) error { +func ListenAndServe(c *cluster.Cluster, s *scheduler.Scheduler, hosts []string, enableCors bool, tlsConfig *tls.Config) error { context := &context{ cluster: c, scheduler: s, - version: version, eventsHandler: NewEventsHandler(), tlsConfig: tlsConfig, } diff --git a/main.go b/main.go index 1255df7489..4399b45581 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,6 @@ import ( log "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" - - "github.com/docker/swarm/api" "github.com/docker/swarm/discovery" _ "github.com/docker/swarm/discovery/consul" _ "github.com/docker/swarm/discovery/etcd" @@ -16,17 +14,15 @@ import ( _ "github.com/docker/swarm/discovery/nodes" "github.com/docker/swarm/discovery/token" _ "github.com/docker/swarm/discovery/zookeeper" + "github.com/docker/swarm/version" ) func main() { app := cli.NewApp() app.Name = path.Base(os.Args[0]) app.Usage = "a Docker-native clustering system" - app.Version = "0.1.0" + app.Version = version.VERSION + " (" + version.GITCOMMIT + ")" - if api.GITCOMMIT != "" { - app.Version += " (" + api.GITCOMMIT + ")" - } app.Author = "" app.Email = "" diff --git a/manage.go b/manage.go index da946da190..0403b1507b 100644 --- a/manage.go +++ b/manage.go @@ -146,5 +146,5 @@ func manage(c *cli.Context) { if c.IsSet("host") || c.IsSet("H") { hosts = hosts[1:] } - log.Fatal(api.ListenAndServe(cluster, sched, hosts, c.App.Version, c.Bool("cors"), tlsConfig)) + log.Fatal(api.ListenAndServe(cluster, sched, hosts, c.Bool("cors"), tlsConfig)) } diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000000..13b230aeca --- /dev/null +++ b/version/version.go @@ -0,0 +1,9 @@ +package version + +var ( + // VERSION should be updated by hand at each release + VERSION = "0.1.0" + + // GITCOMMIT will be overritten automatically by the build system + GITCOMMIT = "HEAD" +)