fix: adiciona limit ao GET /scraper/job-stats para evitar OOM #95
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| name: Build container images | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: Run tests before build | |
| 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: | | |
| echo "=== Initial disk usage ===" | |
| df -h | |
| echo "=== Cleaning up disk space ===" | |
| 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 | |
| echo "=== Disk usage after cleanup ===" | |
| df -h | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Verify Docker Compose | |
| run: | | |
| docker compose version | |
| - name: Setup environment files | |
| run: | | |
| cp --update=none config/sample.env config/current.env || true | |
| test -f censo.csv || curl -fsSO https://data.queridodiario.ok.org.br/censo/censo.csv | |
| test -f themes_config.json || curl -fsSO https://raw.githubusercontent.com/okfn-brasil/querido-diario-data-processing/main/config/themes_config.json | |
| - name: Monitor disk usage before build | |
| run: | | |
| echo "=== Disk usage before build ===" | |
| df -h | |
| echo "=== Docker system info ===" | |
| docker system df | |
| - name: Build and test for platform | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| COMPOSE_DOCKER_CLI_BUILD: 1 | |
| run: | | |
| # Update docker-compose.test.yml to build for specific platform | |
| sed -i "s|dockerfile: Dockerfile|dockerfile: Dockerfile\n platforms:\n - ${{ matrix.platform }}|" docker-compose.test.yml | |
| # Run full test suite on native architecture | |
| docker compose -f docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from api | |
| - name: Clean up test images | |
| if: always() | |
| run: | | |
| docker compose -f docker-compose.test.yml down -v || true | |
| docker system prune -f | |
| docker image prune -af | |
| echo "=== Disk usage after cleanup ===" | |
| df -h | |
| build: | |
| name: Build 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 | |
| if: github.event_name == 'push' | |
| timeout-minutes: 60 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Free up disk space | |
| run: | | |
| echo "=== Initial disk usage ===" | |
| df -h | |
| echo "=== Cleaning up disk space ===" | |
| 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 | |
| echo "=== Disk usage after cleanup ===" | |
| df -h | |
| - 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: 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 | |
| tags: | | |
| ghcr.io/${{ github.repository }}:latest-${{ matrix.arch }} | |
| cache-from: type=gha,scope=api-${{ matrix.arch }} | |
| cache-to: type=gha,mode=max,scope=api-${{ 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 | |
| tags: | | |
| ghcr.io/${{ github.repository }}:${{ github.ref_name }}-${{ matrix.arch }} | |
| cache-from: type=gha,scope=api-${{ matrix.arch }} | |
| cache-to: type=gha,mode=max,scope=api-${{ matrix.arch }} | |
| create-manifest: | |
| name: Create multi-arch manifest | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.event_name == 'push' | |
| 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 |