|
1 | 1 | name: Build Docker
|
2 | 2 |
|
| 3 | +permissions: |
| 4 | + id-token: write |
| 5 | + contents: write |
| 6 | + |
3 | 7 | on:
|
4 | 8 | push:
|
5 | 9 | tags: ["v*"]
|
|
13 | 17 | workflow_dispatch:
|
14 | 18 |
|
15 | 19 | jobs:
|
16 |
| - docker: |
17 |
| - name: Build Docker |
18 |
| - runs-on: ubuntu-24.04 |
| 20 | + docker_build: |
| 21 | + name: Build Docker image for Postgres ${{ matrix.postgres }} on ${{ matrix.runner }} |
19 | 22 | strategy:
|
20 | 23 | matrix:
|
21 | 24 | postgres: ["14", "15", "16", "17"]
|
| 25 | + runner: ["ubuntu-24.04", "ubuntu-24.04-arm"] |
22 | 26 |
|
| 27 | + runs-on: ${{ matrix.runner }} |
| 28 | + |
| 29 | + env: |
| 30 | + BUILDKIT_PROGRESS: plain |
| 31 | + POSTGRES_VERSION: ${{ matrix.postgres }} |
| 32 | + outputs: |
| 33 | + branch_tag: ${{ steps.params.outputs.branch_tag }} |
| 34 | + target_repo: ${{ steps.params.outputs.target_repo }} |
23 | 35 | steps:
|
24 | 36 | - name: Login to Docker Hub
|
25 | 37 | uses: docker/login-action@v3
|
26 | 38 | with:
|
27 | 39 | username: pgduckdb
|
28 | 40 | password: ${{ secrets.DOCKERHUB_TOKEN }}
|
| 41 | + |
29 | 42 | - name: Checkout pg_duckdb extension code
|
30 | 43 | uses: actions/checkout@v4
|
31 | 44 | with:
|
32 | 45 | submodules: "recursive"
|
33 |
| - - name: Set env |
| 46 | + |
| 47 | + - name: Compute job parameters |
| 48 | + id: params |
34 | 49 | run: |
|
35 |
| - echo "POSTGRES_VERSION=${{ matrix.postgres }}" >> $GITHUB_ENV |
36 |
| - - name: Set up QEMU |
37 |
| - uses: docker/setup-qemu-action@v3 |
| 50 | + # Tag is XX-YYYYY-<branch>-latest so 16 + branch name length |
| 51 | + # since maximum docker tag is 128 characters, we need to truncate the branch name to 112 |
| 52 | + BRANCH=$(echo "${{ github.head_ref || github.ref_name }}" \ |
| 53 | + | sed 's/[^a-zA-Z0-9\-\.]/-/g' \ |
| 54 | + | cut -c 1-112 | tr '[:upper:]' '[:lower:]' \ |
| 55 | + | sed -e 's/-*$//') |
| 56 | +
|
| 57 | + # Set platform depending on which runner we're using |
| 58 | + if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then |
| 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 --force |
| 66 | + if [ "$BRANCH" = "main" ] || git rev-parse --verify $BRANCH^{tag} > /dev/null 2>&1; then |
| 67 | + TARGET_REPO='pgduckdb/pgduckdb' |
| 68 | + else |
| 69 | + TARGET_REPO='pgduckdb/ci-builds' |
| 70 | + fi |
| 71 | +
|
| 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 | +
|
| 77 | + - name: Attempt to pull previous image |
| 78 | + run: | |
| 79 | + docker pull ${{ steps.params.outputs.latest_image }} || true |
| 80 | + docker pull moby/buildkit:buildx-stable-1 |
| 81 | +
|
38 | 82 | - name: Set up Docker buildx
|
39 | 83 | uses: docker/setup-buildx-action@v3
|
40 | 84 | with:
|
41 |
| - platforms: linux/amd64,linux/arm64 |
| 85 | + platforms: linux/${{ steps.params.outputs.platform }} |
| 86 | + |
42 | 87 | - name: docker bake
|
43 | 88 | uses: docker/bake-action@v5
|
44 | 89 | with:
|
45 | 90 | targets: pg_duckdb_${{ matrix.postgres }}
|
46 | 91 | push: true
|
47 | 92 | set: |
|
48 |
| - *.platform=linux/amd64,linux/arm64 |
49 |
| - *.cache-to=type=gha,mode=max |
50 |
| - *.cache-from=type=gha |
51 |
| - postgres.tags=pgduckdb/pgduckdb:${{ matrix.postgres }}-${{ github.sha }} |
52 |
| - ${{ !contains(github.ref_name, '/') && format('postgres.tags=pgduckdb/pgduckdb:{0}-{1}', matrix.postgres, github.ref_name) || '' }} |
| 93 | + *.platform=linux/${{ steps.params.outputs.platform }} |
| 94 | + *.cache-from=type=registry,ref=${{ steps.params.outputs.latest_image }} |
| 95 | + *.cache-from=type=gha,scope=${{ github.workflow }} |
| 96 | + *.cache-to=type=gha,mode=max,scope=${{ github.workflow }} |
| 97 | + postgres.tags=pgduckdb/ci-builds:${{ matrix.postgres }}-${{ steps.params.outputs.platform }}-${{ github.sha }} |
| 98 | + postgres.tags=${{ steps.params.outputs.latest_image }} |
| 99 | +
|
| 100 | + docker_merge: |
| 101 | + name: Merge Docker image for Postgres ${{ matrix.postgres }} |
| 102 | + strategy: |
| 103 | + matrix: |
| 104 | + postgres: ["14", "15", "16", "17"] |
| 105 | + |
| 106 | + runs-on: ubuntu-24.04 |
| 107 | + needs: docker_build |
| 108 | + steps: |
| 109 | + - name: Login to Docker Hub |
| 110 | + uses: docker/login-action@v3 |
| 111 | + with: |
| 112 | + username: pgduckdb |
| 113 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 114 | + |
| 115 | + - name: Merge images |
| 116 | + run: | |
| 117 | + docker pull --platform linux/amd64 pgduckdb/ci-builds:${{ matrix.postgres }}-amd64-${{ github.sha }} |
| 118 | + docker pull --platform linux/arm64 pgduckdb/ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }} |
| 119 | +
|
| 120 | + BRANCH="${{ needs.docker_build.outputs.branch_tag }}" |
| 121 | + TARGET_REPO="${{ needs.docker_build.outputs.target_repo }}" |
| 122 | +
|
| 123 | + echo "Will push merged image to '${TARGET_REPO}'." |
| 124 | + docker buildx imagetools create \ |
| 125 | + --tag ${TARGET_REPO}:${{ matrix.postgres }}-${BRANCH} \ |
| 126 | + --tag pgduckdb/ci-builds:${{ matrix.postgres }}-${{ github.sha }} \ |
| 127 | + pgduckdb/ci-builds:${{ matrix.postgres }}-amd64-${{ github.sha }} \ |
| 128 | + pgduckdb/ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }} |
| 129 | +
|
| 130 | + docker buildx imagetools inspect pgduckdb/ci-builds:${{ matrix.postgres }}-${{ github.sha }} |
0 commit comments