Skip to content

Commit 454d75c

Browse files
Updates build/release workflows
1 parent 26ae08e commit 454d75c

File tree

3 files changed

+239
-14
lines changed

3 files changed

+239
-14
lines changed

.github/workflows/build.yml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: Build / Test / Push
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
workflow_call:
8+
workflow_dispatch:
9+
10+
env:
11+
BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }}
12+
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'
13+
14+
jobs:
15+
build:
16+
runs-on: ${{ matrix.runner }}
17+
outputs:
18+
build-image-arm: ${{ steps.gen-output.outputs.image-arm64 }}
19+
build-image-x64: ${{ steps.gen-output.outputs.image-x64 }}
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
runner:
24+
- ubuntu-24.04
25+
- ubuntu-24.04-arm
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- id: build-meta
41+
name: Docker meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ghcr.io/${{ github.repository }}
45+
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}
46+
47+
# Build cache is shared among all builds of the same architecture
48+
- id: cache-meta
49+
name: Docker meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ghcr.io/${{ github.repository }}
53+
tags: type=raw,value=buildcache-${{ runner.arch }}
54+
55+
- id: get-registry
56+
name: Get the sanitized registry name
57+
run: |
58+
echo "registry=$(echo '${{ steps.build-meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT"
59+
60+
- id: build
61+
name: Build/push the arch-specific image
62+
uses: docker/build-push-action@v6
63+
with:
64+
cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
65+
cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
66+
labels: ${{ steps.build-meta.outputs.labels }}
67+
provenance: mode=max
68+
sbom: true
69+
tags: ${{ steps.get-registry.outputs.registry }}
70+
outputs: type=image,push-by-digest=true,push=true
71+
72+
- id: gen-output
73+
name: Write arch-specific image digest to outputs
74+
run: |
75+
echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"
76+
77+
merge:
78+
runs-on: ubuntu-24.04
79+
needs:
80+
- build
81+
env:
82+
DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.build-image-arm }}
83+
DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.build-image-x64 }}
84+
outputs:
85+
build-image: ${{ steps.meta.outputs.tags }}
86+
steps:
87+
- name: Checkout code
88+
uses: actions/checkout@v4
89+
90+
- name: Set up Docker Buildx
91+
uses: docker/setup-buildx-action@v3
92+
93+
- name: Login to GitHub Container Registry
94+
uses: docker/login-action@v3
95+
with:
96+
registry: ghcr.io
97+
username: ${{ github.actor }}
98+
password: ${{ secrets.GITHUB_TOKEN }}
99+
100+
- name: Docker meta
101+
id: meta
102+
uses: docker/metadata-action@v5
103+
with:
104+
images: ghcr.io/${{ github.repository }}
105+
tags: |
106+
type=sha,suffix=-build-${{ github.run_id }}_${{ github.run_attempt }}
107+
108+
- name: Push the multi-platform image
109+
run: |
110+
docker buildx imagetools create \
111+
--tag "$DOCKER_METADATA_OUTPUT_TAGS" \
112+
"$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64"
113+
114+
test:
115+
runs-on: ubuntu-24.04
116+
needs:
117+
- merge
118+
env:
119+
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
120+
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.build-image }}
121+
steps:
122+
- name: Checkout code
123+
uses: actions/checkout@v4
124+
125+
- name: Set up Docker Compose
126+
uses: docker/setup-compose-action@v1
127+
128+
- name: Login to GitHub Container Registry
129+
uses: docker/login-action@v3
130+
with:
131+
registry: ghcr.io
132+
username: ${{ github.actor }}
133+
password: ${{ secrets.GITHUB_TOKEN }}
134+
135+
- name: Setup the stack
136+
run: |
137+
docker compose pull --quiet
138+
docker compose up --detach --wait
139+
140+
- name: Run the test script
141+
run: |
142+
docker compose exec app bin/test
143+
144+
push:
145+
runs-on: ubuntu-24.04
146+
needs:
147+
- merge
148+
- test
149+
env:
150+
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.build-image }}
151+
steps:
152+
- name: Checkout code
153+
uses: actions/checkout@v4
154+
155+
- name: Login to GitHub Container Registry
156+
uses: docker/login-action@v3
157+
with:
158+
registry: ghcr.io
159+
username: ${{ github.actor }}
160+
password: ${{ secrets.GITHUB_TOKEN }}
161+
162+
- name: Produce permanent image tags
163+
id: branch-meta
164+
uses: docker/metadata-action@v5
165+
with:
166+
images: ghcr.io/${{ github.repository }}
167+
tags: |
168+
type=sha
169+
type=ref,event=branch
170+
type=raw,value=latest,enable={{is_default_branch}}
171+
172+
- name: Retag and push the image
173+
run: |
174+
docker pull "$DOCKER_APP_IMAGE"
175+
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$DOCKER_APP_IMAGE"
176+
docker push --all-tags "$(echo "$DOCKER_APP_IMAGE" | cut -f1 -d:)"

.github/workflows/docker-ci.yml

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

.github/workflows/release.yml

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

0 commit comments

Comments
 (0)