|
| 1 | +name: Build Docker |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
| 6 | +concurrency: |
| 7 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 8 | + cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }} |
| 9 | + |
| 10 | +on: |
| 11 | + push: |
| 12 | + tags: ["v*"] |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - Dockerfile |
| 16 | + - docker-bake.hcl |
| 17 | + - ".github/workflows/docker.yaml" |
| 18 | + schedule: |
| 19 | + # Rebuild nightly to pick up base-image updates from pg_ducklake |
| 20 | + - cron: "44 4 * * *" |
| 21 | + workflow_dispatch: |
| 22 | + |
| 23 | +jobs: |
| 24 | + docker_build: |
| 25 | + name: Build Docker image for Postgres ${{ matrix.postgres }} on ${{ matrix.runner }} |
| 26 | + strategy: |
| 27 | + matrix: |
| 28 | + postgres: ["18"] |
| 29 | + runner: ["ubuntu-24.04", "ubuntu-24.04-arm"] |
| 30 | + |
| 31 | + runs-on: ${{ matrix.runner }} |
| 32 | + |
| 33 | + env: |
| 34 | + BUILDKIT_PROGRESS: plain |
| 35 | + PG_VERSION: ${{ matrix.postgres }} |
| 36 | + RAW_REF: ${{ github.head_ref || github.ref_name }} |
| 37 | + outputs: |
| 38 | + branch_tag: ${{ steps.params.outputs.branch_tag }} |
| 39 | + target_repo: ${{ steps.params.outputs.target_repo }} |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Login to Docker Hub |
| 43 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 44 | + uses: docker/login-action@v3 |
| 45 | + with: |
| 46 | + username: pgducklake |
| 47 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 48 | + |
| 49 | + - name: Checkout pg_duckpipe code |
| 50 | + uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Compute job parameters |
| 53 | + id: params |
| 54 | + run: | |
| 55 | + # Sanitise branch name to a valid Docker tag component (max 112 chars) |
| 56 | + BRANCH=$(printf '%s' "$RAW_REF" \ |
| 57 | + | sed 's/[^a-zA-Z0-9\-\.]/-/g' \ |
| 58 | + | cut -c 1-112 | tr '[:upper:]' '[:lower:]' \ |
| 59 | + | sed -e 's/-*$//') |
| 60 | +
|
| 61 | + # Set platform depending on which runner we're using |
| 62 | + if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then |
| 63 | + PLATFORM=amd64 |
| 64 | + else |
| 65 | + PLATFORM=arm64 |
| 66 | + fi |
| 67 | +
|
| 68 | + # main branch and release tags publish to pgducklake/pgduckpipe; |
| 69 | + # all other branches go to the staging pgducklake/pipe-ci-builds repo. |
| 70 | + git fetch --tags --force |
| 71 | + if [ "$BRANCH" = "main" ] || git rev-parse --verify "$BRANCH"^{tag} > /dev/null 2>&1; then |
| 72 | + TARGET_REPO='pgducklake/pgduckpipe' |
| 73 | + else |
| 74 | + TARGET_REPO='pgducklake/pipe-ci-builds' |
| 75 | + fi |
| 76 | +
|
| 77 | + LATEST_IMAGE="pgducklake/pipe-ci-builds:${{ matrix.postgres }}-${PLATFORM}-${BRANCH}-latest" |
| 78 | +
|
| 79 | + echo "platform=$PLATFORM" >> "$GITHUB_OUTPUT" |
| 80 | + echo "branch_tag=$BRANCH" >> "$GITHUB_OUTPUT" |
| 81 | + echo "target_repo=$TARGET_REPO" >> "$GITHUB_OUTPUT" |
| 82 | + echo "latest_image=$LATEST_IMAGE" >> "$GITHUB_OUTPUT" |
| 83 | +
|
| 84 | + - name: Attempt to pull previous image for layer cache |
| 85 | + run: | |
| 86 | + docker pull "${{ steps.params.outputs.latest_image }}" || true |
| 87 | + docker pull moby/buildkit:buildx-stable-1 |
| 88 | +
|
| 89 | + - name: Set up Docker Buildx |
| 90 | + uses: docker/setup-buildx-action@v3 |
| 91 | + with: |
| 92 | + platforms: linux/${{ steps.params.outputs.platform }} |
| 93 | + |
| 94 | + - name: docker bake |
| 95 | + uses: docker/bake-action@v5 |
| 96 | + with: |
| 97 | + targets: pg_duckpipe_${{ matrix.postgres }} |
| 98 | + push: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} |
| 99 | + set: | |
| 100 | + *.platform=linux/${{ steps.params.outputs.platform }} |
| 101 | + *.cache-from=type=registry,ref=${{ steps.params.outputs.latest_image }} |
| 102 | + *.cache-from=type=gha,scope=${{ github.workflow }} |
| 103 | + *.cache-to=type=gha,mode=max,scope=${{ github.workflow }} |
| 104 | + pg_duckpipe.tags=pgducklake/pipe-ci-builds:${{ matrix.postgres }}-${{ steps.params.outputs.platform }}-${{ github.sha }} |
| 105 | + pg_duckpipe.tags=${{ steps.params.outputs.latest_image }} |
| 106 | +
|
| 107 | + docker_merge: |
| 108 | + name: Merge Docker image for Postgres ${{ matrix.postgres }} |
| 109 | + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
| 110 | + strategy: |
| 111 | + matrix: |
| 112 | + postgres: ["18"] |
| 113 | + |
| 114 | + runs-on: ubuntu-24.04 |
| 115 | + needs: docker_build |
| 116 | + |
| 117 | + steps: |
| 118 | + - name: Login to Docker Hub |
| 119 | + uses: docker/login-action@v3 |
| 120 | + with: |
| 121 | + username: pgducklake |
| 122 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 123 | + |
| 124 | + - name: Merge amd64 + arm64 into a multi-arch manifest |
| 125 | + run: | |
| 126 | + docker pull --platform linux/amd64 \ |
| 127 | + pgducklake/pipe-ci-builds:${{ matrix.postgres }}-amd64-${{ github.sha }} |
| 128 | + docker pull --platform linux/arm64 \ |
| 129 | + pgducklake/pipe-ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }} |
| 130 | +
|
| 131 | + BRANCH="${{ needs.docker_build.outputs.branch_tag }}" |
| 132 | + TARGET_REPO="${{ needs.docker_build.outputs.target_repo }}" |
| 133 | +
|
| 134 | + echo "Pushing merged manifest to '${TARGET_REPO}'" |
| 135 | + docker buildx imagetools create \ |
| 136 | + --tag "${TARGET_REPO}:${{ matrix.postgres }}-${BRANCH}" \ |
| 137 | + --tag "pgducklake/pipe-ci-builds:${{ matrix.postgres }}-${{ github.sha }}" \ |
| 138 | + "pgducklake/pipe-ci-builds:${{ matrix.postgres }}-amd64-${{ github.sha }}" \ |
| 139 | + "pgducklake/pipe-ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }}" |
| 140 | +
|
| 141 | + docker buildx imagetools inspect \ |
| 142 | + "pgducklake/pipe-ci-builds:${{ matrix.postgres }}-${{ github.sha }}" |
0 commit comments