Skip to content

Create and publish a Docker image #203

Create and publish a Docker image

Create and publish a Docker image #203

name: Create and publish a Docker image
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
on:
push:
branches: ["main"]
schedule:
- cron: "0 2 * * 1"
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: "${{ github.repository }}"
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prep Image Name
id: image_tag_lower
# Black magic fuckery to ensure lowercase string as docker tag
run: |
IMAGE_TAG=$(echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.python-version }}" | awk '{print tolower($0)}')
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.image_tag_lower.outputs.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PYTHONVERSION=${{ matrix.python-version }}