-
Notifications
You must be signed in to change notification settings - Fork 1.6k
135 lines (124 loc) · 5.58 KB
/
docker-images.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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, allow publishing 3-latest images
workflow_dispatch:
inputs:
publish_3_latest:
description: 'Publish 3-latest images'
required: false
type: boolean
default: false
jobs:
publish-docker-images:
name: Build and publish to DockerHub
runs-on: ubuntu-latest
environment: ${{ github.event_name == 'release' && github.event.release.prerelease && 'pre-release' || github.event_name == 'release' && 'prod' || 'dev' }}
strategy:
matrix:
flavor:
- ""
- "-conda"
- "-kubernetes"
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
steps:
- name: Validate Prerelease Tag
if: ${{ github.event_name == 'release' && github.event.release.prerelease == true }}
run: |
TAG_NAME=${{ github.ref }}
if [[ ! "$TAG_NAME" =~ ^refs/tags/[0-9]+\.[0-9]+\.[0-9]+[a-zA-Z0-9]+$ ]]; then
echo "Error: Tag $TAG_NAME does not match prerelease version pattern."
exit 1
fi
- 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
# generate the production tags on release events or when manually triggered for 3-latest
if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_3_latest == 'true') }}
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
# push `3-latest` tags on latest release or manual trigger
tags: |
type=pep440,pattern={{version}},suffix=-python${{ matrix.python-version }}${{ matrix.flavor }},enable=${{ github.event_name == 'release' }}
type=pep440,pattern={{major}}.{{minor}},suffix=-python${{ matrix.python-version }}${{ matrix.flavor }},enable=${{ github.event_name == 'release' && github.event.release.prerelease == false }}
type=pep440,pattern={{major}},suffix=-python${{ matrix.python-version }}${{ matrix.flavor }},enable=${{ github.event_name == 'release' && github.event.release.prerelease == false && github.ref_name == env.LATEST_TAG }}
type=raw,value=3-latest${{ matrix.flavor }},enable=${{ (github.event_name == 'release' && github.event.release.prerelease == false && github.ref_name == env.LATEST_TAG && matrix.python-version == '3.12') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_3_latest == 'true') }}
type=raw,value=3-latest-python${{ matrix.python-version }}${{ matrix.flavor }},enable=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.publish_3_latest == 'true' }}
flavor: |
latest=false
- name: Build and push image
uses: docker/build-push-action@v6
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') && 'PREFECT_EXTRAS=[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