-
Notifications
You must be signed in to change notification settings - Fork 1
343 lines (295 loc) · 11.8 KB
/
test.yml
File metadata and controls
343 lines (295 loc) · 11.8 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
name: "Test workflow"
run-name: "Test workflow [${{ github.ref_name }}] ${{ github.event.repository.pushed_at}}"
on:
pull_request:
types: [opened, synchronize, reopened, closed]
push:
permissions:
contents: read
packages: write
jobs:
build-ci-images:
if: github.event_name == 'push' && github.ref_name != 'main'
runs-on: ubuntu-22.04
strategy:
matrix:
image:
- name: frontend
context: .
dockerfile: ./frontend/Dockerfile
- name: backend
context: .
dockerfile: ./backend/Dockerfile
- name: mlflow
context: .
dockerfile: ./infrastructure/registry/Dockerfile
env:
REGISTRY: ghcr.io
IMAGE_NAMESPACE: ${{ github.repository_owner }}
steps:
- uses: actions/checkout@v4
- name: Set image tag for CI
run: |
SAFE_REF=$(echo "${{ github.ref_name }}" | tr '/' '-')
echo "IMAGE_TAG=feature-${SAFE_REF}" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ${{ matrix.image.name }}
uses: docker/build-push-action@v5
with:
context: ${{ matrix.image.context }}
file: ${{ matrix.image.dockerfile }}
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/model-platform/${{ matrix.image.name }}:${{ env.IMAGE_TAG }}
test-and-quality-check:
runs-on: ubuntu-22.04
environment: dev
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Install dependencies and project
run: |
uv sync --group dev --group backend
- name: Run pre-commit hooks
run: |
uv run pre-commit install
uv run pre-commit run --all-files
- name: Run unit tests
run: |
echo "Launching unit tests"
uv run pytest tests/test_unitaires
integration-tests-kind:
if: github.event_name == 'push' && github.ref_name != 'main'
runs-on: ubuntu-22.04
environment: dev
needs: [test-and-quality-check, build-ci-images]
steps:
- uses: actions/checkout@v4
- name: Install gettext for envsubst
run: sudo apt-get update && sudo apt-get install -y gettext-base
- name: Set image tag for tests
run: |
SAFE_REF=$(echo "${{ github.ref_name }}" | tr '/' '-')
echo "IMAGE_TAG=feature-${SAFE_REF}" >> $GITHUB_ENV
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Install dependencies
run: |
uv sync --group dev --group backend --group cli
- name: Install Kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: Create Kind cluster
run: |
kind create cluster --name model-platform-ci --wait 60s
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
- name: Verify cluster is running
run: |
kubectl cluster-info
kubectl get nodes
- name: Install ingress-nginx controller for Kind
run: |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
- name: Deploy infrastructure (namespaces, minio, nginx, ingress)
run: |
kubectl apply -f infrastructure/k8s/namespaces.yaml
kubectl apply -f infrastructure/k8s/minio-deployment.yaml
kubectl apply -f infrastructure/k8s/nginx-deployment.yaml
kubectl apply -f infrastructure/k8s/nginx-configmap.yaml
kubectl apply -f infrastructure/k8s/ingress.yaml
kubectl wait --for=condition=available deployment/nginx-reverse-proxy --timeout=120s || true
- name: Deploy backend
run: |
kubectl apply -f infrastructure/k8s/backend-configmap.yaml
kubectl patch configmap backend-config -n model-platform --type merge -p "{\"data\":{\"IMAGE_TAG\":\"${IMAGE_TAG}\"}}"
kubectl create secret generic backend-secret \
--namespace=model-platform \
--from-literal=POSTGRES_PASSWORD='test_password' \
--from-literal=JWT_SECRET='test_jwt_secret_for_ci' \
--from-literal=ADMIN_EMAIL='admin@test.com' \
--from-literal=ADMIN_PASSWORD='test_admin_password'
kubectl wait --for=condition=available deployment/backend -n model-platform --timeout=180s
echo "Backend deployed, checking pods..."
kubectl get pods -n model-platform
- name: Run Kind integration tests (minimal infrastructure tests)
run: |
echo "Launching Kind integration tests"
uv run pytest tests/integration/test_minimal_kind.py -v --tb=short
- name: Delete Kind cluster
if: always()
run: |
kind delete cluster --name model-platform-ci
e2e-tests-minikube:
if: github.event_name == 'push' && github.ref_name != 'main'
runs-on: ubuntu-22.04
environment: dev
needs: [test-and-quality-check, build-ci-images]
steps:
- uses: actions/checkout@v4
- name: Install gettext for envsubst
run: sudo apt-get update && sudo apt-get install -y gettext-base
- name: Set image tag for tests
run: |
SAFE_REF=$(echo "${{ github.ref_name }}" | tr '/' '-')
echo "IMAGE_TAG=feature-${SAFE_REF}" >> $GITHUB_ENV
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Set up Python
run: uv python install 3.11
- name: Install dependencies
run: |
uv sync --group dev --group backend --group cli --group notebooks
- name: Start Minikube
uses: medyagh/setup-minikube@v0.0.18
with:
minikube-version: '1.32.0'
kubernetes-version: 'v1.28.3'
driver: docker
memory: 6144
cpus: 4
- name: Enable Minikube addons
run: |
minikube addons enable ingress
minikube addons enable ingress-dns
# Wait for ingress controller to be ready
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=120s
- name: Setup /etc/hosts for model-platform.com
run: |
echo "$(minikube ip) model-platform.com" | sudo tee -a /etc/hosts
- name: Deploy full infrastructure
run: |
make k8s-infra
make create-backend-secret POSTGRES_PWD=your_postgres_password JWT_SECRET="ask for the JWT secret" ADMIN_EMAIL=alice@example.com ADMIN_PWD=pass!
kubectl apply -f infrastructure/k8s/backend-configmap.yaml
kubectl patch configmap backend-config -n model-platform --type merge -p "{\"data\":{\"IMAGE_TAG\":\"${IMAGE_TAG}\"}}"
make k8s-modelplatform IMAGE_TAG=${IMAGE_TAG}
- name: Wait for infrastructure to settle (3m)
run: |
echo "Waitin 3 minutes for infrastructure to settle"
sleep 60
- name: Run end-to-end tests
run: |
echo "Launching end-to-end tests"
uv run pytest tests/tests_end_to_end/test_from_project_creation_to_model_predict.py -v --tb=long
- name: Collect logs on failure
if: failure()
run: |
echo "=== All Pods Status ==="
kubectl get pods --all-namespaces -o wide
echo "=== All Events ==="
kubectl get events --all-namespaces --sort-by=.metadata.creationTimestamp | tail -50
echo "=== Backend Pod logs ==="
kubectl logs -n model-platform -l app=backend --tail=100 || true
echo "=== Backend Pod describe ==="
kubectl describe pod -n model-platform -l app=backend || true
echo "=== Nginx Pod logs ==="
kubectl logs -l app=nginx-reverse-proxy --tail=100 || true
echo "=== Nginx Pod describe ==="
kubectl describe pod -l app=nginx-reverse-proxy || true
echo "=== Model deployment pods logs and status ==="
for namespace in $(kubectl get namespaces -o name | grep -E "e2e|test" | sed 's/namespace\///'); do
echo "--- Namespace: $namespace ---"
kubectl get pods -n $namespace -o wide || true
for pod in $(kubectl get pods -n $namespace -o name 2>/dev/null | grep -E "deployment|model" | sed 's/pod\///'); do
echo "Pod: $pod"
kubectl describe pod $pod -n $namespace || true
kubectl logs $pod -n $namespace --tail=50 || true
kubectl logs $pod -n $namespace --previous --tail=50 2>/dev/null || true
done
done
echo "=== Docker images in minikube ==="
minikube image ls || true
- name: Stop Minikube
if: always()
run: |
minikube stop
build-release-images:
if: github.event_name == 'push' && github.ref_name == 'main'
runs-on: ubuntu-22.04
needs: [test-and-quality-check]
strategy:
matrix:
image:
- name: frontend
context: .
dockerfile: ./frontend/Dockerfile
- name: backend
context: .
dockerfile: ./backend/Dockerfile
- name: mlflow
context: .
dockerfile: ./infrastructure/registry/Dockerfile
env:
REGISTRY: ghcr.io
IMAGE_NAMESPACE: ${{ github.repository_owner }}
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Set release tag
run: |
echo "RELEASE_TAG=v${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ${{ matrix.image.name }} (release)
uses: docker/build-push-action@v5
with:
context: ${{ matrix.image.context }}
file: ${{ matrix.image.dockerfile }}
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/model-platform/${{ matrix.image.name }}:${{ env.RELEASE_TAG }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAMESPACE }}/model-platform/${{ matrix.image.name }}:latest
cleanup-feature-images:
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-22.04
strategy:
matrix:
package: [frontend, backend, mlflow]
steps:
- name: Set feature tag
id: tag
run: |
SAFE_REF=$(echo "${{ github.event.pull_request.head.ref }}" | tr '/' '-')
echo "tag=feature-${SAFE_REF}" >> $GITHUB_OUTPUT
- name: Delete ${{ matrix.package }}:${{ steps.tag.outputs.tag }}
uses: actions/delete-package-versions@v5
with:
package-name: model-platform/${{ matrix.package }}
package-type: container
package-version-ids: ${{ steps.tag.outputs.tag }}
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true