Skip to content

Commit d5c9b4b

Browse files
authored
AP-735: use shared GHA workflows to ensure multi-arch builds (#25)
1 parent 1ef338c commit d5c9b4b

2 files changed

Lines changed: 21 additions & 182 deletions

File tree

.github/workflows/build.yml

Lines changed: 15 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -6,111 +6,20 @@ on:
66
- '**'
77
workflow_dispatch:
88

9-
env:
10-
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
119

1210
jobs:
13-
build:
14-
runs-on: ${{ matrix.runner }}
15-
outputs:
16-
build-image-arm: ${{ steps.gen-output.outputs.image-arm64 }}
17-
build-image-x64: ${{ steps.gen-output.outputs.image-x64 }}
18-
strategy:
19-
fail-fast: false
20-
matrix:
21-
runner:
22-
- ubuntu-24.04
23-
- ubuntu-24.04-arm
24-
steps:
25-
- name: Checkout code
26-
uses: actions/checkout@v4
27-
28-
- name: Set up Docker Buildx
29-
uses: docker/setup-buildx-action@v3
30-
31-
- name: Login to GitHub Container Registry
32-
uses: docker/login-action@v3
33-
with:
34-
registry: ghcr.io
35-
username: ${{ github.actor }}
36-
password: ${{ secrets.GITHUB_TOKEN }}
37-
38-
- name: Docker meta
39-
id: meta
40-
uses: docker/metadata-action@v5
41-
with:
42-
images: ghcr.io/${{ github.repository }}
43-
# note Specifies a single tag to ensure the default doesn't add more than one.
44-
# The actual tag is not used, this is just used to sanitize the registry name
45-
# and produce labels.
46-
tags: type=sha
47-
48-
- name: Sanitize registry repository name
49-
id: get-reg
50-
run: |
51-
echo "registry=$(echo '${{ steps.meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT"
52-
53-
- name: Build/push the arch-specific image
54-
id: build
55-
uses: docker/build-push-action@v6
56-
with:
57-
# @todo GHA caching needs tuning, these tend not to hit. Perhaps switch to type=registry?
58-
cache-from: type=gha
59-
cache-to: type=gha,mode=max
60-
labels: ${{ steps.meta.outputs.labels }}
61-
provenance: mode=max
62-
sbom: true
63-
tags: ${{ steps.get-reg.outputs.registry }}
64-
outputs: type=image,push-by-digest=true,push=true
65-
66-
- name: Write arch-specific image digest to outputs
67-
id: gen-output
68-
run: |
69-
echo "image-${RUNNER_ARCH,,}=${{ steps.get-reg.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"
70-
71-
merge:
72-
runs-on: ubuntu-24.04
73-
needs:
74-
- build
75-
env:
76-
DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.build-image-arm }}
77-
DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.build-image-x64 }}
78-
outputs:
79-
build-image: ${{ steps.meta.outputs.tags }}
80-
steps:
81-
- name: Checkout code
82-
uses: actions/checkout@v4
83-
84-
- name: Set up Docker Buildx
85-
uses: docker/setup-buildx-action@v3
86-
87-
- name: Login to GitHub Container Registry
88-
uses: docker/login-action@v3
89-
with:
90-
registry: ghcr.io
91-
username: ${{ github.actor }}
92-
password: ${{ secrets.GITHUB_TOKEN }}
93-
94-
- name: Docker meta
95-
id: meta
96-
uses: docker/metadata-action@v5
97-
with:
98-
images: ghcr.io/${{ github.repository }}
99-
tags: |
100-
type=sha,suffix=-build-${{ github.run_id }}_${{ github.run_attempt }}
101-
102-
- name: Push the multi-platform image
103-
run: |
104-
docker buildx imagetools create \
105-
--tag "$DOCKER_METADATA_OUTPUT_TAGS" \
106-
"$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64"
11+
docker-build:
12+
uses: BerkeleyLibrary/.github/.github/workflows/docker-build.yml@v2.0.0
13+
with:
14+
image: ghcr.io/${{ github.repository }}
15+
secrets: inherit
10716

