Files
fredy/.github/workflows/docker.yml
Christian Kellner 9a09548a07 fix docker build
2025-05-15 10:16:43 +02:00

72 lines
1.9 KiB
YAML

name: Create and publish Docker image
on:
push:
branches:
- 'master'
tags:
- '*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/amd64,linux/arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image with cache & retry
run: |
set -e
for i in {1..3}; do
echo "Attempt $i of 3"
docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
--tag ${{ steps.meta.outputs.tags }} \
--label ${{ steps.meta.outputs.labels }} \
--cache-from=type=gha \
--cache-to=type=gha,mode=max \
.
status=$?
if [ $status -eq 0 ]; then
echo "Docker build succeeded on attempt $i"
break
else
echo "Docker build failed (attempt $i). Retrying in 10 seconds..."
sleep 10
fi
if [ $i -eq 3 ]; then
echo "Docker build failed after 3 attempts. Exiting with error."
exit 1
fi
done