Skip to content

Commit a7ec450

Browse files
fix(docker): simplify artifact extraction
1 parent 33893a3 commit a7ec450

1 file changed

Lines changed: 45 additions & 37 deletions

File tree

.github/workflows/__call-docker.yml

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
# Comma separated list of platforms to run for PR events, i.e. `# platforms_pr: linux/amd64`. This will take
1212
# precedence over the `# platforms: ` directive.
1313
# `# artifacts: `
14-
# `true` to build in two steps, stopping at `artifacts` build stage and extracting the image from there to the
15-
# GitHub runner.
14+
# `true` to extract artifacts from the `/artifacts` directory to the GitHub runner.
1615

1716
name: Docker (called)
1817
permissions:
@@ -121,6 +120,36 @@ jobs:
121120
fail-fast: false
122121
matrix: ${{ fromJson(needs.check_dockerfiles.outputs.matrix) }}
123122
steps:
123+
124+
# TODO: remove me
125+
- name: Testing Artifacts
126+
run: |
127+
# create directory tree
128+
mkdir -p artifacts
129+
mkdir -p image/artifacts
130+
mkdir -p image/linux_amd64/artifacts
131+
touch image/artifacts/main_test.txt
132+
touch image/artifacts/main_test2.txt
133+
touch image/linux_amd64/artifacts/linux_amd64_test1.txt
134+
touch image/linux_amd64/artifacts/linux_amd64_test2.txt
135+
136+
# artifacts will be in sub directories named after the docker target platform, e.g. `linux_amd64`
137+
# so move files to the artifacts directory
138+
# https://unix.stackexchange.com/a/52816
139+
echo "::group::Moving artifacts"
140+
find \
141+
./image \
142+
-mindepth 1 \
143+
-maxdepth 3 \
144+
-type d \
145+
-name 'artifacts' \
146+
-exec bash -c 'cp -rv {}/* ./artifacts/' \;
147+
echo "::endgroup::"
148+
149+
echo "::group::Artifacts"
150+
ls -la ./artifacts/
151+
echo "::endgroup::"
152+
124153
- name: Maximize build space
125154
if: inputs.maximize_build_space
126155
uses: easimon/maximize-build-space@v10
@@ -259,29 +288,6 @@ jobs:
259288
username: ${{ secrets.GH_BOT_NAME }}
260289
password: ${{ secrets.GH_BOT_TOKEN }}
261290

262-
- name: Build artifacts
263-
if: steps.prepare.outputs.artifacts == 'true'
264-
id: build_artifacts
265-
uses: docker/build-push-action@v6
266-
with:
267-
context: ./
268-
file: ${{ matrix.dockerfile }}
269-
target: artifacts
270-
outputs: type=local,dest=artifacts
271-
push: false
272-
platforms: ${{ steps.prepare.outputs.platforms }}
273-
build-args: |
274-
BRANCH=${{ steps.prepare.outputs.branch }}
275-
BUILD_DATE=${{ steps.prepare.outputs.build_date }}
276-
BUILD_VERSION=${{ inputs.release_tag }}
277-
COMMIT=${{ inputs.release_commit }}
278-
CLONE_URL=${{ steps.prepare.outputs.clone_url }}
279-
RELEASE=${{ inputs.publish_release }}
280-
tags: ${{ steps.prepare.outputs.tags }}
281-
cache-from: type=local,src=/tmp/.buildx-cache
282-
cache-to: type=local,dest=/tmp/.buildx-cache
283-
no-cache-filters: ${{ steps.prepare.outputs.no_cache_filters }}
284-
285291
- name: Build and push
286292
id: build
287293
uses: docker/build-push-action@v6
@@ -301,34 +307,36 @@ jobs:
301307
cache-from: type=local,src=/tmp/.buildx-cache
302308
cache-to: type=local,dest=/tmp/.buildx-cache
303309
no-cache-filters: ${{ steps.prepare.outputs.no_cache_filters }}
310+
outputs: ${{ steps.prepare.outputs.artifacts == 'true' && 'type=local,dest=image' || '' }}
304311

305312
- name: Arrange Artifacts
306313
if: steps.prepare.outputs.artifacts == 'true'
307-
working-directory: artifacts
308314
run: |
309-
# debug directory
310-
echo "Current directory: $(pwd)"
311-
echo "Directory contents: $(ls -Ra)"
315+
# create artifacts directory
316+
mkdir -p artifacts
312317
313318
# artifacts will be in sub directories named after the docker target platform, e.g. `linux_amd64`
314319
# so move files to the artifacts directory
315320
# https://unix.stackexchange.com/a/52816
321+
echo "::group::Moving artifacts"
316322
find \
317-
./ \
318-
-maxdepth 2 \
323+
./image \
319324
-mindepth 2 \
320-
-type f \
321-
-not -name 'provenance.json' \
322-
-exec mv -t ./ -n '{}' +
325+
-maxdepth 3 \
326+
-type d \
327+
-name 'artifacts' \
328+
-exec mv {}/* artifacts/ \;
329+
echo "::endgroup::"
323330
324-
# remove provenance file
325-
rm -f ./provenance.json
331+
echo "::group::Artifacts"
332+
ls -la ../artifacts/
333+
echo "::endgroup::"
326334
327335
- name: Upload Artifacts
328336
if: steps.prepare.outputs.artifacts == 'true'
329337
uses: actions/upload-artifact@v4
330338
with:
331-
name: Docker${{ matrix.tag }}
339+
name: build-Docker${{ matrix.tag }}
332340
path: artifacts/
333341
if-no-files-found: error
334342

0 commit comments

Comments
 (0)