Created
June 28, 2022 23:31
-
-
Save ronoaldo/f0633752d9ea197c7fda542db65b4e56 to your computer and use it in GitHub Desktop.
Github Workflow to build and push multiarch docker image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/[email protected] | |
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/[email protected] | |
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