Skip to content

Commit 58c477f

Browse files
authored
Merge pull request docker#9744 from crazy-max/cross
Better sandboxed workflow and enhanced cross compilation
2 parents e838930 + 5ec2029 commit 58c477f

File tree

18 files changed

+478
-481
lines changed

18 files changed

+478
-481
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
bin/
2-
dist/

.github/workflows/ci.yml

Lines changed: 171 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,217 @@
1-
name: Continuous integration
1+
name: ci
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
26

37
on:
48
push:
59
branches:
6-
- v2
10+
- 'v2'
11+
tags:
12+
- 'v*'
713
pull_request:
814
workflow_dispatch:
915
inputs:
1016
debug_enabled:
1117
description: 'To run with tmate enter "debug_enabled"'
1218
required: false
1319
default: "false"
20+
1421
env:
15-
GO_VERSION: 1.18.5
16-
DOCKER_CLI_VERSION: 20.10.17
22+
GO_VERSION: "1.18.5" # for non sandboxed e2e tests
23+
DESTDIR: "./bin"
24+
DOCKER_CLI_VERSION: "20.10.17"
25+
1726
jobs:
18-
lint:
19-
name: Lint
27+
prepare:
2028
runs-on: ubuntu-latest
29+
outputs:
30+
matrix: ${{ steps.platforms.outputs.matrix }}
2131
steps:
22-
- name: Checkout code into the Go module directory
32+
-
33+
name: Checkout
2334
uses: actions/checkout@v3
35+
-
36+
name: Create matrix
37+
id: platforms
38+
run: |
39+
echo ::set-output name=matrix::$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms')
40+
-
41+
name: Show matrix
42+
run: |
43+
echo ${{ steps.platforms.outputs.matrix }}
2444
25-
- name: Set up Go ${{ env.GO_VERSION }}
26-
uses: actions/setup-go@v3
27-
with:
28-
go-version: ${{ env.GO_VERSION }}
29-
cache: true
30-
31-
- name: Validate go-mod, license headers and docs are up-to-date
32-
run: make validate
33-
34-
- name: Run golangci-lint
35-
env:
36-
BUILD_TAGS: e2e
37-
uses: golangci/golangci-lint-action@v3
38-
with:
39-
version: v1.47.3
40-
args: --timeout=180s
41-
42-
# only on main branch, costs too much for the gain on every PR
43-
validate-cross-build:
44-
name: Validate cross build
45+
validate:
4546
runs-on: ubuntu-latest
46-
if: github.ref == 'refs/heads/main'
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
target:
51+
- lint
52+
- validate-go-mod
53+
- validate-headers
54+
- validate-docs
4755
steps:
48-
- name: Checkout code into the Go module directory
56+
-
57+
name: Checkout
4958
uses: actions/checkout@v3
59+
-
60+
name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v2
62+
-
63+
name: Run
64+
run: |
65+
make ${{ matrix.target }}
5066
51-
- name: Set up Go ${{ env.GO_VERSION }}
52-
uses: actions/setup-go@v3
67+
binary:
68+
runs-on: ubuntu-latest
69+
needs:
70+
- prepare
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
75+
steps:
76+
-
77+
name: Prepare
78+
run: |
79+
platform=${{ matrix.platform }}
80+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
81+
-
82+
name: Checkout
83+
uses: actions/checkout@v3
84+
-
85+
name: Set up QEMU
86+
uses: docker/setup-qemu-action@v2
87+
-
88+
name: Set up Docker Buildx
89+
uses: docker/setup-buildx-action@v2
90+
-
91+
name: Build
92+
uses: docker/bake-action@v2
5393
with:
54-
go-version: ${{ env.GO_VERSION }}
55-
cache: true
56-
57-
# Ensure we don't discover cross platform build issues at release time.
58-
# Time used to build linux here is gained back in the build for local E2E step
59-
- name: Build packages
60-
run: make -f builder.Makefile cross
94+
targets: release
95+
set: |
96+
*.platform=${{ matrix.platform }}
97+
*.cache-from=type=gha,scope=binary-${{ env.PLATFORM_PAIR }}
98+
*.cache-to=type=gha,scope=binary-${{ env.PLATFORM_PAIR }},mode=max
99+
-
100+
name: Upload artifacts
101+
uses: actions/upload-artifact@v3
102+
with:
103+
name: compose
104+
path: ${{ env.DESTDIR }}/*
105+
if-no-files-found: error
61106

62-
build-plugin:
63-
name: Build and tests in plugin mode
107+
test:
64108
runs-on: ubuntu-latest
65109
steps:
66-
- name: Checkout code into the Go module directory
110+
-
111+
name: Checkout
67112
uses: actions/checkout@v3
68-
69-
- name: Set up Go ${{ env.GO_VERSION }}
70-
uses: actions/setup-go@v3
113+
-
114+
name: Set up Docker Buildx
115+
uses: docker/setup-buildx-action@v2
116+
-
117+
name: Test
118+
uses: docker/bake-action@v2
71119
with:
72-
go-version: ${{ env.GO_VERSION }}
73-
cache: true
74-
75-
- name: Setup docker CLI
76-
run: |
77-
curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
78-
sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version
79-
80-
- name: Test
81-
run: make -f builder.Makefile test
82-
83-
- name: Build for local E2E
84-
env:
85-
BUILD_TAGS: e2e
86-
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
120+
targets: test
121+
set: |
122+
*.cache-from=type=gha,scope=test
123+
*.cache-to=type=gha,scope=test
87124
88-
- name: E2E Test in plugin mode
89-
run: make e2e-compose
90-
91-
build-standalone:
92-
name: Build and tests in standalone mode
125+
e2e:
93126
runs-on: ubuntu-latest
127+
env:
128+
DESTDIR: "./bin/build"
129+
strategy:
130+
fail-fast: false
131+
matrix:
132+
mode:
133+
- plugin
134+
- standalone
94135
steps:
95-
- name: Checkout code into the Go module directory
136+
-
137+
name: Checkout
96138
uses: actions/checkout@v3
97-
98-
- name: Set up Go ${{ env.GO_VERSION }}
139+
-
140+
name: Set up Docker Buildx
141+
uses: docker/setup-buildx-action@v2
142+
-
143+
name: Set up Go
99144
uses: actions/setup-go@v3
100145
with:
101146
go-version: ${{ env.GO_VERSION }}
102147
cache: true
103-
104-
- name: Setup docker CLI
148+
-
149+
name: Setup docker CLI
105150
run: |
106151
curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
107152
sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version
108-
109-
- name: Build for local E2E
153+
-
154+
name: Build
155+
uses: docker/bake-action@v2
156+
with:
157+
targets: binary
158+
set: |
159+
*.cache-from=type=gha,scope=binary-linux-amd64
160+
*.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
161+
*.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
110162
env:
111163
BUILD_TAGS: e2e
112-
run: make GIT_TAG=e2e-PR-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.sha }} -f builder.Makefile compose-plugin
113-
114-
- name: Setup tmate session
115-
uses: mxschmitt/action-tmate@v3
164+
-
165+
name: Setup tmate session
166+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
167+
uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
116168
with:
117169
limit-access-to-actor: true
118170
github-token: ${{ secrets.GITHUB_TOKEN }}
119-
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
120-
121-
- name: E2E Test in standalone mode
171+
-
172+
name: Test plugin mode
173+
if: ${{ matrix.mode == 'plugin' }}
174+
run: |
175+
make e2e-compose
176+
-
177+
name: Test standalone mode
178+
if: ${{ matrix.mode == 'standalone' }}
122179
run: |
123180
rm -f /usr/local/bin/docker-compose
124-
cp bin/docker-compose /usr/local/bin
181+
cp bin/build/docker-compose /usr/local/bin
125182
make e2e-compose-standalone
183+
184+
release:
185+
runs-on: ubuntu-latest
186+
needs:
187+
- binary
188+
steps:
189+
-
190+
name: Checkout
191+
uses: actions/checkout@v3
192+
-
193+
name: Download artifacts
194+
uses: actions/download-artifact@v3
195+
with:
196+
name: compose
197+
path: ${{ env.DESTDIR }}
198+
-
199+
name: License
200+
run: cp packaging/* ${{ env.DESTDIR }}/
201+
-
202+
name: List artifacts
203+
run: |
204+
tree -nh ${{ env.DESTDIR }}
205+
-
206+
name: Check artifacts
207+
run: |
208+
find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
209+
-
210+
name: GitHub Release
211+
if: startsWith(github.ref, 'refs/tags/v')
212+
uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
213+
with:
214+
artifacts: ${{ env.DESTDIR }}/*
215+
generateReleaseNotes: true
216+
draft: true
217+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
bin/
2-
dist/
32
/.vscode/

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
run:
22
concurrency: 2
3+
timeout: 10m
34
linters:
45
enable-all: false
56
disable-all: true

BUILDING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ Once you have the prerequisites installed, you can build the CLI using:
1919
make
2020
```
2121

22-
This will output a `docker-compose` CLI plugin for your host machine in `./bin`.
22+
This will output a `docker-compose` CLI plugin for your host machine in
23+
`./bin/build`.
2324

2425
You can statically cross compile the CLI for Windows, macOS, and Linux using the
2526
`cross` target.
@@ -38,7 +39,6 @@ If you need to update a golden file simply do `go test ./... -test.update-golden
3839
To run e2e tests, the Compose CLI binary need to be build. All the commands to run e2e tests propose a version
3940
with the prefix `build-and-e2e` to first build the CLI before executing tests.
4041

41-
4242
Note that this requires a local Docker Engine to be running.
4343

4444
#### Whole end-to-end tests suite
@@ -76,6 +76,7 @@ make e2e-compose-standalone
7676
```
7777

7878
Or if you need to build the CLI, run:
79+
7980
```console
8081
make build-and-e2e-compose-standalone
8182
```

0 commit comments

Comments
 (0)