Skip to content

Merge pull request #1 from PrefectHQ/main #1

Merge pull request #1 from PrefectHQ/main

Merge pull request #1 from PrefectHQ/main #1

name: Docker images
on:
# On release events (also when a published release is converted from/to prerelease), push all patterns
release:
types: [released, prereleased]
# On each commit merged into main, push sha and branch patterns to prefect-dev
push:
branches: main
paths:
- "Dockerfile"
- ".dockerignore"
- "setup.py"
- "src/**"
- "tests/**"
- "requirements.txt"
- "requirements-client.txt"
- "MANIFEST.in"
- "setup.cfg"
- "versioneer.py"
- ".gitingore"
- ".gitattributes"
- ".github/workflows/docker-images.yaml"
- "ui/**"
# On workflow_dispatch, push sha and branch patterns to prefect-dev
workflow_dispatch:
jobs:
publish-docker-images:
name: Build and publish to DockerHub
runs-on: ubuntu-latest
environment: ${{ ( github.event_name == 'release' && 'prod' ) || 'dev' }}
strategy:
matrix:
flavor:
- ""
- "-conda"
- "-kubernetes"
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=moby/buildkit:v0.12.5
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate tags for prefecthq/prefect-dev
id: metadata-dev
uses: docker/metadata-action@v5
# do not generate the development tags on release events
if: ${{ github.event_name != 'release' }}
with:
images: prefecthq/prefect-dev
tags: |
type=raw,value=${{ github.ref_name }},suffix=-python${{ matrix.python-version }}${{ matrix.flavor }}
type=sha,suffix=-python${{ matrix.python-version }}${{ matrix.flavor }}
flavor: |
latest=false
- name: Determine latest tag
# https://stackoverflow.com/a/75079768/5511061
run: |
echo "LATEST_TAG=$(curl -qsSL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${{ github.api_url }}/repos/${{ github.repository }}/releases/latest" \
| jq -r .tag_name)" >> $GITHUB_ENV
- name: Generate tags for prefecthq/prefect
id: metadata-prod
uses: docker/metadata-action@v5
# only generate the production tags on release events
if: ${{ github.event_name == 'release' }}
with:
images: prefecthq/prefect
# push `latest`, `X.Y` and `X` tags only when the release is not marked as prerelease
# push `latest` and `X` tags only when the release is marked as latest
tags: |
type=pep440,pattern={{version}},suffix=-python${{ matrix.python-version }}${{ matrix.flavor }}
type=pep440,pattern={{major}}.{{minor}},suffix=-python${{ matrix.python-version }}${{ matrix.flavor }},enable=${{ github.event.release.prerelease == false }}
type=pep440,pattern={{major}},suffix=-python${{ matrix.python-version }}${{ matrix.flavor }},enable=${{ github.event.release.prerelease == false && github.ref_name == env.LATEST_TAG }}
type=raw,value=3-latest${{ matrix.flavor }},enable=${{ matrix.python-version == '3.10' && github.event.release.prerelease == false && github.ref_name == env.LATEST_TAG }}
flavor: |
latest=false
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
${{ ( endsWith(matrix.flavor, 'conda') && 'BASE_IMAGE=prefect-conda' ) || '' }}
${{ ( endsWith(matrix.flavor, 'kubernetes') && 'EXTRA_PIP_PACKAGES=prefect-kubernetes' ) || '' }}
tags: ${{ join(steps.metadata-dev.outputs.tags) }},${{ join(steps.metadata-prod.outputs.tags) }}
labels: ${{ steps.metadata-dev.outputs.labels }}
push: true
pull: true
provenance: false