Skip to content

Commit 7650d99

Browse files
authored
Merge pull request #269 from tomquist/fix-ci
Fix Docker image build
2 parents 1979e35 + 66bae0a commit 7650d99

3 files changed

Lines changed: 206 additions & 100 deletions

File tree

.github/workflows/build-image.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Build Image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
registry:
7+
required: true
8+
type: string
9+
description: "Container registry to use"
10+
platform:
11+
required: true
12+
type: string
13+
description: "Platform to build for (e.g. linux/amd64)"
14+
base:
15+
required: false
16+
type: string
17+
description: "Base image to use (e.g. distroless, alpine)"
18+
default: ""
19+
context:
20+
required: true
21+
type: string
22+
dockerfile:
23+
required: true
24+
type: string
25+
build-args:
26+
required: false
27+
type: string
28+
default: ""
29+
image-suffix:
30+
required: true
31+
type: string
32+
digest-prefix:
33+
required: true
34+
type: string
35+
runs-on:
36+
required: false
37+
type: string
38+
default: "ubuntu-latest"
39+
description: "The OS to run the job on. Defaults to ubuntu-latest."
40+
use-qemu:
41+
required: false
42+
type: boolean
43+
default: false
44+
description: "Whether to use QEMU for cross-platform builds. Defaults to false."
45+
46+
jobs:
47+
build:
48+
runs-on: ${{ inputs.runs-on }}
49+
permissions:
50+
contents: read
51+
packages: write
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v3
57+
if: ${{ inputs.use-qemu }}
58+
- id: lower-repo
59+
run: |
60+
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}${{ inputs.image-suffix }}" >> $GITHUB_OUTPUT
61+
- name: Extract metadata
62+
id: meta
63+
uses: docker/metadata-action@v5
64+
with:
65+
images: ${{ inputs.registry }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}
66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
- name: Log in to Container registry
69+
uses: docker/login-action@v3
70+
with:
71+
registry: ${{ inputs.registry }}
72+
username: ${{ github.actor }}
73+
password: ${{ secrets.GITHUB_TOKEN }}
74+
- name: Build
75+
if: github.event_name == 'pull_request'
76+
id: build
77+
uses: docker/build-push-action@v5
78+
with:
79+
context: ${{ inputs.context }}
80+
platforms: ${{ inputs.platform }}
81+
file: ${{ inputs.dockerfile }}
82+
push: false
83+
labels: ${{ steps.meta.outputs.labels }}
84+
outputs: type=image,name=${{ inputs.registry }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}
85+
build-args: |
86+
${{ inputs.build-args }}
87+
BASE=${{ inputs.base }}
88+
cache-from: type=gha
89+
cache-to: type=gha,mode=max
90+
- name: Build and push by digest
91+
if: github.event_name != 'pull_request'
92+
id: build-and-push
93+
uses: docker/build-push-action@v5
94+
with:
95+
context: ${{ inputs.context }}
96+
platforms: ${{ inputs.platform }}
97+
file: ${{ inputs.dockerfile }}
98+
push: true
99+
outputs: type=image,name=${{ inputs.registry }}/${{ steps.lower-repo.outputs.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
100+
labels: ${{ steps.meta.outputs.labels }}
101+
build-args: |
102+
${{ inputs.build-args }}
103+
BASE=${{ inputs.base }}
104+
cache-from: type=gha
105+
cache-to: type=gha,mode=max
106+
- name: Export digest
107+
if: github.event_name != 'pull_request'
108+
run: |
109+
mkdir -p /tmp/digests
110+
digest="${{ steps.build-and-push.outputs.digest }}"
111+
touch "/tmp/digests/${digest#sha256:}"
112+
- name: Set platform name
113+
id: platform
114+
run: |
115+
SAFE_PLATFORM=$(echo "${{ inputs.platform }}" | sed 's|/|-|g')
116+
echo "name=$SAFE_PLATFORM" >> $GITHUB_OUTPUT
117+
- name: Upload digest
118+
if: github.event_name != 'pull_request'
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: ${{ inputs.digest-prefix }}${{ steps.platform.outputs.name }}
122+
path: /tmp/digests/*
123+
if-no-files-found: error
124+
retention-days: 1

.github/workflows/ci.yml

Lines changed: 29 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ci
1+
name: CI Pipeline
22

33
on:
44
push:
@@ -13,124 +13,53 @@ on:
1313
- "main"
1414
- "dev"
1515

16-
env:
17-
REGISTRY: ghcr.io
16+
permissions:
17+
contents: read
18+
packages: write
1819

1920
jobs:
2021
build:
21-
runs-on: ubuntu-latest
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
include:
25+
config:
2626
- platform: linux/amd64
2727
base: distroless
28+
runs-on: ubuntu-24.04
29+
use-qemu: false
2830
- platform: linux/arm/v6
2931
base: alpine
32+
runs-on: ubuntu-22.04-arm
33+
use-qemu: true
3034
- platform: linux/arm/v7
3135
base: alpine
36+
runs-on: ubuntu-22.04-arm
37+
use-qemu: true
3238
- platform: linux/arm64
3339
base: distroless
34-
permissions:
35-
contents: read
36-
packages: write
37-
steps:
38-
- name: Checkout
39-
uses: actions/checkout@v4
40-
- name: Set up QEMU
41-
uses: docker/setup-qemu-action@v3
42-
- id: lower-repo
43-
run: |
44-
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
45-
- name: Extract metadata (tags, labels) for Docker
46-
id: meta
47-
uses: docker/metadata-action@v5
48-
with:
49-
images: ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}
50-
- name: Set up Docker Buildx
51-
uses: docker/setup-buildx-action@v3
52-
- name: Log in to the Container registry
53-
uses: docker/login-action@v3
54-
with:
55-
registry: ${{ env.REGISTRY }}
56-
username: ${{ github.actor }}
57-
password: ${{ secrets.GITHUB_TOKEN }}
58-
- name: Build
59-
if: github.event_name == 'pull_request'
60-
id: build
61-
uses: docker/build-push-action@v5
62-
with:
63-
context: .
64-
platforms: ${{ matrix.platform }}
65-
file: ./Dockerfile
66-
labels: ${{ steps.meta.outputs.labels }}
67-
outputs: type=docker,name=${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}
68-
build-args: BASE=${{ matrix.base }}
69-
- name: Build and push
70-
if: github.event_name != 'pull_request'
71-
id: build_push
72-
uses: docker/build-push-action@v5
73-
with:
74-
context: .
75-
platforms: ${{ matrix.platform }}
76-
file: ./Dockerfile
77-
labels: ${{ steps.meta.outputs.labels }}
78-
outputs: type=image,name=${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
79-
build-args: BASE=${{ matrix.base }}
80-
- name: Export digest
81-
if: github.event_name != 'pull_request'
82-
run: |
83-
mkdir -p /tmp/digests
84-
digest="${{ steps.build_push.outputs.digest }}"
85-
touch "/tmp/digests/${digest#sha256:}"
86-
- name: Upload digest
87-
if: github.event_name != 'pull_request'
88-
uses: actions/upload-artifact@v4
89-
with:
90-
name: digests
91-
path: /tmp/digests/*
92-
if-no-files-found: error
93-
retention-days: 1
94-
overwrite: true
40+
runs-on: ubuntu-24.04-arm
41+
use-qemu: false
42+
uses: ./.github/workflows/build-image.yml
43+
with:
44+
registry: ghcr.io
45+
platform: ${{ matrix.config.platform }}
46+
base: ${{ matrix.config.base }}
47+
runs-on: ${{ matrix.config.runs-on }}
48+
use-qemu: ${{ matrix.config.use-qemu }}
49+
context: .
50+
dockerfile: ./Dockerfile
51+
image-suffix: ""
52+
digest-prefix: "digests-base-"
9553

9654
merge:
97-
runs-on: ubuntu-latest
9855
if: github.event_name != 'pull_request'
99-
permissions:
100-
contents: read
101-
packages: write
10256
needs:
10357
- build
104-
steps:
105-
- name: Download digests
106-
uses: actions/download-artifact@v4
107-
with:
108-
name: digests
109-
path: /tmp/digests
110-
- name: Set up Docker Buildx
111-
uses: docker/setup-buildx-action@v3
112-
- id: lower-repo
113-
run: |
114-
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
115-
- name: Extract metadata (tags, labels) for Docker
116-
id: meta
117-
uses: docker/metadata-action@v5
118-
with:
119-
images: ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}
120-
- name: Log in to the Container registry
121-
uses: docker/login-action@v3
122-
with:
123-
registry: ${{ env.REGISTRY }}
124-
username: ${{ github.actor }}
125-
password: ${{ secrets.GITHUB_TOKEN }}
126-
- name: Create manifest list and push
127-
working-directory: /tmp/digests
128-
run: |
129-
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
130-
$(printf '${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}@sha256:%s ' *)
131-
- name: Inspect image
132-
run: |
133-
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
58+
uses: ./.github/workflows/merge-manifests.yml
59+
with:
60+
registry: ghcr.io
61+
image-suffix: ""
62+
digest-prefix: "digests-base-"
13463

13564
lint:
13665
runs-on: ubuntu-latest
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Merge Manifests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
registry:
7+
required: true
8+
type: string
9+
description: "Container registry to use"
10+
image-suffix:
11+
required: true
12+
type: string
13+
digest-prefix:
14+
required: true
15+
type: string
16+
17+
jobs:
18+
merge:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
steps:
24+
- name: Download digests
25+
uses: actions/download-artifact@v4
26+
with:
27+
pattern: ${{ inputs.digest-prefix }}*
28+
path: /tmp/digests
29+
merge-multiple: true
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
- id: lower-repo
33+
run: |
34+
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}${{ inputs.image-suffix }}" >> $GITHUB_OUTPUT
35+
- name: Extract metadata
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ inputs.registry }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}
40+
- name: Log in to Container registry
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ${{ inputs.registry }}
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
- name: Create manifest list and push
47+
working-directory: /tmp/digests
48+
run: |
49+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
50+
$(printf '${{ inputs.registry }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}@sha256:%s ' *)
51+
- name: Inspect image
52+
run: |
53+
docker buildx imagetools inspect ${{ inputs.registry }}/${{ steps.lower-repo.outputs.IMAGE_NAME }}:${{ steps.meta.outputs.version }}

0 commit comments

Comments
 (0)