-
-
Notifications
You must be signed in to change notification settings - Fork 19
535 lines (503 loc) · 19 KB
/
build_container_image.yaml
File metadata and controls
535 lines (503 loc) · 19 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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
on:
push:
branches:
- main
tags:
- "v*"
workflow_dispatch:
name: Build and Test container images
permissions:
contents: read
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-multi-arch:
name: Test on multiple architectures
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 45
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Free up disk space
run: |
# Remove unnecessary packages and clean up
sudo apt-get autoremove -y
sudo apt-get autoclean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker system prune -af
df -h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.12.5
- name: Monitor disk usage before build
run: |
echo "=== Disk usage before build ==="
df -h
echo "=== Docker system info ==="
docker system df
- name: Build test image for ${{ matrix.platform }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.platform }}
load: ${{ matrix.platform == 'linux/amd64' }}
cache-from: type=gha,scope=test-${{ matrix.platform }}
cache-to: type=gha,mode=min,scope=test-${{ matrix.platform }}
tags: |
test-data-processing:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
- name: Monitor disk usage after build
run: |
echo "=== Disk usage after build ==="
df -h
echo "=== Docker system info ==="
docker system df
- name: Build Apache Tika test image for ${{ matrix.platform }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_apache_tika
platforms: ${{ matrix.platform }}
load: ${{ matrix.platform == 'linux/amd64' }}
cache-from: type=gha,scope=tika-test-${{ matrix.platform }}
cache-to: type=gha,mode=min,scope=tika-test-${{ matrix.platform }}
tags: |
test-apache-tika:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }}
# Run functional tests on both architectures with native execution
- name: Test Python dependencies
run: |
docker run --rm test-data-processing:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} python -c "
import sentence_transformers
import psycopg2
import opensearchpy
import boto3
import sklearn
import numpy
print('✅ All major dependencies imported successfully on ${{ matrix.platform }}')
print('✅ sentence-transformers version:', sentence_transformers.__version__)
print('✅ psycopg2 version:', psycopg2.__version__)
print('✅ opensearchpy version:', opensearchpy.__version__)
print('✅ boto3 version:', boto3.__version__)
print('✅ scikit-learn version:', sklearn.__version__)
print('✅ numpy version:', numpy.__version__)
"
- name: Test Apache Tika server
run: |
# Start Tika server
CONTAINER_ID=$(docker run -d -p 9998:9998 test-apache-tika:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }})
echo "Waiting for Tika server to start on ${{ matrix.platform }}..."
sleep 15
# Test if Tika is responding (with retry)
TIKA_READY=false
for i in {1..6}; do
if curl -f http://localhost:9998/version > /dev/null 2>&1; then
TIKA_READY=true
break
fi
echo "Attempt $i/6: Tika not ready yet, waiting 5 more seconds..."
sleep 5
done
if [ "$TIKA_READY" = true ]; then
echo "✅ Apache Tika server is responding on ${{ matrix.platform }}"
TIKA_VERSION=$(curl -s http://localhost:9998/version)
echo "✅ Tika version: $TIKA_VERSION"
else
echo "❌ Apache Tika server is not responding after 45 seconds on ${{ matrix.platform }}"
echo "Container logs:"
docker logs $CONTAINER_ID
docker stop $CONTAINER_ID
exit 1
fi
# Cleanup
docker stop $CONTAINER_ID
- name: Clean up test images
if: always()
run: |
docker system prune -f
docker image prune -af
test-python-unit:
name: Run Python unit tests
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
services:
postgres:
image: postgres:11
env:
POSTGRES_PASSWORD: queridodiario
POSTGRES_USER: queridodiario
POSTGRES_DB: queridodiariodb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
opensearch:
image: opensearchproject/opensearch:2.9.0
env:
discovery.type: single-node
plugins.security.ssl.http.enabled: false
options: >-
--health-cmd "curl -f http://localhost:9200/_cluster/health"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 9200:9200
minio:
image: quay.io/minio/minio:RELEASE.2025-09-07T16-13-09Z
env:
MINIO_ACCESS_KEY: minio-access-key
MINIO_SECRET_KEY: minio-secret-key
MINIO_DEFAULT_BUCKETS: queridodiariobucket:public
ports:
- 9000:9000
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Free up disk space
run: |
# Remove unnecessary packages and clean up
sudo apt-get autoremove -y
sudo apt-get autoclean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker system prune -af
df -h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.12.5
- name: Build test image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.platform }}
load: true
cache-from: type=gha,scope=unittest-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=unittest-${{ matrix.arch }}
tags: test-data-processing:unittest-${{ matrix.arch }}
- name: Build Apache Tika test image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_apache_tika
platforms: ${{ matrix.platform }}
load: true
cache-from: type=gha,scope=tika-unittest-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=tika-unittest-${{ matrix.arch }}
tags: test-apache-tika:unittest-${{ matrix.arch }}
- name: Start Apache Tika server
run: |
docker run -d -p 9998:9998 --name tika-server-${{ matrix.arch }} test-apache-tika:unittest-${{ matrix.arch }}
sleep 15
# Verify Tika is running
for i in {1..6}; do
if curl -f http://localhost:9998/version > /dev/null 2>&1; then
echo "✅ Apache Tika server is ready on ${{ matrix.platform }}"
break
fi
echo "Waiting for Tika server on ${{ matrix.platform }}... ($i/6)"
sleep 5
done
- name: Run Python unit tests
run: |
docker run --rm \
--network host \
-e PYTHONPATH=/mnt/code \
-e POSTGRES_PASSWORD=queridodiario \
-e POSTGRES_USER=queridodiario \
-e POSTGRES_DB=queridodiariodb \
-e POSTGRES_HOST=localhost \
-e POSTGRES_PORT=5432 \
test-data-processing:unittest-${{ matrix.arch }} \
python -m unittest discover -s tests -p "*.py" -v
- name: Run coverage report
run: |
docker run --rm \
--network host \
-e PYTHONPATH=/mnt/code \
-e POSTGRES_PASSWORD=queridodiario \
-e POSTGRES_USER=queridodiario \
-e POSTGRES_DB=queridodiariodb \
-e POSTGRES_HOST=localhost \
-e POSTGRES_PORT=5432 \
test-data-processing:unittest-${{ matrix.arch }} \
bash -c "coverage run -m unittest discover -s tests -p '*.py' && coverage report -m"
- name: Cleanup
if: always()
run: |
docker stop tika-server-${{ matrix.arch }} || true
docker rm tika-server-${{ matrix.arch }} || true
docker system prune -f
docker image prune -af
build-data-processing:
name: Build data processing container image
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runner }}
needs: [test-multi-arch, test-python-unit]
timeout-minutes: 90
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Free up disk space
run: |
# Remove unnecessary packages and clean up
sudo apt-get autoremove -y
sudo apt-get autoclean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker system prune -af
df -h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.12.5
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push development container image
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.platform }}
push: true
cache-from: type=gha,scope=main-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=main-${{ matrix.arch }}
tags: |
ghcr.io/${{ github.repository }}:latest-${{ matrix.arch }}
- name: Build and push tagged container image
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.platform }}
push: true
cache-from: type=gha,scope=tag-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=tag-${{ matrix.arch }}
tags: |
ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ matrix.arch }}
build-apache-tika:
name: Build Apache Tika container image
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
runs-on: ${{ matrix.runner }}
needs: [test-multi-arch, test-python-unit]
timeout-minutes: 60
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Free up disk space
run: |
# Remove unnecessary packages and clean up
sudo apt-get autoremove -y
sudo apt-get autoclean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker system prune -af
df -h
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:v0.12.5
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Apache Tika development container image
if: ${{ startsWith(github.ref, 'refs/heads/') }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_apache_tika
platforms: ${{ matrix.platform }}
push: true
cache-from: type=gha,scope=tika-main-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=tika-main-${{ matrix.arch }}
tags: |
ghcr.io/okfn-brasil/querido-diario-apache-tika-server:latest-${{ matrix.arch }}
- name: Build and push Apache Tika tagged container image
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile_apache_tika
platforms: ${{ matrix.platform }}
push: true
cache-from: type=gha,scope=tika-tag-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=tika-tag-${{ matrix.arch }}
tags: |
ghcr.io/okfn-brasil/querido-diario-apache-tika-server:${{ github.ref_name }}-${{ matrix.arch }}
create-data-processing-manifest:
name: Create data processing multi-arch manifest
runs-on: ubuntu-latest
needs: build-data-processing
timeout-minutes: 15
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify single-arch images availability (branch)
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
REPO="${{ github.repository }}"
for tag in latest-amd64 latest-arm64; do
for i in {1..20}; do
if docker buildx imagetools inspect ghcr.io/$REPO:$tag > /dev/null 2>&1; then
echo "Found ghcr.io/$REPO:$tag";
break;
fi
echo "Waiting for ghcr.io/$REPO:$tag to be available ($i/20)...";
sleep 3;
done
done
- name: Create and push development manifest
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
REPO="${{ github.repository }}"
docker buildx imagetools create \
-t ghcr.io/$REPO:latest \
ghcr.io/$REPO:latest-amd64 \
ghcr.io/$REPO:latest-arm64
- name: Verify single-arch images availability (tag)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
REPO="${{ github.repository }}"
for arch in amd64 arm64; do
for i in {1..20}; do
if docker buildx imagetools inspect ghcr.io/$REPO:${{ github.ref_name }}-$arch > /dev/null 2>&1; then
echo "Found ghcr.io/$REPO:${{ github.ref_name }}-$arch";
break;
fi
echo "Waiting for ghcr.io/$REPO:${{ github.ref_name }}-$arch to be available ($i/20)...";
sleep 3;
done
done
- name: Create and push tagged manifest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
REPO="${{ github.repository }}"
docker buildx imagetools create \
-t ghcr.io/$REPO:${{ github.ref_name }} \
ghcr.io/$REPO:${{ github.ref_name }}-amd64 \
ghcr.io/$REPO:${{ github.ref_name }}-arm64
create-apache-tika-manifest:
name: Create Apache Tika multi-arch manifest
runs-on: ubuntu-latest
needs: build-apache-tika
timeout-minutes: 15
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Verify single-arch images availability (branch)
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
for tag in latest-amd64 latest-arm64; do
for i in {1..20}; do
if docker buildx imagetools inspect ghcr.io/okfn-brasil/querido-diario-apache-tika-server:$tag > /dev/null 2>&1; then
echo "Found ghcr.io/okfn-brasil/querido-diario-apache-tika-server:$tag";
break;
fi
echo "Waiting for ghcr.io/okfn-brasil/querido-diario-apache-tika-server:$tag to be available ($i/20)...";
sleep 3;
done
done
- name: Create and push Apache Tika development manifest
if: ${{ startsWith(github.ref, 'refs/heads/') }}
run: |
docker buildx imagetools create \
-t ghcr.io/okfn-brasil/querido-diario-apache-tika-server:latest \
ghcr.io/okfn-brasil/querido-diario-apache-tika-server:latest-amd64 \
ghcr.io/okfn-brasil/querido-diario-apache-tika-server:latest-arm64
- name: Verify single-arch images availability (tag)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
for arch in amd64 arm64; do
for i in {1..20}; do
if docker buildx imagetools inspect ghcr.io/okfn-brasil/querido-diario-apache-tika-server:${{ github.ref_name }}-$arch > /dev/null 2>&1; then
echo "Found ghcr.io/okfn-brasil/querido-diario-apache-tika-server:${{ github.ref_name }}-$arch";
break;
fi
echo "Waiting for ghcr.io/okfn-brasil/querido-diario-apache-tika-server:${{ github.ref_name }}-$arch to be available ($i/20)...";
sleep 3;
done
done
- name: Create and push Apache Tika tagged manifest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
docker buildx imagetools create \
-t ghcr.io/okfn-brasil/querido-diario-apache-tika-server:${{ github.ref_name }} \
ghcr.io/okfn-brasil/querido-diario-apache-tika-server:${{ github.ref_name }}-amd64 \
ghcr.io/okfn-brasil/querido-diario-apache-tika-server:${{ github.ref_name }}-arm64