Skip to content

Commit

Permalink
Build arm64 Docker image (#115)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
felixvanoost authored Oct 24, 2023
1 parent 8da238d commit 90ca649
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 23 deletions.
101 changes: 79 additions & 22 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,101 @@
name: Create and publish a Docker image
name: Create and publish a multi-architecture Docker image

on:
push:
tags: ['v[0-9]+.[0-9]+.[0-9]+']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
IMAGE_NAME: ghcr.io/${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
build-image:
strategy:
fail-fast: false
matrix:
runner: [ubuntu-latest, buildjet-4vcpu-ubuntu-2204-arm]
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/[email protected]
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to the Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
- name: Build and export the image to Docker
uses: docker/build-push-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern=v{{version}}
- name: Build and push Docker image
uses: docker/[email protected]
context: .
load: true
tags: ${{ env.IMAGE_NAME }}:test
- name: Test the image
run: |
docker run --rm -i ${{ env.IMAGE_NAME }}:test < examples/nfldb.er >| nfldb.pdf
- name: Push the image by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
- name: Export the digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload the digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: example-diagram-nfldb
path: nfldb.pdf

merge-image:
runs-on: ubuntu-latest
needs:
- build-image
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
- name: Login to the Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# - Go to Preferences > Resources > Memory
# - and give docker more memory (eg: 4gb)

FROM haskell:8
FROM haskell:8-slim

WORKDIR /opt/erd

Expand Down

0 comments on commit 90ca649

Please sign in to comment.