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
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
@ -31,6 +37,15 @@ 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:
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
}
[[ -n $GITHUB_REF_NAME ]] || {
[[ -n ${GITHUB_REF_NAME:-} ]] || {
log "ERR: This script is intended to run on a Github Action only."
exit 1
}
@ -16,11 +16,11 @@ 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."
@ -28,13 +28,5 @@ tag)
;;
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}