Skip to content

Instantly share code, notes, and snippets.

@ronoaldo
Created June 28, 2022 23:31
Show Gist options
  • Save ronoaldo/f0633752d9ea197c7fda542db65b4e56 to your computer and use it in GitHub Desktop.
Save ronoaldo/f0633752d9ea197c7fda542db65b4e56 to your computer and use it in GitHub Desktop.
Github Workflow to build and push multiarch docker image
name: Create and publish a multiarch Docker image
on:
push:
branches:
- 'main'
- 'issue**'
- '**/issue**'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
multiarch-build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- dockerfile: Dockerfile
platforms: |-
linux/amd64
linux/arm64
fail-fast: true
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3.5.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=r{{date 'YYYYMMDD'}}
- name: Set up QEMU for multiarch builds
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to the Container registry
uses: docker/login-action@v1.10.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.ref_name == 'main' }}
file: ${{ matrix.dockerfile }}
platforms: ${{ matrix.platforms }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment