diff --git a/Makefile b/Makefile index d1f0c73e00..7e29729484 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ # -# github.com/docker/cli +# github.com/docker/cli # .PHONY: build clean test lint cross # build the CLI build: clean - @go build -o ./build/docker github.com/docker/cli/cmd/docker + @./scripts/build/binary # remove build artifacts clean: @@ -23,9 +23,7 @@ lint: # build the CLI for multiple architectures cross: clean - @gox -output build/docker-{{.OS}}-{{.Arch}} \ - -osarch="linux/arm linux/amd64 darwin/amd64 windows/amd64" \ - github.com/docker/cli/cmd/docker + @./scripts/build/cross vendor: vendor.conf @vndr 2> /dev/null diff --git a/cli/command/cli.go b/cli/command/cli.go index eea823f4c5..0c88beff5d 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -7,6 +7,7 @@ import ( "os" "runtime" + "github.com/docker/cli/cli" cliconfig "github.com/docker/cli/cli/config" "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/credentials" @@ -15,7 +16,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" - "github.com/docker/docker/dockerversion" dopts "github.com/docker/docker/opts" "github.com/docker/go-connections/sockets" "github.com/docker/go-connections/tlsconfig" @@ -300,5 +300,5 @@ func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, er // UserAgent returns the user agent string used for making API requests func UserAgent() string { - return "Docker-Client/" + dockerversion.Version + " (" + runtime.GOOS + ")" + return "Docker-Client/" + cli.Version + " (" + runtime.GOOS + ")" } diff --git a/cli/command/system/version.go b/cli/command/system/version.go index e046527c5a..21c5a6df30 100644 --- a/cli/command/system/version.go +++ b/cli/command/system/version.go @@ -9,7 +9,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" - "github.com/docker/docker/dockerversion" "github.com/docker/docker/pkg/templates" "github.com/spf13/cobra" ) @@ -94,12 +93,12 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error { vd := versionInfo{ Client: clientVersion{ - Version: dockerversion.Version, + Version: cli.Version, APIVersion: dockerCli.Client().ClientVersion(), DefaultAPIVersion: dockerCli.DefaultVersion(), GoVersion: runtime.Version(), - GitCommit: dockerversion.GitCommit, - BuildTime: dockerversion.BuildTime, + GitCommit: cli.GitCommit, + BuildTime: cli.BuildTime, Os: runtime.GOOS, Arch: runtime.GOARCH, }, diff --git a/cli/version.go b/cli/version.go new file mode 100644 index 0000000000..bff7ab49ef --- /dev/null +++ b/cli/version.go @@ -0,0 +1,9 @@ +package cli + +// Default build-time variable. +// These values are overriding via ldflags +var ( + Version = "unknown-version" + GitCommit = "unknown-commit" + BuildTime = "unknown-buildtime" +) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index abc262e357..e7ec0428f9 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -15,7 +15,6 @@ import ( cliflags "github.com/docker/cli/cli/flags" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" - "github.com/docker/docker/dockerversion" "github.com/docker/docker/pkg/term" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -184,7 +183,7 @@ func main() { } func showVersion() { - fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit) + fmt.Printf("Docker version %s, build %s\n", cli.Version, cli.GitCommit) } func dockerPreRun(opts *cliflags.ClientOptions) { diff --git a/scripts/build/binary b/scripts/build/binary new file mode 100755 index 0000000000..9f6f472812 --- /dev/null +++ b/scripts/build/binary @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +source ./scripts/build/ldflags + +go build -o ./build/docker --ldflags "${LDFLAGS}" github.com/docker/cli/cmd/docker diff --git a/scripts/build/cross b/scripts/build/cross new file mode 100755 index 0000000000..4e113943a4 --- /dev/null +++ b/scripts/build/cross @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +source ./scripts/build/ldflags + +gox -output build/docker-{{.OS}}-{{.Arch}} \ + -osarch="linux/arm linux/amd64 darwin/amd64 windows/amd64" \ + --ldflags "${LDFLAGS}" \ + github.com/docker/cli/cmd/docker diff --git a/scripts/build/ldflags b/scripts/build/ldflags new file mode 100755 index 0000000000..a0c5e1f9e6 --- /dev/null +++ b/scripts/build/ldflags @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +VERSION=${VERSION:-"unknown-version"} +GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)} +BUILDTIME=${BUILDTIME:-$(date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')} + +export LDFLAGS="-X github.com/docker/cli/cli.GitCommit=${GITCOMMIT} \ + -X github.com/docker/cli/cli.BuildTime=${BUILDTIME} \ + -X github.com/docker/cli/cli.Version=${VERSION} ${LDFLAGS}" diff --git a/vendor/github.com/docker/docker/dockerversion/useragent.go b/vendor/github.com/docker/docker/dockerversion/useragent.go deleted file mode 100644 index 53632cbc35..0000000000 --- a/vendor/github.com/docker/docker/dockerversion/useragent.go +++ /dev/null @@ -1,76 +0,0 @@ -package dockerversion - -import ( - "fmt" - "runtime" - - "github.com/docker/docker/pkg/parsers/kernel" - "github.com/docker/docker/pkg/useragent" - "golang.org/x/net/context" -) - -// UAStringKey is used as key type for user-agent string in net/context struct -const UAStringKey = "upstream-user-agent" - -// DockerUserAgent is the User-Agent the Docker client uses to identify itself. -// In accordance with RFC 7231 (5.5.3) is of the form: -// [docker client's UA] UpstreamClient([upstream client's UA]) -func DockerUserAgent(ctx context.Context) string { - httpVersion := make([]useragent.VersionInfo, 0, 6) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "docker", Version: Version}) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "go", Version: runtime.Version()}) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "git-commit", Version: GitCommit}) - if kernelVersion, err := kernel.GetKernelVersion(); err == nil { - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "kernel", Version: kernelVersion.String()}) - } - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "os", Version: runtime.GOOS}) - httpVersion = append(httpVersion, useragent.VersionInfo{Name: "arch", Version: runtime.GOARCH}) - - dockerUA := useragent.AppendVersions("", httpVersion...) - upstreamUA := getUserAgentFromContext(ctx) - if len(upstreamUA) > 0 { - ret := insertUpstreamUserAgent(upstreamUA, dockerUA) - return ret - } - return dockerUA -} - -// getUserAgentFromContext returns the previously saved user-agent context stored in ctx, if one exists -func getUserAgentFromContext(ctx context.Context) string { - var upstreamUA string - if ctx != nil { - var ki interface{} = ctx.Value(UAStringKey) - if ki != nil { - upstreamUA = ctx.Value(UAStringKey).(string) - } - } - return upstreamUA -} - -// escapeStr returns s with every rune in charsToEscape escaped by a backslash -func escapeStr(s string, charsToEscape string) string { - var ret string - for _, currRune := range s { - appended := false - for _, escapeableRune := range charsToEscape { - if currRune == escapeableRune { - ret += `\` + string(currRune) - appended = true - break - } - } - if !appended { - ret += string(currRune) - } - } - return ret -} - -// insertUpstreamUserAgent adds the upstream client useragent to create a user-agent -// string of the form: -// $dockerUA UpstreamClient($upstreamUA) -func insertUpstreamUserAgent(upstreamUA string, dockerUA string) string { - charsToEscape := `();\` - upstreamUAEscaped := escapeStr(upstreamUA, charsToEscape) - return fmt.Sprintf("%s UpstreamClient(%s)", dockerUA, upstreamUAEscaped) -} diff --git a/vendor/github.com/docker/docker/dockerversion/version_lib.go b/vendor/github.com/docker/docker/dockerversion/version_lib.go deleted file mode 100644 index 33f77d3ce6..0000000000 --- a/vendor/github.com/docker/docker/dockerversion/version_lib.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build !autogen - -// Package dockerversion is auto-generated at build-time -package dockerversion - -// Default build-time variable for library-import. -// This file is overridden on build with build-time informations. -const ( - GitCommit string = "library-import" - Version string = "library-import" - BuildTime string = "library-import" - IAmStatic string = "library-import" - ContainerdCommitID string = "library-import" - RuncCommitID string = "library-import" - InitCommitID string = "library-import" -)