Skip to content

Commit 90ca649

Browse files
authored
Build arm64 Docker image (#115)
* Run build action on push Hard-code tag for testing Fix Docker image name Attempt to build multi-arch image Free up runner disk space and disable Docker parallelism Attempt to build arm64 image only Test build on BuildJet arm64 runner Attempt to build images on native runners Remove duplicate 'runs-on' key Fix YAML syntax error Check ghcr.io login first Fix another YAML syntax issue This better work... Run build only on tags * Test Docker image after building * Store test diagram as an artifact * Don't push digest with tags * Test Docker image in interactive mode
1 parent 8da238d commit 90ca649

File tree

2 files changed

+80
-23
lines changed

2 files changed

+80
-23
lines changed

.github/workflows/build-image.yml

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,101 @@
1-
name: Create and publish a Docker image
1+
name: Create and publish a multi-architecture Docker image
22

33
on:
44
push:
55
tags: ['v[0-9]+.[0-9]+.[0-9]+']
66

77
env:
88
REGISTRY: ghcr.io
9-
IMAGE_NAME: ${{ github.repository }}
9+
IMAGE_NAME: ghcr.io/${{ github.repository }}
1010

1111
jobs:
12-
build-and-push-image:
13-
runs-on: ubuntu-latest
12+
build-image:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
runner: [ubuntu-latest, buildjet-4vcpu-ubuntu-2204-arm]
17+
runs-on: ${{ matrix.runner }}
1418
permissions:
1519
contents: read
1620
packages: write
17-
1821
steps:
1922
- name: Checkout repository
20-
uses: actions/checkout@v3
21-
22-
- name: Log in to the Container registry
23-
uses: docker/[email protected]
23+
uses: actions/checkout@v4
24+
- name: Docker meta
25+
id: meta
26+
uses: docker/metadata-action@v5
27+
with:
28+
images: ${{ env.IMAGE_NAME }}
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
- name: Login to the Container Registry
32+
uses: docker/login-action@v3
2433
with:
2534
registry: ${{ env.REGISTRY }}
2635
username: ${{ github.actor }}
2736
password: ${{ secrets.GITHUB_TOKEN }}
28-
29-
- name: Extract metadata (tags, labels) for Docker
30-
id: meta
31-
uses: docker/[email protected]
37+
- name: Build and export the image to Docker
38+
uses: docker/build-push-action@v5
3239
with:
33-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34-
tags: |
35-
type=semver,pattern=v{{version}}
36-
37-
- name: Build and push Docker image
38-
uses: docker/[email protected]
40+
context: .
41+
load: true
42+
tags: ${{ env.IMAGE_NAME }}:test
43+
- name: Test the image
44+
run: |
45+
docker run --rm -i ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| nfldb.pdf
46+
- name: Push the image by digest
47+
id: build
48+
uses: docker/build-push-action@v5
3949
with:
4050
context: .
41-
push: true
42-
tags: |
43-
${{ steps.meta.outputs.tags }}
4451
labels: ${{ steps.meta.outputs.labels }}
52+
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
53+
- name: Export the digest
54+
run: |
55+
mkdir -p /tmp/digests
56+
digest="${{ steps.build.outputs.digest }}"
57+
touch "/tmp/digests/${digest#sha256:}"
58+
- name: Upload the digest
59+
uses: actions/upload-artifact@v3
60+
with:
61+
name: digests
62+
path: /tmp/digests/*
63+
if-no-files-found: error
64+
retention-days: 1
65+
- name: Upload artifacts
66+
uses: actions/upload-artifact@v3
67+
with:
68+
name: example-diagram-nfldb
69+
path: nfldb.pdf
70+
71+
merge-image:
72+
runs-on: ubuntu-latest
73+
needs:
74+
- build-image
75+
steps:
76+
- name: Download digests
77+
uses: actions/download-artifact@v3
78+
with:
79+
name: digests
80+
path: /tmp/digests
81+
- name: Set up Docker Buildx
82+
uses: docker/setup-buildx-action@v3
83+
- name: Docker meta
84+
id: meta
85+
uses: docker/metadata-action@v5
86+
with:
87+
images: ${{ env.IMAGE_NAME }}
88+
- name: Login to the Container Registry
89+
uses: docker/login-action@v3
90+
with:
91+
registry: ${{ env.REGISTRY }}
92+
username: ${{ github.actor }}
93+
password: ${{ secrets.GITHUB_TOKEN }}
94+
- name: Create manifest list and push
95+
working-directory: /tmp/digests
96+
run: |
97+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
98+
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)
99+
- name: Inspect image
100+
run: |
101+
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# - Go to Preferences > Resources > Memory
1515
# - and give docker more memory (eg: 4gb)
1616

17-
FROM haskell:8
17+
FROM haskell:8-slim
1818

1919
WORKDIR /opt/erd
2020

0 commit comments

Comments
 (0)