-
Notifications
You must be signed in to change notification settings - Fork 22
313 lines (273 loc) · 11.8 KB
/
docker-publish.yml
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
name: Build and Publish Mlflow Docker Image
on:
push:
branches: [main]
# Publish semver tags as releases.
tags:
- "*.*.*"
- "*.*.*.*"
paths:
- ".github/workflows/docker-publish.yml"
- ".env"
- "poetry.lock"
- "poetry.toml"
- "pyproject.toml"
- "Dockerfile"
- "mlflowstack/**"
- "docker-compose.*.yaml"
- "tests/**"
- "test-containers/**"
pull_request:
branches: [main]
workflow_dispatch:
jobs:
integrationtest:
runs-on: ubuntu-latest
strategy:
matrix:
database-combo:
- {
postgres: "15",
mysql: "8.0",
minio: "RELEASE.2024-11-07T00-52-20Z",
gcs: "1.50.2",
azurite: "3.33.0",
azure-storage-blob: "12.26.0",
}
- {
postgres: "16",
mysql: "8.4",
minio: "RELEASE.2024-11-07T00-52-20Z",
gcs: "1.50.2",
azurite: "3.33.0",
azure-storage-blob: "12.26.0",
}
- {
postgres: "17",
mysql: "9.1",
minio: "RELEASE.2024-11-07T00-52-20Z",
gcs: "1.50.2",
azurite: "3.33.0",
azure-storage-blob: "12.26.0",
}
name: Test PostgreSQL ${{ matrix.database-combo.postgres }} & MySQL ${{ matrix.database-combo.mysql }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.12
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
- name: Cache Docker images
id: cache-docker-images
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.docker-cache
key: ${{ runner.os }}-docker-images-${{ matrix.database-combo.postgres }}-${{ matrix.database-combo.mysql }}-${{ matrix.database-combo.minio }}-${{ matrix.database-combo.gcs }}-${{ matrix.database-combo.azurite }}
restore-keys: |
${{ runner.os }}-docker-images-
- name: Load Cached Docker Images
if: steps.cache-docker-images.outputs.cache-hit == 'true'
run: |
docker load --input ${{ github.workspace }}/.docker-cache/docker-images.tar
- name: Pull and Save Docker Images if not Cached
if: steps.cache-docker-images.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ github.workspace }}/.docker-cache
docker pull postgres:${{ matrix.database-combo.postgres }}
docker pull mysql:${{ matrix.database-combo.mysql }}
docker pull minio/minio:${{ matrix.database-combo.minio }}
docker pull fsouza/fake-gcs-server:${{ matrix.database-combo.gcs }}
docker pull mcr.microsoft.com/azure-storage/azurite:${{ matrix.database-combo.azurite }}
docker save -o ${{ github.workspace }}/.docker-cache/docker-images.tar \
postgres:${{ matrix.database-combo.postgres }} \
mysql:${{ matrix.database-combo.mysql }} \
minio/minio:${{ matrix.database-combo.minio }} \
fsouza/fake-gcs-server:${{ matrix.database-combo.gcs }} \
mcr.microsoft.com/azure-storage/azurite:${{ matrix.database-combo.azurite }}
#----------------------------------------------
# Overwrite .env file to test different version of databases
#----------------------------------------------
- name: Set up .env file
run: |
echo "POSTGRES_VERSION=${{ matrix.database-combo.postgres }}" > .env
echo "MYSQL_VERSION=${{ matrix.database-combo.mysql }}" >> .env
echo "MINIO_VERSION=${{ matrix.database-combo.minio }}" >> .env
echo "FAKE_GCS_SERVER_VERSION=${{ matrix.database-combo.gcs }}" >> .env
echo "AZURITE_VERSION=${{ matrix.database-combo.azurite }}" >> .env
echo "AZURE_STORAGE_BLOB_VERSION=${{ matrix.database-combo.azure-storage-blob }}" >> .env
#----------------------------------------------
# run test suite
#----------------------------------------------
- name: Run tests
env:
POSTGRES_VERSION: ${{ matrix.database-combo.postgres }}
MYSQL_VERSION: ${{ matrix.database-combo.mysql }}
run: |
source .venv/bin/activate
poetry run pytest
buildtestpush:
runs-on: ubuntu-latest
needs: integrationtest
env:
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
# To upload sarif files
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install ORAS
id: install_oras
uses: oras-project/setup-oras@main
- name: Install Cosign
id: install_cosign
uses: sigstore/[email protected]
- name: Set up QEMU
uses: docker/[email protected]
with:
platforms: all
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker Hub registry except on PR
# https://github.com/docker/login-action
- name: Login to Docker Hub
id: docker_hub_login
if: github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/')
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to GitHub Container Registry
id: ghcr_login
if: github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to GitHub Container Registry (ORAS)
id: oras_ghcr_login
if: github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/')
run: |
echo ${{ secrets.GITHUB_TOKEN }} | oras login ghcr.io --username ${{ github.actor }} --password-stdin
- name: Publish Artifact Hub Manifest
id: publish_ah_manifest
if: github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/')
run: |
oras push \
ghcr.io/${{ env.IMAGE_NAME }}:artifacthub.io \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \
artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
if: github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/')
id: meta
uses: docker/metadata-action@v5
with:
images: |
docker.io/${{ env.IMAGE_NAME }}
ghcr.io/${{ env.IMAGE_NAME }}
flavor: |
latest=true
tags: |
type=ref,event=tag
labels: |
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/burakince/mlflow/main/README.md
io.artifacthub.package.maintainers=[{"name":"burakince","email":"[email protected]"}]
io.artifacthub.package.logo-url=https://raw.githubusercontent.com/mlflow/mlflow/master/assets/logo.svg
io.artifacthub.package.keywords=machine-learning,ai,ml,model-management,mlflow,mlflow-tracking-server,mlflow-docker,mlflow-tracking,mlflow-kube
io.artifacthub.package.license=MIT
io.artifacthub.package.alternative-locations=docker.io/${{ env.IMAGE_NAME }}
# Build Docker image with Buildx and don't push it
- name: Build Docker image
id: build-docker-image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64/v8,linux/amd64
push: false
# load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Snyk to check Docker image for vulnerabilities
id: docker-image-scan
continue-on-error: true
uses: snyk/actions/[email protected]
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
image: docker.io/${{ env.IMAGE_NAME }}:latest
args: --file=Dockerfile --severity-threshold=medium --sarif-file-output=snyk.sarif
- name: Upload result to GitHub Code Scanning
if: hashFiles('snyk.sarif') != ''
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: snyk.sarif
# Break the pipeline with failure status if security scan failed
# - name: Check docker image scan status
# if: ${{ steps.docker-image-scan.outcome == 'failure' }}
# run: exit 1
- name: Install Dive
run: |
DIVE_VERSION=$(curl -sL "https://api.github.com/repos/wagoodman/dive/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
curl -OL https://github.com/wagoodman/dive/releases/download/v${DIVE_VERSION}/dive_${DIVE_VERSION}_linux_amd64.deb
sudo apt install ./dive_${DIVE_VERSION}_linux_amd64.deb
- name: Analyse Efficiency and Wastes on Image
run: dive docker.io/${{ env.IMAGE_NAME }}:latest
- name: Push All Docker Image Tags
if: github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/')
run: |
docker push --all-tags docker.io/${{ env.IMAGE_NAME }}
docker push --all-tags ghcr.io/${{ env.IMAGE_NAME }}
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker images
if: github.event_name != 'pull_request' && contains(github.ref, 'refs/tags/')
run: |
echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign -y {}@${{ steps.build-docker-image.outputs.digest }}