All checks were successful
Docker Build and Push (Multi-architecture) / build-and-push (push) Successful in 22s
89 lines
3.0 KiB
YAML
89 lines
3.0 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: Generate Docker tags
|
|
id: tags
|
|
run: |
|
|
# Base image name
|
|
IMAGE_NAME="${{ vars.REGISTRY }}/${{ github.repository_owner }}/${{ vars.IMAGE_NAME }}"
|
|
|
|
# Determine primary tag
|
|
if [ -n "${{ github.event.inputs.image_tag }}" ]; then
|
|
PRIMARY_TAG="${{ github.event.inputs.image_tag }}"
|
|
elif [[ ${{ github.ref }} == refs/tags/v* ]]; then
|
|
PRIMARY_TAG="${GITHUB_REF#refs/tags/}"
|
|
elif [[ ${{ github.ref }} == refs/heads/main ]]; then
|
|
PRIMARY_TAG="latest"
|
|
elif [[ ${{ github.ref }} == refs/heads/experimental ]]; then
|
|
PRIMARY_TAG="experimental"
|
|
else
|
|
PRIMARY_TAG="latest"
|
|
fi
|
|
|
|
# Start with primary tag and SHA tag
|
|
TAGS="$IMAGE_NAME:$PRIMARY_TAG,$IMAGE_NAME:${{ github.sha }}"
|
|
|
|
# Add version tags for releases
|
|
if [[ ${{ github.ref }} == refs/tags/v* ]]; then
|
|
# Add 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
|
|
TAGS="$TAGS,$IMAGE_NAME:$MAJOR_MINOR_TAG"
|
|
fi
|
|
|
|
# Add 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
|
|
TAGS="$TAGS,$IMAGE_NAME:$MAJOR_TAG"
|
|
fi
|
|
fi
|
|
|
|
echo "tags=$TAGS" >> $GITHUB_OUTPUT
|
|
echo "Generated tags: $TAGS"
|
|
|
|
- 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: ${{ steps.tags.outputs.tags }} |