Docker Build & Publish #558
This file contains 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: Docker Build & Publish | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
push: | |
paths-ignore: | |
- '**.md' | |
branches: [ master ] | |
tags: [ 'v*.*.*' ] | |
pull_request: | |
branches: [ master ] | |
paths-ignore: | |
- '**.md' | |
schedule: | |
- cron: '00 20 * * 0-5' | |
workflow_dispatch: | |
env: | |
# Use docker.io for Docker Hub if empty | |
#REGISTRY: ghcr.io | |
REGISTRY: docker.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
#TAG_LATEST: bullseye | |
# vars.DOCKER_EXTPORT_TAG: github repository variables. | |
TAG_LATEST: ${{ vars.DOCKER_EXPORT_TAG}} | |
PLATFORMS: linux/amd64,linux/arm64 | |
#BASE_IMG: debian:bullseye | |
#BASE_IMG: python:3.11-bullseye | |
# vars.DOCKER_BASE_IMG: github repository variables. | |
BASE_IMG: ${{ vars.DOCKER_BASE_IMG}} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: adjust image name from ${{ github.repository }} | |
run: | | |
echo IMAGE_NAME=${{ env.IMAGE_NAME }} | sed 's/docker-//' >> $GITHUB_ENV | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# prepare multi-arch build for docker image, cf. https://docs.docker.com/build/ci/github-actions/multi-platform/ | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
# Login against a Docker registry except on PR https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
# password: ${{ secrets.GITHUB_TOKEN }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=semver,pattern={{raw}} | |
type=schedule,pattern=${{env.TAG_LATEST}} | |
type=ref,event=branch,enable=${{ !endsWith(github.ref, 'refs/heads/master') }} | |
type=raw,value=${{env.TAG_LATEST}},enable=${{ endsWith(github.ref, 'refs/heads/master') }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image to ${{ env.REGISTRY }} | |
uses: docker/build-push-action@v6 | |
with: | |
platforms: ${{ env.PLATFORMS }} | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
base=${{env.BASE_IMG}} |