Skip to content

Commit da04f49

Browse files
committed
Move even more stuff into dockerversion
Also, use it in all the places. :) Docker-DCO-1.1-Signed-off-by: Andrew Page <[email protected]> (github: tianon)
1 parent ae3c7de commit da04f49

9 files changed

Lines changed: 26 additions & 36 deletions

File tree

commands.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/dotcloud/docker/api"
1212
"github.com/dotcloud/docker/archive"
1313
"github.com/dotcloud/docker/auth"
14+
"github.com/dotcloud/docker/dockerversion"
1415
"github.com/dotcloud/docker/engine"
1516
flag "github.com/dotcloud/docker/pkg/mflag"
1617
"github.com/dotcloud/docker/pkg/sysinfo"
@@ -383,12 +384,12 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
383384
cmd.Usage()
384385
return nil
385386
}
386-
if VERSION != "" {
387-
fmt.Fprintf(cli.out, "Client version: %s\n", VERSION)
387+
if dockerversion.VERSION != "" {
388+
fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
388389
}
389390
fmt.Fprintf(cli.out, "Go version (client): %s\n", runtime.Version())
390-
if GITCOMMIT != "" {
391-
fmt.Fprintf(cli.out, "Git commit (client): %s\n", GITCOMMIT)
391+
if dockerversion.GITCOMMIT != "" {
392+
fmt.Fprintf(cli.out, "Git commit (client): %s\n", dockerversion.GITCOMMIT)
392393
}
393394

394395
body, _, err := readBody(cli.call("GET", "/version", nil, false))
@@ -413,7 +414,7 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
413414
release := utils.GetReleaseVersion()
414415
if release != "" {
415416
fmt.Fprintf(cli.out, "Last stable version: %s", release)
416-
if (VERSION != "" || remoteVersion.Exists("Version")) && (strings.Trim(VERSION, "-dev") != release || strings.Trim(remoteVersion.Get("Version"), "-dev") != release) {
417+
if (dockerversion.VERSION != "" || remoteVersion.Exists("Version")) && (strings.Trim(dockerversion.VERSION, "-dev") != release || strings.Trim(remoteVersion.Get("Version"), "-dev") != release) {
417418
fmt.Fprintf(cli.out, ", please update docker")
418419
}
419420
fmt.Fprintf(cli.out, "\n")
@@ -2298,7 +2299,7 @@ func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo b
22982299
}
22992300
}
23002301
}
2301-
req.Header.Set("User-Agent", "Docker-Client/"+VERSION)
2302+
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
23022303
req.Host = cli.addr
23032304
if data != nil {
23042305
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
23552356
if err != nil {
23562357
return err
23572358
}
2358-
req.Header.Set("User-Agent", "Docker-Client/"+VERSION)
2359+
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
23592360
req.Host = cli.addr
23602361
if method == "POST" {
23612362
req.Header.Set("Content-Type", "plain/text")
@@ -2419,7 +2420,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
24192420
if err != nil {
24202421
return err
24212422
}
2422-
req.Header.Set("User-Agent", "Docker-Client/"+VERSION)
2423+
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
24232424
req.Header.Set("Content-Type", "plain/text")
24242425
req.Host = cli.addr
24252426

dockerinit/dockerinit.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import (
44
"github.com/dotcloud/docker/sysinit"
55
)
66

7-
var (
8-
GITCOMMIT string
9-
VERSION string
10-
)
11-
127
func main() {
138
// Running in init mode
149
sysinit.SysInit()

dockerversion/dockerversion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ package dockerversion
88
var (
99
GITCOMMIT string
1010
VERSION string
11+
12+
IAMSTATIC bool // whether or not Docker itself was compiled statically via ./hack/make.sh binary
13+
INITSHA1 string // sha1sum of separate static dockerinit, if Docker itself was compiled dynamically via ./hack/make.sh dynbinary
14+
INITPATH string // custom location to search for a valid dockerinit binary (available for packagers as a last resort escape hatch)
1115
)

graph.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package docker
33
import (
44
"fmt"
55
"github.com/dotcloud/docker/archive"
6+
"github.com/dotcloud/docker/dockerversion"
67
"github.com/dotcloud/docker/graphdriver"
78
"github.com/dotcloud/docker/utils"
89
"io"
@@ -130,7 +131,7 @@ func (graph *Graph) Create(layerData archive.Archive, container *Container, comm
130131
ID: GenerateID(),
131132
Comment: comment,
132133
Created: time.Now().UTC(),
133-
DockerVersion: VERSION,
134+
DockerVersion: dockerversion.VERSION,
134135
Author: author,
135136
Config: config,
136137
Architecture: runtime.GOARCH,

hack/make/dynbinary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export DOCKER_INITSHA1="$(sha1sum $DEST/dockerinit-$VERSION | cut -d' ' -f1)"
1212
# exported so that "dyntest" can easily access it later without recalculating it
1313

1414
(
15-
export LDFLAGS_STATIC="-X github.com/dotcloud/docker/utils.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/utils.INITPATH \"$DOCKER_INITPATH\""
15+
export LDFLAGS_STATIC="-X github.com/dotcloud/docker/dockerversion.INITSHA1 \"$DOCKER_INITSHA1\" -X github.com/dotcloud/docker/dockerversion.INITPATH \"$DOCKER_INITPATH\""
1616
source "$(dirname "$BASH_SOURCE")/binary"
1717
)

runtime.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"container/list"
55
"fmt"
66
"github.com/dotcloud/docker/archive"
7+
"github.com/dotcloud/docker/dockerversion"
78
"github.com/dotcloud/docker/engine"
89
"github.com/dotcloud/docker/execdriver"
910
"github.com/dotcloud/docker/execdriver/chroot"
@@ -678,7 +679,7 @@ func NewRuntimeFromDirectory(config *DaemonConfig, eng *engine.Engine) (*Runtime
678679
return nil, err
679680
}
680681

681-
localCopy := path.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", VERSION))
682+
localCopy := path.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", dockerversion.VERSION))
682683
sysInitPath := utils.DockerInitPath(localCopy)
683684
if sysInitPath == "" {
684685
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.")

server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"github.com/dotcloud/docker/archive"
88
"github.com/dotcloud/docker/auth"
9+
"github.com/dotcloud/docker/dockerversion"
910
"github.com/dotcloud/docker/engine"
1011
"github.com/dotcloud/docker/pkg/graphdb"
1112
"github.com/dotcloud/docker/registry"
@@ -827,7 +828,7 @@ func (srv *Server) DockerInfo(job *engine.Job) engine.Status {
827828
v.SetInt("NEventsListener", len(srv.events))
828829
v.Set("KernelVersion", kernelVersion)
829830
v.Set("IndexServerAddress", auth.IndexServerAddress())
830-
v.Set("InitSha1", utils.INITSHA1)
831+
v.Set("InitSha1", dockerversion.INITSHA1)
831832
v.Set("InitPath", initPath)
832833
if _, err := v.WriteTo(job.Stdout); err != nil {
833834
return job.Error(err)

utils/utils.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/json"
99
"errors"
1010
"fmt"
11+
"github.com/dotcloud/docker/dockerversion"
1112
"index/suffixarray"
1213
"io"
1314
"io/ioutil"
@@ -23,12 +24,6 @@ import (
2324
"time"
2425
)
2526

26-
var (
27-
IAMSTATIC bool // whether or not Docker itself was compiled statically via ./hack/make.sh binary
28-
INITSHA1 string // sha1sum of separate static dockerinit, if Docker itself was compiled dynamically via ./hack/make.sh dynbinary
29-
INITPATH string // custom location to search for a valid dockerinit binary (available for packagers as a last resort escape hatch)
30-
)
31-
3227
// A common interface to access the Fatal method of
3328
// both testing.B and testing.T.
3429
type Fataler interface {
@@ -201,7 +196,7 @@ func isValidDockerInitPath(target string, selfPath string) bool { // target and
201196
if target == "" {
202197
return false
203198
}
204-
if IAMSTATIC {
199+
if dockerversion.IAMSTATIC {
205200
if selfPath == "" {
206201
return false
207202
}
@@ -218,7 +213,7 @@ func isValidDockerInitPath(target string, selfPath string) bool { // target and
218213
}
219214
return os.SameFile(targetFileInfo, selfPathFileInfo)
220215
}
221-
return INITSHA1 != "" && dockerInitSha1(target) == INITSHA1
216+
return dockerversion.INITSHA1 != "" && dockerInitSha1(target) == dockerversion.INITSHA1
222217
}
223218

224219
// Figure out the path of our dockerinit (which may be SelfPath())
@@ -230,7 +225,7 @@ func DockerInitPath(localCopy string) string {
230225
}
231226
var possibleInits = []string{
232227
localCopy,
233-
INITPATH,
228+
dockerversion.INITPATH,
234229
filepath.Join(filepath.Dir(selfPath), "dockerinit"),
235230

236231
// 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."

version.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ import (
77
"runtime"
88
)
99

10-
var (
11-
// FIXME: this is a convenience indirection to preserve legacy
12-
// code. It can be removed by using dockerversion.VERSION and
13-
// dockerversion.GITCOMMIT directly
14-
GITCOMMIT string = dockerversion.GITCOMMIT
15-
VERSION string = dockerversion.VERSION
16-
)
17-
1810
func init() {
1911
engine.Register("version", jobVersion)
2012
}
@@ -31,8 +23,8 @@ func jobVersion(job *engine.Job) engine.Status {
3123
// environment.
3224
func dockerVersion() *engine.Env {
3325
v := &engine.Env{}
34-
v.Set("Version", VERSION)
35-
v.Set("GitCommit", GITCOMMIT)
26+
v.Set("Version", dockerversion.VERSION)
27+
v.Set("GitCommit", dockerversion.GITCOMMIT)
3628
v.Set("GoVersion", runtime.Version())
3729
v.Set("Os", runtime.GOOS)
3830
v.Set("Arch", runtime.GOARCH)

0 commit comments

Comments
 (0)