From 2610b986fdb4fbbd9af86260c9c8f16e483f81dd Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Tue, 19 May 2020 21:46:44 +0200 Subject: [PATCH] delegate Moby to docker-classic binary, link docker-classic in e2e tests --- Makefile | 5 ++++- README.md | 3 +++ cli/main.go | 2 +- tests/framework/helper.go | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index cfeaf303e..4bb58718d 100644 --- a/Makefile +++ b/Makefile @@ -64,10 +64,13 @@ cache-clear: ## Clear the builder cache lint: ## run linter(s) docker run --rm -t -v $(PWD):/app -w /app golangci/golangci-lint:v1.27-alpine golangci-lint run --timeout 10m0s ./... +classic-link: ## create docker-classic symlink if does not already exist + ln -s /usr/local/bin/docker-classic /Applications/Docker.app/Contents/Resources/bin/docker + help: ## Show help @echo Please specify a build target. The choices are: @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' FORCE: -.PHONY: all protos cli e2e-local cross test cache-clear lint help +.PHONY: all protos cli e2e-local cross test cache-clear lint help classic-link diff --git a/README.md b/README.md index 8a9ad0520..e57de2102 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ If you don't have or want to use Docker for building you need to make sure you h And then you can call the same make targets but you need to pass it the `builder.Makefile` (`make -f builder.Makefile`). +The new CLI delegates to the classic docker for default contexts ; delegation is done to `docker-classic`. +* `make classic-link` will create a `docker-classic` link in `/usr/local/bin` if you don't already have it from Docker Desktop + ## Building the project ```bash diff --git a/cli/main.go b/cli/main.go index bb943b06b..7bff9a07a 100644 --- a/cli/main.go +++ b/cli/main.go @@ -180,7 +180,7 @@ func execMoby(ctx context.Context) { // Only run original docker command if the current context is not // ours. if err != nil { - cmd := exec.Command("docker", os.Args[1:]...) + cmd := exec.Command("docker-classic", os.Args[1:]...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/tests/framework/helper.go b/tests/framework/helper.go index 4eb79a0ff..45a461fec 100644 --- a/tests/framework/helper.go +++ b/tests/framework/helper.go @@ -1,7 +1,9 @@ package framework import ( + "fmt" "log" + "os" "strings" "github.com/robpike/filter" @@ -36,4 +38,20 @@ func gomegaFailHandler(message string, callerSkip ...int) { //SetupTest Init gomega fail handler func SetupTest() { gomega.RegisterFailHandler(gomegaFailHandler) + + linkClassicDocker() +} + +func linkClassicDocker() { + dockerOriginal := strings.TrimSuffix(NewCommand("which", "docker").ExecOrDie(), "\n") + _, err := NewCommand("rm", "-r", "./bin/tests").Exec() + if err == nil { + fmt.Println("Removing existing /bin/tests folder before running tests") + } + _, err = NewCommand("mkdir", "-p", "./bin/tests").Exec() + gomega.Expect(err).To(gomega.BeNil()) + NewCommand("ln", "-s", dockerOriginal, "./bin/tests/docker-classic").ExecOrDie() + newPath := "./bin/tests:" + os.Getenv("PATH") + err = os.Setenv("PATH", newPath) + gomega.Expect(err).To(gomega.BeNil()) }