Files
cdk/.github/workflows/docker-publish.yml

84 lines
2.5 KiB
YAML

name: Publish Docker Image AMD64
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Tag to build and publish'
required: true
default: 'latest'
env:
REGISTRY: docker.io
IMAGE_NAME: cashubtc/mintd
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=branch
type=ref,event=pr
type=sha
${{ github.event.inputs.tag != '' && github.event.inputs.tag || '' }}
# Build and push AMD64 image with architecture suffix
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}-amd64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Create and push multi-arch manifest if both images exist
- name: Create and push multi-arch manifest
run: |
# For each tag in the metadata output
echo "${{ steps.meta.outputs.tags }}" | while read -r tag; do
# Check if ARM64 image exists
if docker manifest inspect $tag-arm64 >/dev/null 2>&1; then
# Create manifest
docker manifest create $tag \
$tag-amd64 \
$tag-arm64
# Annotate the manifest with architecture specific information
docker manifest annotate $tag $tag-amd64 --arch amd64
docker manifest annotate $tag $tag-arm64 --arch arm64
# Push the manifest
docker manifest push $tag
else
echo "ARM64 image not found for $tag, skipping manifest creation"
fi
done