diff --git a/Makefile b/Makefile index 4937aa0a7..2a6e18ebd 100644 --- a/Makefile +++ b/Makefile @@ -33,10 +33,22 @@ check_go_env: @test $$(go list) = "$(PKG_NAME)" || \ (echo "Invalid Go environment - The local directory structure must match: $(PKG_NAME)" && false) -cross: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe ## cross-compile binaries (linux, darwin, windows) +cross: cross-plugin cross-standalone ## cross-compile binaries (linux, darwin, windows) + +cross-plugin: bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-windows.exe + +cross-standalone: bin/${BIN_STANDALONE_NAME}-linux bin/${BIN_STANDALONE_NAME}-darwin bin/${BIN_STANDALONE_NAME}-windows.exe e2e-cross: bin/$(BIN_NAME)-e2e-linux bin/$(BIN_NAME)-e2e-darwin bin/$(BIN_NAME)-e2e-windows.exe +.PHONY: bin/${BIN_STANDALONE_NAME}-windows +bin/${BIN_STANDALONE_NAME}-%.exe bin/${BIN_STANDALONE_NAME}-%: cmd/${BIN_STANDALONE_NAME} check_go_env + GOOS=$* $(GO_BUILD) -o $@ ./$< + +.PHONY: bin/${BIN_STANDALONE_NAME} +bin/${BIN_STANDALONE_NAME}: cmd/${BIN_STANDALONE_NAME} check_go_env + $(GO_BUILD) -o $@$(EXEC_EXT) ./$< + .PHONY: bin/$(BIN_NAME)-e2e-windows bin/$(BIN_NAME)-e2e-%.exe bin/$(BIN_NAME)-e2e-%: e2e bin/$(BIN_NAME)-% GOOS=$* $(GO_TEST) -c -o $@ ./e2e/ diff --git a/cmd/docker-app-standalone/main.go b/cmd/docker-app-standalone/main.go new file mode 100644 index 000000000..17d124da1 --- /dev/null +++ b/cmd/docker-app-standalone/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/docker/app/internal" + app "github.com/docker/app/internal/commands" + "github.com/docker/cli/cli" + "github.com/docker/cli/cli/command" + cliflags "github.com/docker/cli/cli/flags" + "github.com/sirupsen/logrus" +) + +func main() { + dockerCli, err := command.NewDockerCli() + if err != nil { + fmt.Fprintln(os.Stderr, err) + } + logrus.SetOutput(dockerCli.Err()) + + cmd := app.NewRootCmd("docker-app", dockerCli) + configureRootCmd(cmd, dockerCli) + + if err := cmd.Execute(); err != nil { + os.Exit(1) + } +} + +func configureRootCmd(cmd *cobra.Command, dockerCli *command.DockerCli) { + var ( + opts *cliflags.ClientOptions + flags *pflag.FlagSet + ) + + cmd.SilenceUsage = true + cmd.TraverseChildren = true + cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { + opts.Common.SetDefaultOptions(flags) + return dockerCli.Initialize(opts) + } + cmd.Version = fmt.Sprintf("%s, build %s", internal.Version, internal.GitCommit) + + opts, flags, _ = cli.SetupRootCommand(cmd) + flags.BoolP("version", "v", false, "Print version information") + cmd.SetVersionTemplate("docker-app version {{.Version}}\n") +} diff --git a/docker.Makefile b/docker.Makefile index 0fcf13f88..efe14671b 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -43,10 +43,16 @@ cross: create_bin ## cross-compile binaries (linux, darwin, windows) docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-linux bin/$(BIN_NAME)-linux docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-darwin bin/$(BIN_NAME)-darwin docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/$(BIN_NAME)-windows.exe bin/$(BIN_NAME)-windows.exe + docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/${BIN_STANDALONE_NAME}-linux bin/${BIN_STANDALONE_NAME}-linux + docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/${BIN_STANDALONE_NAME}-darwin bin/${BIN_STANDALONE_NAME}-darwin + docker cp $(CROSS_CTNR_NAME):$(PKG_PATH)/bin/${BIN_STANDALONE_NAME}-windows.exe bin/${BIN_STANDALONE_NAME}-windows.exe docker rm $(CROSS_CTNR_NAME) @$(call chmod,+x,bin/$(BIN_NAME)-linux) @$(call chmod,+x,bin/$(BIN_NAME)-darwin) @$(call chmod,+x,bin/$(BIN_NAME)-windows.exe) + @$(call chmod,+x,bin/${BIN_STANDALONE_NAME}-linux) + @$(call chmod,+x,bin/${BIN_STANDALONE_NAME}-darwin) + @$(call chmod,+x,bin/${BIN_STANDALONE_NAME}-windows.exe) cli-cross: create_bin docker build $(BUILD_ARGS) --target=build -t $(CLI_IMAGE_NAME) . @@ -71,11 +77,11 @@ e2e-cross: create_bin @$(call chmod,+x,bin/$(BIN_NAME)-e2e-windows.exe) tars: - tar czf bin/$(BIN_NAME)-linux.tar.gz -C bin $(BIN_NAME)-linux + tar --transform='flags=r;s|$(BIN_NAME)-linux|$(BIN_NAME)-plugin-linux|' -czf bin/$(BIN_NAME)-linux.tar.gz -C bin $(BIN_NAME)-linux ${BIN_STANDALONE_NAME}-linux tar czf bin/$(BIN_NAME)-e2e-linux.tar.gz -C bin $(BIN_NAME)-e2e-linux - tar czf bin/$(BIN_NAME)-darwin.tar.gz -C bin $(BIN_NAME)-darwin + tar --transform='flags=r;s|$(BIN_NAME)-darwin|$(BIN_NAME)-plugin-darwin|' -czf bin/$(BIN_NAME)-darwin.tar.gz -C bin $(BIN_NAME)-darwin ${BIN_STANDALONE_NAME}-darwin tar czf bin/$(BIN_NAME)-e2e-darwin.tar.gz -C bin $(BIN_NAME)-e2e-darwin - tar czf bin/$(BIN_NAME)-windows.tar.gz -C bin $(BIN_NAME)-windows.exe + tar --transform='flags=r;s|$(BIN_NAME)-windows|$(BIN_NAME)-plugin-windows|' -czf bin/$(BIN_NAME)-windows.tar.gz -C bin $(BIN_NAME)-windows.exe ${BIN_STANDALONE_NAME}-windows.exe tar czf bin/$(BIN_NAME)-e2e-windows.tar.gz -C bin $(BIN_NAME)-e2e-windows.exe test: test-unit test-e2e ## run all tests diff --git a/vars.mk b/vars.mk index 33e37d34a..9bb0f9e2d 100644 --- a/vars.mk +++ b/vars.mk @@ -1,5 +1,6 @@ PKG_NAME := github.com/docker/app BIN_NAME ?= docker-app +BIN_STANDALONE_NAME := ${BIN_NAME}-standalone E2E_NAME := $(BIN_NAME)-e2e # Enable experimental features. "on" or "off"