3030 BUILDKIT_PROGRESS : plain
3131 POSTGRES_VERSION : ${{ matrix.postgres }}
3232 outputs :
33- branch_tag : ${{ steps.compute_platform.outputs.branch_tag }}
33+ branch_tag : ${{ steps.params.outputs.branch_tag }}
34+ target_repo : ${{ steps.params.outputs.target_repo }}
3435 steps :
3536 - name : Login to Docker Hub
3637 uses : docker/login-action@v3
@@ -43,46 +44,58 @@ jobs:
4344 with :
4445 submodules : " recursive"
4546
46- - name : Compute platform
47- id : compute_platform
47+ - name : Compute job parameters
48+ id : params
4849 run : |
4950 # Tag is XX-YYYYY-<branch>-latest so 16 + branch name length
5051 # since maximum docker tag is 128 characters, we need to truncate the branch name to 112
5152 BRANCH=$(echo "${{ github.head_ref || github.ref_name }}" \
52- | sed 's/[^a-zA-Z0-9\-]/-/g' \
53+ | sed 's/[^a-zA-Z0-9\-\. ]/-/g' \
5354 | cut -c 1-112 | tr '[:upper:]' '[:lower:]' \
5455 | sed -e 's/-*$//')
5556
56- echo "branch_tag=$BRANCH" >> "$GITHUB_OUTPUT"
5757 # Set platform depending on which runner we're using
5858 if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then
59- echo "platform=amd64" >> "$GITHUB_OUTPUT"
59+ PLATFORM=amd64
60+ else
61+ PLATFORM=arm64
62+ fi
63+
64+ # If main or tag, then push to `pgduckdb/pgduckdb`
65+ git fetch --tags
66+ if [ "$BRANCH" = "main" ] || git rev-parse --verify $BRANCH^{tag} > /dev/null 2>&1; then
67+ TARGET_REPO='pgduckdb/pgduckdb'
6068 else
61- echo "platform=arm64" >> "$GITHUB_OUTPUT"
69+ TARGET_REPO='pgduckdb/ci-builds'
6270 fi
6371
72+ echo "platform=$PLATFORM" >> "$GITHUB_OUTPUT"
73+ echo "branch_tag=$BRANCH" >> "$GITHUB_OUTPUT"
74+ echo "target_repo=$TARGET_REPO" >> "$GITHUB_OUTPUT"
75+ echo "latest_image=pgduckdb/ci-builds:${{ matrix.postgres }}-${PLATFORM}-${BRANCH}-latest" >> "$GITHUB_OUTPUT"
76+
6477 - name : Attempt to pull previous image
6578 run : |
66- docker pull pgduckdb/ci-builds: ${{ matrix.postgres }}-${{ steps.compute_platform .outputs.platform }}-${{ steps.compute_platform.outputs.branch_tag }}-latest || true
79+ docker pull ${{ steps.params .outputs.latest_image }} || true
6780 docker pull moby/buildkit:buildx-stable-1
6881
6982 - name : Set up Docker buildx
7083 uses : docker/setup-buildx-action@v3
7184 with :
72- platforms : linux/${{ steps.compute_platform .outputs.platform }}
85+ platforms : linux/${{ steps.params .outputs.platform }}
7386
7487 - name : docker bake
7588 uses : docker/bake-action@v5
7689 with :
7790 targets : pg_duckdb_${{ matrix.postgres }}
7891 push : true
7992 set : |
80- *.platform=linux/${{ steps.compute_platform .outputs.platform }}
81- *.cache-from=type=registry,ref=pgduckdb/ci-builds: ${{ matrix.postgres }}-${{ steps.compute_platform .outputs.platform }}-${{ steps.compute_platform.outputs.branch_tag }}-latest
93+ *.platform=linux/${{ steps.params .outputs.platform }}
94+ *.cache-from=type=registry,ref=${{ steps.params .outputs.latest_image }}
8295 *.cache-from=type=gha,scope=${{ github.workflow }}
8396 *.cache-to=type=gha,mode=max,scope=${{ github.workflow }}
84- postgres.tags=pgduckdb/ci-builds:${{ matrix.postgres }}-${{ steps.compute_platform .outputs.platform }}-${{ github.sha }}
85- postgres.tags=pgduckdb/ci-builds: ${{ matrix.postgres }}-${{ steps.compute_platform .outputs.platform }}-${{ steps.compute_platform.outputs.branch_tag }}-latest
97+ postgres.tags=pgduckdb/ci-builds:${{ matrix.postgres }}-${{ steps.params .outputs.platform }}-${{ github.sha }}
98+ postgres.tags=${{ steps.params .outputs.latest_image }}
8699
87100 docker_merge :
88101 name : Merge Docker image for Postgres ${{ matrix.postgres }}
@@ -105,19 +118,13 @@ jobs:
105118 docker pull --platform linux/arm64 pgduckdb/ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }}
106119
107120 BRANCH="${{ needs.docker_build.outputs.branch_tag }}"
108-
109- # If main or tag, then push to `pgduckdb/pgduckdb`
110- if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "v"* ]; then
111- TARGET_REPO='pgduckdb/pgduckdb'
112- else
113- TARGET_REPO='pgduckdb/ci-builds'
114- SHA_TAG="--tag ${TARGET_REPO}:${{ matrix.postgres }}-${{ github.sha }}"
115- fi
121+ TARGET_REPO="${{ needs.docker_build.outputs.target_repo }}"
116122
117123 echo "Will push merged image to '${TARGET_REPO}'."
118- docker buildx imagetools create ${SHA_TAG} \
119- --tag ${TARGET_REPO}:${{ matrix.postgres }}-${BRANCH} \
124+ docker buildx imagetools create \
125+ --tag ${TARGET_REPO}:${{ matrix.postgres }}-${BRANCH} \
126+ --tag pgduckdb/ci-builds:${{ matrix.postgres }}-${{ github.sha }} \
120127 pgduckdb/ci-builds:${{ matrix.postgres }}-amd64-${{ github.sha }} \
121128 pgduckdb/ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }}
122129
123- docker buildx imagetools inspect ${TARGET_REPO} :${{ matrix.postgres }}-${{ github.sha }}
130+ docker buildx imagetools inspect pgduckdb/ci-builds :${{ matrix.postgres }}-${{ github.sha }}
0 commit comments