CI: Add multi-platform image build

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-09-22 11:42:02 +02:00
parent 496ace34f4
commit 73209fc52c
No known key found for this signature in database
2 changed files with 21 additions and 14 deletions

View File

@ -18,6 +18,12 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: 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 - uses: actions/checkout@v4
with: with:
lfs: true lfs: true
@ -31,6 +37,15 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Build & Publish - 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:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.taggen.outputs.docker_build_tags }}
... ...

View File

@ -5,7 +5,7 @@ function log() {
echo "[$(date +%H:%M:%S)] $@" >&2 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." log "ERR: This script is intended to run on a Github Action only."
exit 1 exit 1
} }
@ -16,11 +16,11 @@ tags=()
case "${GITHUB_REF_TYPE}" in case "${GITHUB_REF_TYPE}" in
branch) branch)
# Generic build to develop: Workflow has to limit branches to master # Generic build to develop: Workflow has to limit branches to master
tags+=(develop) tags+=("${repo}:develop")
;; ;;
tag) tag)
# Build to latest & tag: Older tags are not intended to rebuild # 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." log "ERR: The ref type ${GITHUB_REF_TYPE} is not handled."
@ -28,13 +28,5 @@ tag)
;; ;;
esac esac
log "Building Docker image..." export IFS=,
docker build -t "${repo}:local" . echo "docker_build_tags=${tags[*]}" >>${GITHUB_OUTPUT}
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."