Build images on target platforms #198
This file contains 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
name: Build Docker | |
on: | |
push: | |
tags: ["v*"] | |
pull_request: | |
paths: | |
- Dockerfile | |
- docker-bake.hcl | |
- ".github/workflows/docker.yaml" | |
schedule: | |
- cron: "44 4 * * *" | |
workflow_dispatch: | |
jobs: | |
docker_build: | |
name: Build Docker image for Postgres ${{ matrix.postgres }} on ${{ matrix.runner }} | |
strategy: | |
matrix: | |
postgres: ["14", "15", "16", "17"] | |
runner: ["ubuntu-24.04", "ubuntu-24.04-arm"] | |
runs-on: ${{ matrix.runner }} | |
env: | |
BUILDKIT_PROGRESS: plain | |
POSTGRES_VERSION: ${{ matrix.postgres }} | |
outputs: | |
branch_tag: ${{ steps.compute_platform.outputs.branch_tag }} | |
steps: | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: pgduckdb | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Checkout pg_duckdb extension code | |
uses: actions/checkout@v4 | |
with: | |
submodules: "recursive" | |
- name: Compute platform | |
id: compute_platform | |
run: | | |
# Tag is XX-YYYYY-<branch>-latest so 16 + branch name length | |
# since maximum docker tag is 128 characters, we need to truncate the branch name to 112 | |
BRANCH=$(echo "${{ github.head_ref || github.ref_name }}" \ | |
| sed 's/[^a-zA-Z0-9\-]/-/g' \ | |
| cut -c 1-112 | tr '[:upper:]' '[:lower:]' \ | |
| sed -e 's/-*$//') | |
echo "branch_tag=$BRANCH" >> "$GITHUB_OUTPUT" | |
# Set platform depending on which runner we're using | |
if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then | |
echo "platform=amd64" >> "$GITHUB_OUTPUT" | |
else | |
echo "platform=arm64" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Attempt to pull previous image | |
run: | | |
docker pull pgduckdb/pgduckdb:${{ matrix.postgres }}-${{ steps.compute_platform.outputs.platform }}-${{ steps.compute_platform.outputs.branch_tag }}-latest || true | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
platforms: linux/${{ steps.compute_platform.outputs.platform }} | |
- name: docker bake | |
uses: docker/bake-action@v5 | |
with: | |
targets: pg_duckdb_${{ matrix.postgres }} | |
push: true | |
set: | | |
*.platform=linux/${{ steps.compute_platform.outputs.platform }} | |
*.cache-to=type=gha,mode=max | |
*.cache-from=type=gha | |
postgres.tags=pgduckdb/pgduckdb:${{ matrix.postgres }}-${{ steps.compute_platform.outputs.platform }}-${{ github.sha }} | |
postgres.tags=pgduckdb/pgduckdb:${{ matrix.postgres }}-${{ steps.compute_platform.outputs.platform }}-${{ steps.compute_platform.outputs.branch_tag }}-latest | |
docker_merge: | |
name: Merge Docker image for Postgres ${{ matrix.postgres }} | |
strategy: | |
matrix: | |
postgres: ["14", "15", "16", "17"] | |
runs-on: ubuntu-24.04 | |
needs: docker_build | |
steps: | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: pgduckdb | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Pull images | |
run: | | |
docker pull --platform linux/amd64 pgduckdb/pgduckdb:${{ matrix.postgres }}-amd64-${{ github.sha }} | |
docker pull --platform linux/arm64 pgduckdb/pgduckdb:${{ matrix.postgres }}-arm64-${{ github.sha }} | |
BRANCH="${{ needs.docker_build.outputs.branch_tag }}" | |
docker buildx imagetools create \ | |
--tag pgduckdb/pgduckdb:${{ matrix.postgres }}-${{ github.sha }} \ | |
--tag pgduckdb/pgduckdb:${{ matrix.postgres }}-${BRANCH}-latest \ | |
pgduckdb/pgduckdb:${{ matrix.postgres }}-amd64-${{ github.sha }} \ | |
pgduckdb/pgduckdb:${{ matrix.postgres }}-arm64-${{ github.sha }} | |
docker buildx imagetools inspect pgduckdb/pgduckdb:${{ matrix.postgres }}-${{ github.sha }} |