|
| 1 | +name: Docker Image Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize] |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - develop |
| 9 | + - release/* |
| 10 | + workflow_call: |
| 11 | + secrets: |
| 12 | + DEV_AWS_ROLE: |
| 13 | + required: true |
| 14 | + NIX_SIGN_SECRET_KEY: |
| 15 | + required: true |
| 16 | + workflow_dispatch: |
| 17 | + inputs: |
| 18 | + dockerfile: |
| 19 | + description: 'Specific Dockerfile to test (leave empty for all)' |
| 20 | + required: false |
| 21 | + default: '' |
| 22 | + type: string |
| 23 | + |
| 24 | +permissions: |
| 25 | + id-token: write |
| 26 | + contents: read |
| 27 | + |
| 28 | +jobs: |
| 29 | + check-changes: |
| 30 | + name: Check Docker Image Changes |
| 31 | + runs-on: blacksmith-2vcpu-ubuntu-2404 |
| 32 | + outputs: |
| 33 | + should_run: ${{ steps.check.outputs.should_run }} |
| 34 | + input_hash: ${{ steps.check.outputs.input_hash }} |
| 35 | + steps: |
| 36 | + - name: Checkout Repo |
| 37 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 38 | + |
| 39 | + - name: Install nix |
| 40 | + uses: ./.github/actions/nix-install-ephemeral |
| 41 | + with: |
| 42 | + push-to-cache: 'false' |
| 43 | + env: |
| 44 | + DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} |
| 45 | + NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} |
| 46 | + |
| 47 | + - name: Check Docker image changes |
| 48 | + id: check |
| 49 | + uses: ./.github/actions/check-docker-image-changes |
| 50 | + with: |
| 51 | + event_name: ${{ github.event_name }} |
| 52 | + base_ref: ${{ github.base_ref }} |
| 53 | + |
| 54 | + docker-image-test: |
| 55 | + name: Test ${{ matrix.dockerfile }} |
| 56 | + needs: check-changes |
| 57 | + if: needs.check-changes.outputs.should_run == 'true' |
| 58 | + runs-on: large-linux-arm |
| 59 | + timeout-minutes: 120 |
| 60 | + strategy: |
| 61 | + fail-fast: false |
| 62 | + matrix: |
| 63 | + dockerfile: |
| 64 | + - Dockerfile-15 |
| 65 | + - Dockerfile-17 |
| 66 | + - Dockerfile-orioledb-17 |
| 67 | + steps: |
| 68 | + - name: Checkout Repo |
| 69 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 70 | + |
| 71 | + - name: Install nix |
| 72 | + uses: ./.github/actions/nix-install-ephemeral |
| 73 | + with: |
| 74 | + push-to-cache: 'false' |
| 75 | + env: |
| 76 | + DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} |
| 77 | + NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} |
| 78 | + |
| 79 | + - name: Create Docker context |
| 80 | + run: docker context create builders |
| 81 | + |
| 82 | + - name: Set up Docker Buildx |
| 83 | + uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 |
| 84 | + with: |
| 85 | + endpoint: builders |
| 86 | + |
| 87 | + - name: Build Docker image |
| 88 | + run: | |
| 89 | + echo "Building ${{ matrix.dockerfile }}..." |
| 90 | + VERSION="${{ matrix.dockerfile }}" |
| 91 | + VERSION="${VERSION#Dockerfile-}" |
| 92 | + # Build with tags expected by both tools |
| 93 | + docker build -f ${{ matrix.dockerfile }} \ |
| 94 | + -t "pg-docker-test:${VERSION}" \ |
| 95 | + -t "supabase-postgres:${VERSION}-analyze" \ |
| 96 | + . |
| 97 | +
|
| 98 | + - name: Run image size analysis |
| 99 | + run: | |
| 100 | + echo "=== Image Size Analysis for ${{ matrix.dockerfile }} ===" |
| 101 | + nix run --accept-flake-config .#image-size-analyzer -- --image ${{ matrix.dockerfile }} --no-build |
| 102 | +
|
| 103 | + - name: Run Docker image tests |
| 104 | + run: | |
| 105 | + echo "=== Running tests for ${{ matrix.dockerfile }} ===" |
| 106 | + nix run --accept-flake-config .#docker-image-test -- --no-build ${{ matrix.dockerfile }} |
| 107 | +
|
| 108 | + - name: Show container logs on failure |
| 109 | + if: failure() |
| 110 | + run: | |
| 111 | + VERSION="${{ matrix.dockerfile }}" |
| 112 | + VERSION="${VERSION#Dockerfile-}" |
| 113 | + CONTAINER_NAME=$(docker ps -a --filter "name=pg-test-${VERSION}" --format "{{.Names}}" | head -1) |
| 114 | + if [[ -n "$CONTAINER_NAME" ]]; then |
| 115 | + echo "=== Container logs for $CONTAINER_NAME ===" |
| 116 | + docker logs "$CONTAINER_NAME" 2>&1 || true |
| 117 | + fi |
| 118 | +
|
| 119 | + - name: Cleanup |
| 120 | + if: always() |
| 121 | + run: | |
| 122 | + VERSION="${{ matrix.dockerfile }}" |
| 123 | + VERSION="${VERSION#Dockerfile-}" |
| 124 | + # Remove test containers |
| 125 | + docker ps -a --filter "name=pg-test-${VERSION}" -q | xargs -r docker rm -f || true |
| 126 | + # Remove test images |
| 127 | + docker rmi "pg-docker-test:${VERSION}" || true |
| 128 | + docker rmi "supabase-postgres:${VERSION}-analyze" || true |
| 129 | +
|
| 130 | + skip-notification: |
| 131 | + name: Docker Image Test (Skipped) |
| 132 | + needs: check-changes |
| 133 | + if: needs.check-changes.outputs.should_run == 'false' |
| 134 | + runs-on: ubuntu-latest |
| 135 | + steps: |
| 136 | + - name: Report skipped |
| 137 | + run: | |
| 138 | + echo "Docker image tests skipped - inputs unchanged" |
| 139 | + echo "Input hash: ${{ needs.check-changes.outputs.input_hash }}" |
0 commit comments