mirror of https://github.com/docker/compose.git
Merge pull request #289 from gtardif/automate_version_from_tag
Automate version from tag
This commit is contained in:
commit
4fb039164d
|
@ -23,7 +23,9 @@ ifeq ($(GOOS),windows)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
STATIC_FLAGS=CGO_ENABLED=0
|
STATIC_FLAGS=CGO_ENABLED=0
|
||||||
LDFLAGS:="-s -w"
|
GIT_TAG=$(shell git describe --tags --match "v[0-9]*")
|
||||||
|
|
||||||
|
LDFLAGS="-s -w -X main.version=${GIT_TAG}"
|
||||||
GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
|
GO_BUILD=$(STATIC_FLAGS) go build -trimpath -ldflags=$(LDFLAGS)
|
||||||
|
|
||||||
BINARY?=bin/docker
|
BINARY?=bin/docker
|
||||||
|
@ -37,18 +39,18 @@ endif
|
||||||
all: cli
|
all: cli
|
||||||
|
|
||||||
protos:
|
protos:
|
||||||
@protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
|
protoc -I. --go_out=plugins=grpc,paths=source_relative:. ${PROTOS}
|
||||||
|
|
||||||
cli:
|
cli:
|
||||||
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
|
GOOS=${GOOS} GOARCH=${GOARCH} $(GO_BUILD) $(TAGS) -o $(BINARY_WITH_EXTENSION) ./cli
|
||||||
|
|
||||||
cross:
|
cross:
|
||||||
@GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
|
GOOS=linux GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-linux-amd64 ./cli
|
||||||
@GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
|
GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-darwin-amd64 ./cli
|
||||||
@GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
|
GOOS=windows GOARCH=amd64 $(GO_BUILD) $(TAGS) -o $(BINARY)-windows-amd64.exe ./cli
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
|
go test $(TAGS) -cover $(shell go list ./... | grep -vE 'e2e')
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run --timeout 10m0s ./...
|
golangci-lint run --timeout 10m0s ./...
|
||||||
|
|
|
@ -26,15 +26,15 @@ import (
|
||||||
"github.com/docker/api/cli/mobycli"
|
"github.com/docker/api/cli/mobycli"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cliVersion = "0.1.4"
|
|
||||||
|
|
||||||
// VersionCommand command to display version
|
// VersionCommand command to display version
|
||||||
func VersionCommand() *cobra.Command {
|
func VersionCommand(version string) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Show the Docker version information",
|
Short: "Show the Docker version information",
|
||||||
Args: cobra.MaximumNArgs(0),
|
Args: cobra.MaximumNArgs(0),
|
||||||
RunE: runVersion,
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
|
return runVersion(cmd, version)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
// define flags for backward compatibility with com.docker.cli
|
// define flags for backward compatibility with com.docker.cli
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
@ -45,7 +45,8 @@ func VersionCommand() *cobra.Command {
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runVersion(cmd *cobra.Command, args []string) error {
|
func runVersion(cmd *cobra.Command, version string) error {
|
||||||
|
displayedVersion := strings.TrimPrefix(version, "v")
|
||||||
versionResult, _ := mobycli.ExecSilent(cmd.Context())
|
versionResult, _ := mobycli.ExecSilent(cmd.Context())
|
||||||
// we don't want to fail on error, there is an error if the engine is not available but it displays client version info
|
// we don't want to fail on error, there is an error if the engine is not available but it displays client version info
|
||||||
// Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
|
// Still, technically the [] byte versionResult could be nil, just let the original command display what it has to display
|
||||||
|
@ -53,6 +54,6 @@ func runVersion(cmd *cobra.Command, args []string) error {
|
||||||
return mobycli.ExecCmd(cmd)
|
return mobycli.ExecCmd(cmd)
|
||||||
}
|
}
|
||||||
var s string = string(versionResult)
|
var s string = string(versionResult)
|
||||||
fmt.Print(strings.Replace(s, "\n Version:", "\n Azure integration "+cliVersion+"\n Version:", 1))
|
fmt.Print(strings.Replace(s, "\n Version:", "\n Azure integration "+displayedVersion+"\n Version:", 1))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,10 @@ import (
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ownCommands = map[string]struct{}{
|
ownCommands = map[string]struct{}{
|
||||||
"context": {},
|
"context": {},
|
||||||
|
@ -110,7 +114,7 @@ func main() {
|
||||||
cmd.InspectCommand(),
|
cmd.InspectCommand(),
|
||||||
compose.Command(),
|
compose.Command(),
|
||||||
login.Command(),
|
login.Command(),
|
||||||
cmd.VersionCommand(),
|
cmd.VersionCommand(version),
|
||||||
)
|
)
|
||||||
|
|
||||||
helpFunc := root.HelpFunc()
|
helpFunc := root.HelpFunc()
|
||||||
|
|
Loading…
Reference in New Issue