Skip to content

fix: update CI workflow for consistency, change manifest/digest logic #52

fix: update CI workflow for consistency, change manifest/digest logic

fix: update CI workflow for consistency, change manifest/digest logic #52

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: buildx
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract platform short name
id: platform
run: |
# Extract the architecture from the platform (e.g., amd64 from linux/amd64)
ARCH=$(echo "${{ matrix.platform }}" | cut -d/ -f2)
echo "arch=${ARCH}" >> $GITHUB_OUTPUT
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.tags }}-${{ steps.platform.outputs.arch }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
create-manifest:
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
- name: Create manifest list and push
run: |
# Get the first tag from meta outputs (without newlines)
FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
# Create manifest with both architecture images
docker buildx imagetools create \
--tag ${FIRST_TAG} \
${FIRST_TAG}-amd64 \
${FIRST_TAG}-arm64
- name: Inspect image
run: |
FIRST_TAG=$(echo "${{ steps.meta.outputs.tags }}" | head -n 1)
docker buildx imagetools inspect ${FIRST_TAG}