Skip to content

Commit

Permalink
CI: Add multi-platform image build
Browse files Browse the repository at this point in the history
Signed-off-by: Knut Ahlers <[email protected]>
  • Loading branch information
Luzifer committed Sep 22, 2024
1 parent 496ace3 commit 516bf61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- uses: actions/checkout@v4
with:
lfs: true
Expand All @@ -31,6 +37,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Build & Publish
run: bash ci/docker-publish.sh
id: taggen
run: bash ci/docker-gen-tagnames.sh

- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.taggen.outputs.docker_build_tags }}

...
18 changes: 5 additions & 13 deletions ci/docker-publish.sh → ci/docker-gen-tagnames.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function log() {
echo "[$(date +%H:%M:%S)] $@" >&2
}

[[ -n $GITHUB_REF_NAME ]] || {
[[ -n ${GITHUB_REF_NAME:-} ]] || {
log "ERR: This script is intended to run on a Github Action only."
exit 1
}
Expand All @@ -16,25 +16,17 @@ tags=()
case "${GITHUB_REF_TYPE}" in
branch)
# Generic build to develop: Workflow has to limit branches to master
tags+=(develop)
tags+=("${repo}:develop")
;;
tag)
# Build to latest & tag: Older tags are not intended to rebuild
tags+=(latest ${GITHUB_REF_NAME})
tags+=("${repo}:latest" "${repo}:${GITHUB_REF_NAME}")
;;
*)
log "ERR: The ref type ${GITHUB_REF_TYPE} is not handled."
exit 1
;;
esac

log "Building Docker image..."
docker build -t "${repo}:local" .

for ref in "${tags[@]}"; do
log "Pushing Docker image to '${repo}:${ref}'..."
docker tag "${repo}:local" "${repo}:${ref}"
docker push "${repo}:${ref}"
done

log "Publish finished."
export IFS=,
echo "docker_build_tags=${tags[*]}" >>${GITHUB_OUTPUT}

0 comments on commit 516bf61

Please sign in to comment.