Skip to content

Add QEMU setup for Docker multi-platform support #22

Add QEMU setup for Docker multi-platform support

Add QEMU setup for Docker multi-platform support #22

name: Build and Push Docker Image
on:
push:
branches: [ main, master ]
tags: [ 'v*' ]
pull_request:
branches: [ main, master ]
workflow_dispatch: # Allow manual triggering
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
id: build-push
uses: docker/build-push-action@v5
with:
context: .
file: debian.dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/image.tar
- name: Get image size
id: image-size
run: |
# Load the image from the build step output
docker load < /tmp/image.tar
# Get the image ID from the loaded image
IMAGE_ID=$(docker images --format "{{.ID}}" | head -n 1)
echo "Using image ID: $IMAGE_ID"
# Get the image size
SIZE=$(docker image inspect $IMAGE_ID --format='{{.Size}}')
SIZE_MB=$(echo "scale=2; $SIZE/1024/1024" | bc)
echo "size=$SIZE_MB MB" >> $GITHUB_OUTPUT
echo "Image size: $SIZE_MB MB"