|
5 | 5 | tags: |
6 | 6 | - "v*" |
7 | 7 |
|
8 | | -name: Build container images |
| 8 | +name: Build and Test container images |
9 | 9 |
|
10 | 10 | jobs: |
| 11 | + test-multi-arch: |
| 12 | + name: Test on multiple architectures |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + platform: [linux/amd64, linux/arm64] |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up QEMU |
| 22 | + uses: docker/setup-qemu-action@v3 |
| 23 | + |
| 24 | + - name: Set up Docker Buildx |
| 25 | + uses: docker/setup-buildx-action@v3 |
| 26 | + with: |
| 27 | + driver-opts: | |
| 28 | + image=moby/buildkit:v0.12.5 |
| 29 | + |
| 30 | + - name: Build test image for ${{ matrix.platform }} |
| 31 | + uses: docker/build-push-action@v5 |
| 32 | + with: |
| 33 | + context: . |
| 34 | + file: ./Dockerfile |
| 35 | + platforms: ${{ matrix.platform }} |
| 36 | + load: ${{ matrix.platform == 'linux/amd64' }} |
| 37 | + cache-from: type=gha,scope=test-${{ matrix.platform }} |
| 38 | + cache-to: type=gha,mode=max,scope=test-${{ matrix.platform }} |
| 39 | + tags: | |
| 40 | + test-data-processing:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 41 | + |
| 42 | + - name: Build Apache Tika test image for ${{ matrix.platform }} |
| 43 | + uses: docker/build-push-action@v5 |
| 44 | + with: |
| 45 | + context: . |
| 46 | + file: ./Dockerfile_apache_tika |
| 47 | + platforms: ${{ matrix.platform }} |
| 48 | + load: ${{ matrix.platform == 'linux/amd64' }} |
| 49 | + cache-from: type=gha,scope=tika-test-${{ matrix.platform }} |
| 50 | + cache-to: type=gha,mode=max,scope=tika-test-${{ matrix.platform }} |
| 51 | + tags: | |
| 52 | + test-apache-tika:${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 53 | + |
| 54 | + # Only run functional tests on AMD64 (faster and ARM64 emulation can be flaky for complex tests) |
| 55 | + - name: Test Python dependencies (AMD64 only) |
| 56 | + if: matrix.platform == 'linux/amd64' |
| 57 | + run: | |
| 58 | + docker run --rm test-data-processing:amd64 python -c " |
| 59 | + import sentence_transformers |
| 60 | + import psycopg2 |
| 61 | + import opensearchpy |
| 62 | + import boto3 |
| 63 | + import sklearn |
| 64 | + import numpy |
| 65 | + print('✅ All major dependencies imported successfully') |
| 66 | + print('✅ sentence-transformers version:', sentence_transformers.__version__) |
| 67 | + print('✅ psycopg2 version:', psycopg2.__version__) |
| 68 | + print('✅ opensearchpy version:', opensearchpy.__version__) |
| 69 | + print('✅ boto3 version:', boto3.__version__) |
| 70 | + print('✅ scikit-learn version:', sklearn.__version__) |
| 71 | + print('✅ numpy version:', numpy.__version__) |
| 72 | + " |
| 73 | + |
| 74 | + - name: Test Apache Tika server (AMD64 only) |
| 75 | + if: matrix.platform == 'linux/amd64' |
| 76 | + run: | |
| 77 | + # Start Tika server |
| 78 | + CONTAINER_ID=$(docker run -d -p 9998:9998 test-apache-tika:amd64) |
| 79 | + echo "Waiting for Tika server to start..." |
| 80 | + sleep 15 |
| 81 | + |
| 82 | + # Test if Tika is responding (with retry) |
| 83 | + TIKA_READY=false |
| 84 | + for i in {1..6}; do |
| 85 | + if curl -f http://localhost:9998/version > /dev/null 2>&1; then |
| 86 | + TIKA_READY=true |
| 87 | + break |
| 88 | + fi |
| 89 | + echo "Attempt $i/6: Tika not ready yet, waiting 5 more seconds..." |
| 90 | + sleep 5 |
| 91 | + done |
| 92 | + |
| 93 | + if [ "$TIKA_READY" = true ]; then |
| 94 | + echo "✅ Apache Tika server is responding" |
| 95 | + TIKA_VERSION=$(curl -s http://localhost:9998/version) |
| 96 | + echo "✅ Tika version: $TIKA_VERSION" |
| 97 | + else |
| 98 | + echo "❌ Apache Tika server is not responding after 45 seconds" |
| 99 | + echo "Container logs:" |
| 100 | + docker logs $CONTAINER_ID |
| 101 | + docker stop $CONTAINER_ID |
| 102 | + exit 1 |
| 103 | + fi |
| 104 | + |
| 105 | + # Cleanup |
| 106 | + docker stop $CONTAINER_ID |
| 107 | +
|
| 108 | + test-python-unit: |
| 109 | + name: Run Python unit tests |
| 110 | + runs-on: ubuntu-latest |
| 111 | + services: |
| 112 | + postgres: |
| 113 | + image: postgres:11 |
| 114 | + env: |
| 115 | + POSTGRES_PASSWORD: queridodiario |
| 116 | + POSTGRES_USER: queridodiario |
| 117 | + POSTGRES_DB: queridodiariodb |
| 118 | + options: >- |
| 119 | + --health-cmd pg_isready |
| 120 | + --health-interval 10s |
| 121 | + --health-timeout 5s |
| 122 | + --health-retries 5 |
| 123 | + ports: |
| 124 | + - 5432:5432 |
| 125 | + |
| 126 | + opensearch: |
| 127 | + image: opensearchproject/opensearch:2.9.0 |
| 128 | + env: |
| 129 | + discovery.type: single-node |
| 130 | + plugins.security.ssl.http.enabled: false |
| 131 | + options: >- |
| 132 | + --health-cmd "curl -f http://localhost:9200/_cluster/health" |
| 133 | + --health-interval 10s |
| 134 | + --health-timeout 5s |
| 135 | + --health-retries 5 |
| 136 | + ports: |
| 137 | + - 9200:9200 |
| 138 | + |
| 139 | + minio: |
| 140 | + image: bitnami/minio:2021.4.6 |
| 141 | + env: |
| 142 | + MINIO_ACCESS_KEY: minio-access-key |
| 143 | + MINIO_SECRET_KEY: minio-secret-key |
| 144 | + MINIO_DEFAULT_BUCKETS: queridodiariobucket:public |
| 145 | + ports: |
| 146 | + - 9000:9000 |
| 147 | + |
| 148 | + steps: |
| 149 | + - name: Checkout code |
| 150 | + uses: actions/checkout@v4 |
| 151 | + |
| 152 | + - name: Set up QEMU |
| 153 | + uses: docker/setup-qemu-action@v3 |
| 154 | + |
| 155 | + - name: Set up Docker Buildx |
| 156 | + uses: docker/setup-buildx-action@v3 |
| 157 | + with: |
| 158 | + driver-opts: | |
| 159 | + image=moby/buildkit:v0.12.5 |
| 160 | + |
| 161 | + - name: Build test image |
| 162 | + uses: docker/build-push-action@v5 |
| 163 | + with: |
| 164 | + context: . |
| 165 | + file: ./Dockerfile |
| 166 | + platforms: linux/amd64 |
| 167 | + load: true |
| 168 | + cache-from: type=gha,scope=unittest |
| 169 | + cache-to: type=gha,mode=max,scope=unittest |
| 170 | + tags: test-data-processing:unittest |
| 171 | + |
| 172 | + - name: Build Apache Tika test image |
| 173 | + uses: docker/build-push-action@v5 |
| 174 | + with: |
| 175 | + context: . |
| 176 | + file: ./Dockerfile_apache_tika |
| 177 | + platforms: linux/amd64 |
| 178 | + load: true |
| 179 | + cache-from: type=gha,scope=tika-unittest |
| 180 | + cache-to: type=gha,mode=max,scope=tika-unittest |
| 181 | + tags: test-apache-tika:unittest |
| 182 | + |
| 183 | + - name: Start Apache Tika server |
| 184 | + run: | |
| 185 | + docker run -d -p 9998:9998 --name tika-server test-apache-tika:unittest |
| 186 | + sleep 15 |
| 187 | + |
| 188 | + # Verify Tika is running |
| 189 | + for i in {1..6}; do |
| 190 | + if curl -f http://localhost:9998/version > /dev/null 2>&1; then |
| 191 | + echo "✅ Apache Tika server is ready" |
| 192 | + break |
| 193 | + fi |
| 194 | + echo "Waiting for Tika server... ($i/6)" |
| 195 | + sleep 5 |
| 196 | + done |
| 197 | + |
| 198 | + - name: Run Python unit tests |
| 199 | + run: | |
| 200 | + docker run --rm \ |
| 201 | + --network host \ |
| 202 | + -e PYTHONPATH=/mnt/code \ |
| 203 | + -e POSTGRES_PASSWORD=queridodiario \ |
| 204 | + -e POSTGRES_USER=queridodiario \ |
| 205 | + -e POSTGRES_DB=queridodiariodb \ |
| 206 | + -e POSTGRES_HOST=localhost \ |
| 207 | + -e POSTGRES_PORT=5432 \ |
| 208 | + test-data-processing:unittest \ |
| 209 | + python -m unittest discover -s tests -p "*.py" -v |
| 210 | + |
| 211 | + - name: Run coverage report |
| 212 | + run: | |
| 213 | + docker run --rm \ |
| 214 | + --network host \ |
| 215 | + -e PYTHONPATH=/mnt/code \ |
| 216 | + -e POSTGRES_PASSWORD=queridodiario \ |
| 217 | + -e POSTGRES_USER=queridodiario \ |
| 218 | + -e POSTGRES_DB=queridodiariodb \ |
| 219 | + -e POSTGRES_HOST=localhost \ |
| 220 | + -e POSTGRES_PORT=5432 \ |
| 221 | + test-data-processing:unittest \ |
| 222 | + bash -c "coverage run -m unittest discover -s tests -p '*.py' && coverage report -m" |
| 223 | + |
| 224 | + - name: Cleanup |
| 225 | + if: always() |
| 226 | + run: | |
| 227 | + docker stop tika-server || true |
| 228 | + docker rm tika-server || true |
| 229 | +
|
11 | 230 | build-data-processing: |
| 231 | + name: Build data processing container image |
| 232 | + runs-on: ubuntu-latest |
| 233 | + needs: [test-multi-arch, test-python-unit] |
12 | 234 | name: Build data processing container image |
13 | 235 | runs-on: ubuntu-latest |
14 | 236 | steps: |
|
62 | 284 | build-apache-tika: |
63 | 285 | name: Build Apache Tika container image |
64 | 286 | runs-on: ubuntu-latest |
| 287 | + needs: [test-multi-arch, test-python-unit] |
65 | 288 | steps: |
66 | 289 | - name: Checkout code |
67 | 290 | uses: actions/checkout@v4 |
|
0 commit comments