CI: Docker improvements

- Multiple arches in the docker image
- Use the docker@metadata-action github action to create the tags and labels
- Push to Docker Hub and Github Container Repository
This commit is contained in:
Eric Allam
2023-06-24 10:15:52 +01:00
parent a816c52699
commit 7a3a9a6f7c
@@ -4,7 +4,11 @@ on:
push:
branches:
- main
- dev-q22023
tags:
- "v*"
pull_request:
branches:
- main
permissions:
id-token: write
@@ -49,22 +53,43 @@ jobs:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
- name: 🐳 Generate Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: 🐳 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
- name: 🐳 Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🐙 Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
- name: 🐳 Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ghcr.io/${{ github.repository }}:latest
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:latest
cache-to: type=inline