Skip to content

Commit b8b4727

Browse files
committed
use bake matrix strategy
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent f88cc49 commit b8b4727

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1484
-3720
lines changed

.github/workflows/.build.yml

Lines changed: 121 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
envs:
1111
required: false
1212
type: string
13+
fail-fast:
14+
default: true
15+
required: false
16+
type: boolean
1317

1418
env:
1519
BUILD_CACHE_REGISTRY_SLUG: dockereng/packaging-cache
@@ -26,35 +30,66 @@ jobs:
2630
name: Checkout
2731
uses: actions/checkout@v4
2832
-
29-
name: Set outputs
30-
id: set
31-
run: |
32-
ghamatrix=$GHA_DEFAULT_MATRIX
33-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
34-
ghamatrix=${{ inputs.pkgs }}
35-
fi
36-
pkgs=$(make gha-matrix GHA_MATRIX=$ghamatrix)
37-
echo "pkgs=$pkgs" >> $GITHUB_OUTPUT
38-
if [ "${{ inputs.fail-fast }}" != "" ]; then
39-
failfast=${{ inputs.fail-fast }}
40-
else
41-
failfast=true
42-
fi
43-
echo "fail-fast=$failfast" >> $GITHUB_OUTPUT
44-
-
45-
name: Show outputs
46-
run: |
47-
echo pkgs=${{ steps.set.outputs.pkgs }}
48-
echo fail-fast=${{ steps.set.outputs.fail-fast }}
33+
name: Matrix
34+
id: matrix
35+
uses: actions/github-script@v7
36+
env:
37+
INPUT_NAME: ${{ inputs.name }}
38+
INPUT_FAIL-FAST: ${{ inputs.fail-fast }}
39+
with:
40+
script: |
41+
const inpName = core.getInput('name');
42+
const inpFailFast = core.getBooleanInput('fail-fast');
43+
44+
let def = {};
45+
await core.group(`Parsing definition`, async () => {
46+
const resPrint = await exec.getExecOutput('docker', ['buildx', 'bake', 'pkg', '--print'], {
47+
ignoreReturnCode: true
48+
});
49+
if (resPrint.stderr.length > 0 && resPrint.exitCode != 0) {
50+
throw new Error(res.stderr);
51+
}
52+
def = JSON.parse(resPrint.stdout.trim());
53+
});
54+
55+
await core.group(`Generating matrix`, async () => {
56+
const includes = [];
57+
for (const targetName of Object.keys(def.target)) {
58+
if (!targetName.startsWith(`pkg-${inpName}`)) {
59+
continue;
60+
}
61+
const match = targetName.match(/^pkg-(.+)-([^-]+)$/);
62+
if (!match) {
63+
throw new Error(`Invalid target name: ${targetName}`);
64+
}
65+
const pkgName = match[1];
66+
const distro = match[2];
67+
const target = def.target[targetName];
68+
if (target.platforms && target.platforms.length > 0) {
69+
target.platforms.forEach(platform => {
70+
includes.push({
71+
distro: distro,
72+
platform: platform
73+
});
74+
});
75+
} else {
76+
includes.push({
77+
distro: distro
78+
});
79+
}
80+
}
81+
core.info(JSON.stringify(includes, null, 2));
82+
core.setOutput('includes', JSON.stringify(includes));
83+
});
4984
5085
build:
5186
runs-on: ubuntu-24.04
5287
needs:
5388
- prepare
5489
strategy:
55-
fail-fast: ${{ needs.prepare.outputs.fail-fast == 'true' }}
90+
fail-fast: ${{ inputs.fail-fast }}
5691
matrix:
57-
pkg: ${{ fromJson(needs.prepare.outputs.pkgs) }}
92+
include: ${{ fromJson(needs.prepare.outputs.includes) }}
5893
steps:
5994
-
6095
name: Checkout
@@ -74,18 +109,10 @@ jobs:
74109
echo "BUILD_CACHE_REGISTRY_PUSH=1" >> $GITHUB_ENV
75110
fi
76111
# Limit to local platform for pkgs other than static for performance
77-
# reasons. See common/vars.mk and common/build.mk for more info on
78-
# filtered platforms
79-
if [ "${{ matrix.pkg }}" != "static" ]; then
112+
# reasons. See docker-bake.hcl for more info on filtered platforms.
113+
if [ "${{ matrix.distro }}" != "static" ]; then
80114
echo "LOCAL_PLATFORM=1" >> $GITHUB_ENV
81115
fi
82-
-
83-
name: Login to Docker Hub
84-
if: github.event_name != 'pull_request'
85-
uses: docker/login-action@v3
86-
with:
87-
username: ${{ secrets.DOCKERPUBLICBOT_USERNAME }}
88-
password: ${{ secrets.DOCKERPUBLICBOT_WRITE_PAT }}
89116
-
90117
name: Set up QEMU
91118
uses: docker/setup-qemu-action@v3
@@ -96,22 +123,26 @@ jobs:
96123
version: latest
97124
-
98125
name: Build
99-
run: |
100-
make -C pkg/${{ inputs.name }} run-pkg-${{ matrix.pkg }}
126+
uses: docker/bake-action@v6
127+
with:
128+
source: .
129+
targets: pkg-${{ inputs.name }}-${{ matrix.distro }}
130+
set: |
131+
*.platform=${{ matrix.platform }}
101132
-
102133
name: List artifacts
103134
run: |
104-
tree -nh ./pkg/${{ inputs.name }}/bin
105-
-
106-
name: Verify
107-
run: |
108-
make -C pkg/${{ inputs.name }} run-verify-${{ matrix.pkg }}
135+
tree -nh ./bin/pkg/${{ inputs.name }}
136+
# -
137+
# name: Verify
138+
# run: |
139+
# make -C pkg/${{ inputs.name }} run-verify-${{ matrix.pkg }}
109140
-
110141
name: Upload artifacts
111142
uses: actions/upload-artifact@v4
112143
with:
113-
name: build-pkg-${{ inputs.name }}-${{ matrix.pkg }}
114-
path: ./pkg/${{ inputs.name }}/bin/*
144+
name: build-pkg-${{ inputs.name }}-${{ matrix.distro }}
145+
path: ./bin/pkg/${{ inputs.name }}/*
115146
if-no-files-found: error
116147
retention-days: 1
117148

@@ -138,52 +169,56 @@ jobs:
138169
name: Download binaries
139170
uses: actions/download-artifact@v4
140171
with:
141-
path: ./pkg/${{ inputs.name }}/bin
172+
path: ./bin/pkg/${{ inputs.name }}
142173
pattern: build-pkg-*
143174
merge-multiple: true
144175
-
145-
name: Generate metadata
146-
run: |
147-
make -C pkg/${{ inputs.name }} metadata
148-
-
149-
name: Summary
150-
run: |
151-
for l in $(cat ./pkg/${{ inputs.name }}/bin/metadata.env); do
152-
export "${l?}"
153-
done
154-
155-
cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
156-
* repo: ${REPO}
157-
* ref: \`${REF}\`
158-
* version: \`${VERSION}\`
159-
* commit: [\`${COMMIT}\`](${REPO}/commit/${COMMIT})
160-
EOF
161-
162-
if [ "${{ inputs.name }}" = "containerd" ]; then
163-
cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
164-
* runc
165-
* repo: ${RUNC_REPO}
166-
* ref: \`${RUNC_REF}\`
167-
* version: \`${RUNC_VERSION}\`
168-
* commit: [\`${RUNC_COMMIT}\`](${RUNC_REPO}/commit/${RUNC_COMMIT})
169-
EOF
170-
fi
171-
172-
cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
173-
* packages: \`$(find ./pkg/${{ inputs.name }}/bin -type f | wc -l)\` files
174-
* size: \`$(du -sh ./pkg/${{ inputs.name }}/bin | awk '{print $1}')\`
175-
EOF
176-
-
177-
name: Release
178-
uses: docker/bake-action@v6
179-
with:
180-
workdir: ./pkg/${{ inputs.name }}
181-
source: .
182-
targets: release
183-
provenance: false
184-
set: |
185-
*.output=/tmp/release
186-
-
187-
name: List release artifacts
176+
name: List binaries
188177
run: |
189-
tree /tmp/release
178+
tree -nh ./bin/pkg/${{ inputs.name }}
179+
# -
180+
# name: Generate metadata
181+
# run: |
182+
# make -C pkg/${{ inputs.name }} metadata
183+
# -
184+
# name: Summary
185+
# run: |
186+
# for l in $(cat ./pkg/${{ inputs.name }}/bin/metadata.env); do
187+
# export "${l?}"
188+
# done
189+
#
190+
# cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
191+
# * repo: ${REPO}
192+
# * ref: \`${REF}\`
193+
# * version: \`${VERSION}\`
194+
# * commit: [\`${COMMIT}\`](${REPO}/commit/${COMMIT})
195+
# EOF
196+
#
197+
# if [ "${{ inputs.name }}" = "containerd" ]; then
198+
# cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
199+
# * runc
200+
# * repo: ${RUNC_REPO}
201+
# * ref: \`${RUNC_REF}\`
202+
# * version: \`${RUNC_VERSION}\`
203+
# * commit: [\`${RUNC_COMMIT}\`](${RUNC_REPO}/commit/${RUNC_COMMIT})
204+
# EOF
205+
# fi
206+
#
207+
# cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
208+
# * packages: \`$(find ./pkg/${{ inputs.name }}/bin -type f | wc -l)\` files
209+
# * size: \`$(du -sh ./pkg/${{ inputs.name }}/bin | awk '{print $1}')\`
210+
# EOF
211+
# -
212+
# name: Release
213+
# uses: docker/bake-action@v6
214+
# with:
215+
# workdir: ./pkg/${{ inputs.name }}
216+
# source: .
217+
# targets: release
218+
# provenance: false
219+
# set: |
220+
# *.output=/tmp/release
221+
# -
222+
# name: List release artifacts
223+
# run: |
224+
# tree /tmp/release

.github/workflows/build-buildx.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
paths:
2525
- '.github/workflows/.build.yml'
2626
- '.github/workflows/build-buildx.yml'
27-
- 'common/**'
27+
- 'hack/scripts/**'
2828
- 'pkg/buildx/**'
2929
pull_request:
3030
branches:
@@ -33,12 +33,13 @@ on:
3333
paths:
3434
- '.github/workflows/.build.yml'
3535
- '.github/workflows/build-buildx.yml'
36-
- 'common/**'
36+
- 'hack/scripts/**'
3737
- 'pkg/buildx/**'
3838

3939
jobs:
4040
run:
4141
uses: ./.github/workflows/.build.yml
4242
with:
4343
name: buildx
44+
fail-fast: ${{ inputs.fail-fast }}
4445
secrets: inherit

.github/workflows/build-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
paths:
2525
- '.github/workflows/.build.yml'
2626
- '.github/workflows/build-compose.yml'
27-
- 'common/**'
27+
- 'hack/scripts/**'
2828
- 'pkg/compose/**'
2929
pull_request:
3030
branches:
@@ -33,12 +33,13 @@ on:
3333
paths:
3434
- '.github/workflows/.build.yml'
3535
- '.github/workflows/build-compose.yml'
36-
- 'common/**'
36+
- 'hack/scripts/**'
3737
- 'pkg/compose/**'
3838

3939
jobs:
4040
run:
4141
uses: ./.github/workflows/.build.yml
4242
with:
4343
name: compose
44+
fail-fast: ${{ inputs.fail-fast }}
4445
secrets: inherit

.github/workflows/build-containerd.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
paths:
2525
- '.github/workflows/.build.yml'
2626
- '.github/workflows/build-containerd.yml'
27-
- 'common/**'
27+
- 'hack/scripts/**'
2828
- 'pkg/containerd/**'
2929
pull_request:
3030
branches:
@@ -33,12 +33,13 @@ on:
3333
paths:
3434
- '.github/workflows/.build.yml'
3535
- '.github/workflows/build-containerd.yml'
36-
- 'common/**'
36+
- 'hack/scripts/**'
3737
- 'pkg/containerd/**'
3838

3939
jobs:
4040
run:
4141
uses: ./.github/workflows/.build.yml
4242
with:
4343
name: containerd
44+
fail-fast: ${{ inputs.fail-fast }}
4445
secrets: inherit

.github/workflows/build-credential-helpers.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
paths:
2525
- '.github/workflows/.build.yml'
2626
- '.github/workflows/build-credential-helpers.yml'
27-
- 'common/**'
27+
- 'hack/scripts/**'
2828
- 'pkg/credential-helpers/**'
2929
pull_request:
3030
branches:
@@ -33,12 +33,13 @@ on:
3333
paths:
3434
- '.github/workflows/.build.yml'
3535
- '.github/workflows/build-credential-helpers.yml'
36-
- 'common/**'
36+
- 'hack/scripts/**'
3737
- 'pkg/credential-helpers/**'
3838

3939
jobs:
4040
run:
4141
uses: ./.github/workflows/.build.yml
4242
with:
4343
name: credential-helpers
44+
fail-fast: ${{ inputs.fail-fast }}
4445
secrets: inherit

.github/workflows/build-docker-cli.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
paths:
2525
- '.github/workflows/.build.yml'
2626
- '.github/workflows/build-docker-cli.yml'
27-
- 'common/**'
27+
- 'hack/scripts/**'
2828
- 'pkg/docker-cli/**'
2929
pull_request:
3030
branches:
@@ -33,12 +33,13 @@ on:
3333
paths:
3434
- '.github/workflows/.build.yml'
3535
- '.github/workflows/build-docker-cli.yml'
36-
- 'common/**'
36+
- 'hack/scripts/**'
3737
- 'pkg/docker-cli/**'
3838

3939
jobs:
4040
run:
4141
uses: ./.github/workflows/.build.yml
4242
with:
4343
name: docker-cli
44+
fail-fast: ${{ inputs.fail-fast }}
4445
secrets: inherit

0 commit comments

Comments
 (0)