-
Notifications
You must be signed in to change notification settings - Fork 82
130 lines (111 loc) · 4.51 KB
/
docker.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Build Docker
permissions:
id-token: write
contents: write
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.params.outputs.branch_tag }}
target_repo: ${{ steps.params.outputs.target_repo }}
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 job parameters
id: params
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/-*$//')
# Set platform depending on which runner we're using
if [ "${{ matrix.runner }}" = "ubuntu-24.04" ]; then
PLATFORM=amd64
else
PLATFORM=arm64
fi
# If main or tag, then push to `pgduckdb/pgduckdb`
git fetch --tags --force
if [ "$BRANCH" = "main" ] || git rev-parse --verify $BRANCH^{tag} > /dev/null 2>&1; then
TARGET_REPO='pgduckdb/pgduckdb'
else
TARGET_REPO='pgduckdb/ci-builds'
fi
echo "platform=$PLATFORM" >> "$GITHUB_OUTPUT"
echo "branch_tag=$BRANCH" >> "$GITHUB_OUTPUT"
echo "target_repo=$TARGET_REPO" >> "$GITHUB_OUTPUT"
echo "latest_image=pgduckdb/ci-builds:${{ matrix.postgres }}-${PLATFORM}-${BRANCH}-latest" >> "$GITHUB_OUTPUT"
- name: Attempt to pull previous image
run: |
docker pull ${{ steps.params.outputs.latest_image }} || true
docker pull moby/buildkit:buildx-stable-1
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/${{ steps.params.outputs.platform }}
- name: docker bake
uses: docker/bake-action@v5
with:
targets: pg_duckdb_${{ matrix.postgres }}
push: true
set: |
*.platform=linux/${{ steps.params.outputs.platform }}
*.cache-from=type=registry,ref=${{ steps.params.outputs.latest_image }}
*.cache-from=type=gha,scope=${{ github.workflow }}
*.cache-to=type=gha,mode=max,scope=${{ github.workflow }}
postgres.tags=pgduckdb/ci-builds:${{ matrix.postgres }}-${{ steps.params.outputs.platform }}-${{ github.sha }}
postgres.tags=${{ steps.params.outputs.latest_image }}
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: Merge images
run: |
docker pull --platform linux/amd64 pgduckdb/ci-builds:${{ matrix.postgres }}-amd64-${{ github.sha }}
docker pull --platform linux/arm64 pgduckdb/ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }}
BRANCH="${{ needs.docker_build.outputs.branch_tag }}"
TARGET_REPO="${{ needs.docker_build.outputs.target_repo }}"
echo "Will push merged image to '${TARGET_REPO}'."
docker buildx imagetools create \
--tag ${TARGET_REPO}:${{ matrix.postgres }}-${BRANCH} \
--tag pgduckdb/ci-builds:${{ matrix.postgres }}-${{ github.sha }} \
pgduckdb/ci-builds:${{ matrix.postgres }}-amd64-${{ github.sha }} \
pgduckdb/ci-builds:${{ matrix.postgres }}-arm64-${{ github.sha }}
docker buildx imagetools inspect pgduckdb/ci-builds:${{ matrix.postgres }}-${{ github.sha }}