10817
test:
10918
runs-on: ubuntu-latest
11019
needs:
111-
- merge
20+
- docker-build
11221
container:
113-
image: ${{ needs.merge.outputs.build-image }}
22+
image: ${{ needs.docker-build.outputs.image }}
11423
defaults:
11524
run:
11625
working-directory: /opt/app
@@ -138,41 +47,18 @@ jobs:
13847

13948
- name: Upload artifacts
14049
if: ${{ always() }}
141-
uses: actions/upload-artifact@v4
50+
uses: actions/upload-artifact@v7
14251
with:
14352
name: artifacts
14453
path: artifacts/**
14554

14655
push:
147-
runs-on: ubuntu-24.04
14856
needs:
149-
- merge
57+
- docker-build
15058
- test
151-
env:
152-
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.build-image }}
153-
steps:
154-
- name: Checkout code
155-
uses: actions/checkout@v4
156-
157-
- name: Login to GitHub Container Registry
158-
uses: docker/login-action@v3
159-
with:
160-
registry: ghcr.io
161-
username: ${{ github.actor }}
162-
password: ${{ secrets.GITHUB_TOKEN }}
163-
164-
- name: Produce permanent image tags
165-
id: branch-meta
166-
uses: docker/metadata-action@v5
167-
with:
168-
images: ghcr.io/${{ github.repository }}
169-
tags: |
170-
type=sha
171-
type=ref,event=branch
172-
type=raw,value=latest,enable={{is_default_branch}}
173-
174-
- name: Retag and push the image
175-
run: |
176-
docker pull "$DOCKER_APP_IMAGE"
177-
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$DOCKER_APP_IMAGE"
178-
docker push --all-tags "$(echo "$DOCKER_APP_IMAGE" | cut -f1 -d:)"
59+
uses: BerkeleyLibrary/.github/.github/workflows/docker-push.yml@v2.0.0
60+
with:
61+
image: ghcr.io/${{ github.repository }}
62+
build-image-arm64: ${{ needs.docker-build.outputs.image-arm64 }}
63+
build-image-x64: ${{ needs.docker-build.outputs.image-x64 }}
64+
secrets: inherit

.github/workflows/release.yml

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,12 @@ on:
44
push:
55
tags:
66
- '**'
7+
workflow_call:
78
workflow_dispatch:
89

9-
env:
10-
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
11-
1210
jobs:
13-
retag:
14-
runs-on: ubuntu-latest
15-
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v4
18-
19-
- name: Set up QEMU
20-
uses: docker/setup-qemu-action@v3
21-
22-
- name: Set up Docker Buildx
23-
uses: docker/setup-buildx-action@v3
24-
25-
- name: Login to GitHub Container Registry
26-
uses: docker/login-action@v3
27-
with:
28-
registry: ghcr.io
29-
username: ${{ github.actor }}
30-
password: ${{ secrets.GITHUB_TOKEN }}
31-
32-
- name: Determine the sha-based image tag to retag
33-
id: get-base-image
34-
uses: docker/metadata-action@v5
35-
with:
36-
images: ghcr.io/${{ github.repository }}
37-
tags: type=sha
38-
39-
- name: Verify that the image was previously built
40-
env:
41-
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
42-
run: |
43-
docker pull "$BASE_IMAGE"
44-
45-
- name: Produce release tags
46-
id: tag-meta
47-
uses: docker/metadata-action@v5
48-
with:
49-
images: ghcr.io/${{ github.repository }}
50-
flavor: latest=false
51-
tags: |
52-
type=ref,event=tag
53-
type=semver,pattern={{major}}
54-
type=semver,pattern={{major}}.{{minor}}
55-
type=semver,pattern={{version}}
56-
57-
- name: Retag the pulled image
58-
env:
59-
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
60-
run: |
61-
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$BASE_IMAGE"
62-
docker push --all-tags "$(echo "$BASE_IMAGE" | cut -f1 -d:)"
11+
release:
12+
uses: BerkeleyLibrary/.github/.github/workflows/docker-release.yml@v2.0.0
13+
with:
14+
image: ghcr.io/${{ github.repository }}
15+
secrets: inherit

0 commit comments

Comments
 (0)