From 723078c5938e3ae28422ea3ea9fd1f10f22b2934 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Fri, 16 Sep 2022 10:16:29 -0400 Subject: [PATCH 1/9] Remove `/rebase` GitHub Action since it's no longer necessary Signed-off-by: Laura Brehm --- .github/workflows/rebase.yml | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .github/workflows/rebase.yml diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml deleted file mode 100644 index ea0556dcca..0000000000 --- a/.github/workflows/rebase.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Automatic Rebase -on: - issue_comment: - types: [created] -jobs: - rebase: - name: Rebase - if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') - runs-on: ubuntu-latest - steps: - - name: Checkout the latest code - uses: actions/checkout@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - fetch-depth: 0 # otherwise, you will fail to push refs to dest repo - - name: Automatic Rebase - uses: cirrus-actions/rebase@1.4 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 937fa2dc8fb65d87a8502647242855f52c97228a Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Fri, 16 Sep 2022 12:13:42 -0400 Subject: [PATCH 2/9] Add GitHub Action workflow to run tests on Mac/Windows runners Signed-off-by: Laura Brehm --- .github/workflows/merge.yml | 82 +++++++++++++++++++++++++++++++++++++ pkg/e2e/buffer.go | 2 +- pkg/e2e/pause_test.go | 2 +- pkg/e2e/up_test.go | 3 ++ 4 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/merge.yml diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml new file mode 100644 index 0000000000..1f79b9cc98 --- /dev/null +++ b/.github/workflows/merge.yml @@ -0,0 +1,82 @@ +name: merge + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - 'v2' + tags: + - 'v*' + workflow_dispatch: + +jobs: + e2e: + name: Build and test + runs-on: ${{ matrix.os }} + timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + os: [desktop-windows, desktop-macos, desktop-m1] + # mode: [plugin, standalone] + mode: [plugin] + env: + GO111MODULE: "on" + steps: + - name: test-action-unsafe-checkout + if: ${{ contains(matrix.os, 'desktop-windows') }} + run: | + git config --global --add safe.directory C:/actions-runner/_work/compose/compose + - uses: actions/checkout@v3 + + # TODO(milas): revert to @v3 after next actions/setup-go minor release + - uses: actions/setup-go@f27981397569ab1d623dab1f29d3db81b75b5258 + with: + go-version-file: go.mod + cache: true + check-latest: true + + - name: Check arch of go binary + run: | + which go + file $(which go) + if: ${{ !contains(matrix.os, 'desktop-windows') }} + + - name: List Docker resources on machine + run: | + docker ps --all + docker volume ls + docker network ls + docker image ls + - name: Remove Docker resources on machine + continue-on-error: true + run: | + docker kill $(docker ps -q) + docker rm -f $(docker ps -aq) + docker volume rm -f $(docker volume ls -q) + docker ps --all + + - name: Unit tests + run: make test + + - name: Build binaries + run: | + make + - name: Check arch of go compose binary + run: | + file ./bin/build/docker-compose + if: ${{ !contains(matrix.os, 'desktop-windows') }} + - + name: Test plugin mode + if: ${{ matrix.mode == 'plugin' }} + run: | + make e2e-compose + - + name: Test standalone mode + if: ${{ matrix.mode == 'standalone' }} + run: | + make e2e-compose-standalone + diff --git a/pkg/e2e/buffer.go b/pkg/e2e/buffer.go index 787e6c358f..b97b81d01b 100644 --- a/pkg/e2e/buffer.go +++ b/pkg/e2e/buffer.go @@ -60,7 +60,7 @@ func (l *lockedBuffer) RequireEventuallyContains(t testing.TB, v string) { "Error: %v", err) } return strings.Contains(bufContents.String(), v) - }, 2*time.Second, 20*time.Millisecond, + }, 5*time.Second, 20*time.Millisecond, "Buffer did not contain %q\n============\n%s\n============", v, &bufContents) } diff --git a/pkg/e2e/pause_test.go b/pkg/e2e/pause_test.go index a91c7a2028..d70d8cb382 100644 --- a/pkg/e2e/pause_test.go +++ b/pkg/e2e/pause_test.go @@ -98,7 +98,7 @@ func TestPauseServiceAlreadyPaused(t *testing.T) { // launch a and wait for it to come up cli.RunDockerComposeCmd(t, "up", "-d", "a") - HTTPGetWithRetry(t, urlForService(t, cli, "a", 80), http.StatusOK, 50*time.Millisecond, 5*time.Second) + HTTPGetWithRetry(t, urlForService(t, cli, "a", 80), http.StatusOK, 50*time.Millisecond, 10*time.Second) // pause a twice - first time should pass, second time fail cli.RunDockerComposeCmd(t, "pause", "a") diff --git a/pkg/e2e/up_test.go b/pkg/e2e/up_test.go index c0ba517bf8..e859829649 100644 --- a/pkg/e2e/up_test.go +++ b/pkg/e2e/up_test.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + /* Copyright 2022 Docker Compose CLI authors From 6bc50cb45761efe684efd6e9431d341ff5eccf1a Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Mon, 19 Sep 2022 12:51:23 -0400 Subject: [PATCH 3/9] Rework Makefile for better Windows support Fixes error when attempting to run `uname` on Windows, and add `.exe` to built binary on `make` if on Windows Signed-off-by: Laura Brehm --- Makefile | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 675cb04bd4..4c49ca3d3e 100644 --- a/Makefile +++ b/Makefile @@ -18,13 +18,20 @@ VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags) GO_LDFLAGS ?= -s -w -X ${PKG}/internal.Version=${VERSION} GO_BUILDTAGS ?= e2e,kube -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Linux) +ifeq ($(OS),Windows_NT) + DETECTED_OS = Windows +else + DETECTED_OS = $(shell uname) +endif +ifeq ($(DETECTED_OS),Linux) MOBY_DOCKER=/usr/bin/docker endif -ifeq ($(UNAME_S),Darwin) +ifeq ($(DETECTED_OS),Darwin) MOBY_DOCKER=/Applications/Docker.app/Contents/Resources/bin/docker endif +ifeq ($(DETECTED_OS),Windows) + BINARY_EXT=.exe +endif TEST_FLAGS?= E2E_TEST?= @@ -40,7 +47,7 @@ all: build .PHONY: build ## Build the compose cli-plugin build: - CGO_ENABLED=0 GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose" ./cmd + CGO_ENABLED=0 GO111MODULE=on go build -trimpath -tags "$(GO_BUILDTAGS)" -ldflags "$(GO_LDFLAGS)" -o "$(DESTDIR)/docker-compose$(BINARY_EXT)" ./cmd .PHONY: binary binary: From 8714f983ac274527604add8509d80730598dec56 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Mon, 19 Sep 2022 15:28:59 -0400 Subject: [PATCH 4/9] Temporarily disable broken E2E tests on Windows Signed-off-by: Laura Brehm --- pkg/e2e/build_test.go | 90 ++++++++++++++++++++++++----------------- pkg/e2e/compose_test.go | 2 +- pkg/e2e/volumes_test.go | 4 ++ 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/pkg/e2e/build_test.go b/pkg/e2e/build_test.go index 0620f6e583..9be7f5b2f3 100644 --- a/pkg/e2e/build_test.go +++ b/pkg/e2e/build_test.go @@ -18,6 +18,7 @@ package e2e import ( "net/http" + "runtime" "strings" "testing" "time" @@ -85,6 +86,51 @@ func TestLocalComposeBuild(t *testing.T) { res.Assert(t, icmd.Expected{Out: `"RESULT": "SUCCESS"`}) }) + t.Run("build as part of up", func(t *testing.T) { + c.RunDockerOrExitError(t, "rmi", "build-test-nginx") + c.RunDockerOrExitError(t, "rmi", "custom-nginx") + + res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d") + t.Cleanup(func() { + c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "down") + }) + + res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) + res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"}) + + output := HTTPGetWithRetry(t, "http://localhost:8070", http.StatusOK, 2*time.Second, 20*time.Second) + assert.Assert(t, strings.Contains(output, "Hello from Nginx container")) + + c.RunDockerCmd(t, "image", "inspect", "build-test-nginx") + c.RunDockerCmd(t, "image", "inspect", "custom-nginx") + }) + + t.Run("no rebuild when up again", func(t *testing.T) { + res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d") + + assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout()) + }) + + t.Run("rebuild when up --build", func(t *testing.T) { + res := c.RunDockerComposeCmd(t, "--workdir", "fixtures/build-test", "up", "-d", "--build") + + res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) + res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"}) + }) + + t.Run("cleanup build project", func(t *testing.T) { + c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "down") + c.RunDockerCmd(t, "rmi", "build-test-nginx") + c.RunDockerCmd(t, "rmi", "custom-nginx") + }) +} + +func TestBuildSSH(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Running on Windows. Skipping...") + } + c := NewParallelCLI(t) + t.Run("build failed with ssh default value", func(t *testing.T) { res := c.RunDockerComposeCmdNoCheck(t, "--project-directory", "fixtures/build-test", "build", "--ssh", "") res.Assert(t, icmd.Expected{ @@ -130,47 +176,12 @@ func TestLocalComposeBuild(t *testing.T) { }) c.RunDockerCmd(t, "image", "inspect", "build-test-ssh") }) - - t.Run("build as part of up", func(t *testing.T) { - c.RunDockerOrExitError(t, "rmi", "build-test-nginx") - c.RunDockerOrExitError(t, "rmi", "custom-nginx") - - res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d") - t.Cleanup(func() { - c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "down") - }) - - res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) - res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"}) - - output := HTTPGetWithRetry(t, "http://localhost:8070", http.StatusOK, 2*time.Second, 20*time.Second) - assert.Assert(t, strings.Contains(output, "Hello from Nginx container")) - - c.RunDockerCmd(t, "image", "inspect", "build-test-nginx") - c.RunDockerCmd(t, "image", "inspect", "custom-nginx") - }) - - t.Run("no rebuild when up again", func(t *testing.T) { - res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d") - - assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout()) - }) - - t.Run("rebuild when up --build", func(t *testing.T) { - res := c.RunDockerComposeCmd(t, "--workdir", "fixtures/build-test", "up", "-d", "--build") - - res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) - res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"}) - }) - - t.Run("cleanup build project", func(t *testing.T) { - c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "down") - c.RunDockerCmd(t, "rmi", "build-test-nginx") - c.RunDockerCmd(t, "rmi", "custom-nginx") - }) } func TestBuildSecrets(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("skipping test on windows") + } c := NewParallelCLI(t) t.Run("build with secrets", func(t *testing.T) { @@ -259,6 +270,9 @@ func TestBuildImageDependencies(t *testing.T) { } func TestBuildPlatformsWithCorrectBuildxConfig(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Running on Windows. Skipping...") + } c := NewParallelCLI(t) // declare builder diff --git a/pkg/e2e/compose_test.go b/pkg/e2e/compose_test.go index de5d3c029a..0b8175b8a2 100644 --- a/pkg/e2e/compose_test.go +++ b/pkg/e2e/compose_test.go @@ -146,7 +146,7 @@ func TestAttachRestart(t *testing.T) { return strings.Count(res.Stdout(), "failing-1 exited with code 1") == 3, fmt.Sprintf("'failing-1 exited with code 1' not found 3 times in : \n%s\n", debug) - }, 2*time.Minute, 2*time.Second) + }, 3*time.Minute, 2*time.Second) assert.Equal(t, strings.Count(res.Stdout(), "failing-1 | world"), 3, res.Combined()) } diff --git a/pkg/e2e/volumes_test.go b/pkg/e2e/volumes_test.go index 76a9094b9a..2c9d47c25a 100644 --- a/pkg/e2e/volumes_test.go +++ b/pkg/e2e/volumes_test.go @@ -20,6 +20,7 @@ import ( "net/http" "os" "path/filepath" + "runtime" "strings" "testing" "time" @@ -99,6 +100,9 @@ func TestProjectVolumeBind(t *testing.T) { const projectName = "compose-e2e-project-volume-bind" t.Run("up on project volume with bind specification", func(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Running on Windows. Skipping...") + } tmpDir, err := os.MkdirTemp("", projectName) assert.NilError(t, err) defer os.RemoveAll(tmpDir) //nolint From 118b4f07e5e730fad82a9746597257f2ef8b2d4b Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Mon, 19 Sep 2022 16:03:06 -0400 Subject: [PATCH 5/9] Increase E2E test timeouts to reduce flakiness Signed-off-by: Laura Brehm --- pkg/e2e/compose_test.go | 2 +- pkg/e2e/pause_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/e2e/compose_test.go b/pkg/e2e/compose_test.go index 0b8175b8a2..5e46bf8622 100644 --- a/pkg/e2e/compose_test.go +++ b/pkg/e2e/compose_test.go @@ -146,7 +146,7 @@ func TestAttachRestart(t *testing.T) { return strings.Count(res.Stdout(), "failing-1 exited with code 1") == 3, fmt.Sprintf("'failing-1 exited with code 1' not found 3 times in : \n%s\n", debug) - }, 3*time.Minute, 2*time.Second) + }, 4*time.Minute, 2*time.Second) assert.Equal(t, strings.Count(res.Stdout(), "failing-1 | world"), 3, res.Combined()) } diff --git a/pkg/e2e/pause_test.go b/pkg/e2e/pause_test.go index d70d8cb382..066ebad6f9 100644 --- a/pkg/e2e/pause_test.go +++ b/pkg/e2e/pause_test.go @@ -46,7 +46,7 @@ func TestPause(t *testing.T) { "b": urlForService(t, cli, "b", 80), } for _, url := range urls { - HTTPGetWithRetry(t, url, http.StatusOK, 50*time.Millisecond, 5*time.Second) + HTTPGetWithRetry(t, url, http.StatusOK, 50*time.Millisecond, 20*time.Second) } // pause a and verify that it can no longer be hit but b still can From a1984ca1def89edf87929c7311056c0b7f26f529 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Mon, 19 Sep 2022 18:12:41 -0400 Subject: [PATCH 6/9] Skip some tests in CI due to flakiness Signed-off-by: Laura Brehm --- pkg/e2e/compose_test.go | 3 +++ pkg/e2e/pause_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/pkg/e2e/compose_test.go b/pkg/e2e/compose_test.go index 5e46bf8622..3eade16cc5 100644 --- a/pkg/e2e/compose_test.go +++ b/pkg/e2e/compose_test.go @@ -135,6 +135,9 @@ func TestDownComposefileInParentFolder(t *testing.T) { } func TestAttachRestart(t *testing.T) { + if _, ok := os.LookupEnv("CI"); ok { + t.Skip("Skipping test on CI... flaky") + } c := NewParallelCLI(t) cmd := c.NewDockerComposeCmd(t, "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up") diff --git a/pkg/e2e/pause_test.go b/pkg/e2e/pause_test.go index 066ebad6f9..a823814166 100644 --- a/pkg/e2e/pause_test.go +++ b/pkg/e2e/pause_test.go @@ -21,6 +21,7 @@ import ( "fmt" "net" "net/http" + "os" "testing" "time" @@ -29,6 +30,9 @@ import ( ) func TestPause(t *testing.T) { + if _, ok := os.LookupEnv("CI"); ok { + t.Skip("Skipping test on CI... flaky") + } cli := NewParallelCLI(t, WithEnv( "COMPOSE_PROJECT_NAME=e2e-pause", "COMPOSE_FILE=./fixtures/pause/compose.yaml")) From 6cd68a4bf240089ab841191b6bd01c4fc840d6dd Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Tue, 20 Sep 2022 11:07:37 -0400 Subject: [PATCH 7/9] Upgrade `actions/setup-go` to v3 Signed-off-by: Laura Brehm --- .github/workflows/merge.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 1f79b9cc98..64c94952b0 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -32,8 +32,7 @@ jobs: git config --global --add safe.directory C:/actions-runner/_work/compose/compose - uses: actions/checkout@v3 - # TODO(milas): revert to @v3 after next actions/setup-go minor release - - uses: actions/setup-go@f27981397569ab1d623dab1f29d3db81b75b5258 + - uses: actions/setup-go@v3 with: go-version-file: go.mod cache: true From 8891d9e2b5e13e1d510f4be2e9745e578ebc680c Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Wed, 21 Sep 2022 08:59:09 -0400 Subject: [PATCH 8/9] Streamline GHA workflow Signed-off-by: Laura Brehm --- .github/workflows/merge.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 64c94952b0..94259e522b 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -26,10 +26,6 @@ jobs: env: GO111MODULE: "on" steps: - - name: test-action-unsafe-checkout - if: ${{ contains(matrix.os, 'desktop-windows') }} - run: | - git config --global --add safe.directory C:/actions-runner/_work/compose/compose - uses: actions/checkout@v3 - uses: actions/setup-go@v3 @@ -38,12 +34,6 @@ jobs: cache: true check-latest: true - - name: Check arch of go binary - run: | - which go - file $(which go) - if: ${{ !contains(matrix.os, 'desktop-windows') }} - - name: List Docker resources on machine run: | docker ps --all From 0dc64723c9202a1e1f930f300f483edd77765996 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Wed, 21 Sep 2022 10:19:00 -0400 Subject: [PATCH 9/9] Restore `-s` in `uname` OS detection logic in `Makefile` Signed-off-by: Laura Brehm --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4c49ca3d3e..1e53b14c87 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ GO_BUILDTAGS ?= e2e,kube ifeq ($(OS),Windows_NT) DETECTED_OS = Windows else - DETECTED_OS = $(shell uname) + DETECTED_OS = $(shell uname -s) endif ifeq ($(DETECTED_OS),Linux) MOBY_DOCKER=/usr/bin/docker