Some checks failed
Docker Build and Push (Multi-architecture) / build-and-push (push) Failing after 18s
86 lines
3.4 KiB
YAML
86 lines
3.4 KiB
YAML
name: Docker Build and Push (Multi-architecture)
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, experimental ]
|
|
tags: [ 'v*.*.*' ]
|
|
workflow_dispatch:
|
|
inputs:
|
|
image_tag:
|
|
description: 'Custom tag for the Docker image'
|
|
required: true
|
|
default: 'latest'
|
|
type: string
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
with:
|
|
platforms: arm64
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
with:
|
|
platforms: linux/amd64,linux/arm64
|
|
driver-opts: |
|
|
image=moby/buildkit:latest
|
|
|
|
- name: Log in to registry
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ${{ vars.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Determine Docker tags
|
|
id: tags
|
|
run: |
|
|
# Default tag from workflow_dispatch input
|
|
if [ -n "${{ github.event.inputs.image_tag }}" ]; then
|
|
PRIMARY_TAG="${{ github.event.inputs.image_tag }}"
|
|
# Tag for release (semantic version tag)
|
|
elif [[ ${{ github.ref }} == refs/tags/v* ]]; then
|
|
PRIMARY_TAG="${GITHUB_REF#refs/tags/}"
|
|
# Also create a major.minor tag (e.g., v1.2 for v1.2.3)
|
|
MAJOR_MINOR_TAG=$(echo "$PRIMARY_TAG" | sed -E 's/^v([0-9]+\.[0-9]+)\.[0-9]+.*$/v\1/')
|
|
if [[ "$MAJOR_MINOR_TAG" != "$PRIMARY_TAG" ]]; then
|
|
echo "major_minor_tag=$MAJOR_MINOR_TAG" >> $GITHUB_OUTPUT
|
|
fi
|
|
# Also create a major tag (e.g., v1 for v1.2.3)
|
|
MAJOR_TAG=$(echo "$PRIMARY_TAG" | sed -E 's/^v([0-9]+)\.[0-9]+\.[0-9]+.*$/v\1/')
|
|
if [[ "$MAJOR_TAG" != "$PRIMARY_TAG" ]]; then
|
|
echo "major_tag=$MAJOR_TAG" >> $GITHUB_OUTPUT
|
|
fi
|
|
# Tag for main branch
|
|
elif [[ ${{ github.ref }} == refs/heads/main ]]; then
|
|
PRIMARY_TAG="latest"
|
|
# Tag for experimental branch
|
|
elif [[ ${{ github.ref }} == refs/heads/experimental ]]; then
|
|
PRIMARY_TAG="experimental"
|
|
fi
|
|
|
|
echo "primary_tag=$PRIMARY_TAG" >> $GITHUB_OUTPUT
|
|
echo "Using primary tag: $PRIMARY_TAG"
|
|
|
|
# Always include SHA tag for traceability
|
|
echo "sha_tag=${{ github.sha }}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build and push multi-arch image
|
|
uses: docker/build-push-action@v4
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64,linux/arm64
|
|
push: true
|
|
cache-from: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache
|
|
cache-to: type=registry,ref=${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:cache,mode=max
|
|
tags: |
|
|
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.primary_tag }}
|
|
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.sha_tag }}
|
|
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.major_minor_tag }}
|
|
${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ steps.tags.outputs.major_tag }} |