Skip to content

try fixing build pipeline #48

try fixing build pipeline

try fixing build pipeline #48

Workflow file for this run

name: Docker
on:
push:
# Only build Docker images when a tag is pushed
tags: [ '*.*.*' ]
# Also allow manual triggering for testing
workflow_dispatch:
env:
REGISTRY: ghcr.io
jobs:
setup:
runs-on: ubuntu-latest
outputs:
lowercase_image_name: ${{ steps.image-name.outputs.lowercase_image_name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ steps.set-platforms.outputs.platforms }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set lowercase image name
id: image-name
run: echo "lowercase_image_name=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ steps.image-name.outputs.lowercase_image_name }}
- name: Set platforms
id: set-platforms
run: |
echo "platforms=[\"linux/amd64\", \"linux/arm64\", \"linux/arm/v7\"]" >> $GITHUB_OUTPUT
build:
needs: setup
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
strategy:
fail-fast: false # Allow other platforms to continue building if one fails
matrix:
platform: ${{ fromJson(needs.setup.outputs.platforms) }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get platform short name
id: platform-name
run: |
PLATFORM="${{ matrix.platform }}"
SHORT_NAME=$(echo $PLATFORM | sed -e 's/linux\///' -e 's/\//-/')
echo "short_name=${SHORT_NAME}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
platforms: ${{ matrix.platform }}
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ needs.setup.outputs.lowercase_image_name }}-${{ steps.platform-name.outputs.short_name }}:${{ github.ref_name || 'latest' }}
labels: ${{ needs.setup.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Final job to create and push the multi-platform manifest
create-manifest:
needs: [setup, build]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against registry
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Create and push manifest
- name: Create and push multi-platform manifest
run: |
IMAGE_NAME="${{ env.REGISTRY }}/${{ needs.setup.outputs.lowercase_image_name }}"
TAG="${{ github.ref_name || 'latest' }}"
platforms='["linux/amd64", "linux/arm64", "linux/arm/v7"]'
# Clear any existing manifests with these names first
docker manifest rm "${IMAGE_NAME}:${TAG}" 2>/dev/null || true
docker manifest rm "${IMAGE_NAME}:latest" 2>/dev/null || true
# Create new manifests
manifest_create_args=""
for platform in $(echo $platforms | jq -r '.[]'); do
short_name=$(echo $platform | sed -e 's/linux\///' -e 's/\//-/')
platform_tag="${IMAGE_NAME}-${short_name}:${TAG}"
# Verify image exists before adding to manifest
docker manifest inspect "${platform_tag}" >/dev/null 2>&1 || { echo "Image ${platform_tag} not found"; continue; }
manifest_create_args="${manifest_create_args} --amend ${platform_tag}"
done
# Create and push the manifests if we have images to include
if [ -n "${manifest_create_args}" ]; then
docker manifest create "${IMAGE_NAME}:${TAG}" ${manifest_create_args}
docker manifest create "${IMAGE_NAME}:latest" ${manifest_create_args}
docker manifest push "${IMAGE_NAME}:${TAG}"
docker manifest push "${IMAGE_NAME}:latest"
else
echo "No valid platform images found to include in manifest"
exit 1
fi