1212 IMAGE_NAME : constructive-io/docker/postgres-plus
1313 PG_VERSION : ' 17'
1414
15+ concurrency :
16+ group : ${{ github.workflow }}-${{ github.ref }}-docker-postgres-plus
17+ cancel-in-progress : true
18+
1519jobs :
16- build :
17- runs-on : ubuntu-latest
20+ build-postgres-plus :
21+ strategy :
22+ fail-fast : false
23+ matrix :
24+ include :
25+ - platform : linux/amd64
26+ arch : amd64
27+ runner : ubuntu-latest
28+ - platform : linux/arm64
29+ arch : arm64
30+ runner : ubuntu-24.04-arm
31+ runs-on : ${{ matrix.runner }}
32+
1833 permissions :
1934 contents : read
2035 packages : write
2338 - name : Checkout
2439 uses : actions/checkout@v4
2540
26- - name : Set up QEMU
27- uses : docker/setup-qemu-action@v3
28-
2941 - name : Set up Docker Buildx
3042 uses : docker/setup-buildx-action@v3
3143
@@ -49,15 +61,117 @@ jobs:
4961 type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
5062 type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
5163
52- - name : Build and push
64+ - name : Build (no push, PR only, amd64)
65+ if : github.event_name == 'pull_request' && matrix.platform == 'linux/amd64'
5366 uses : docker/build-push-action@v6
5467 with :
5568 context : .
56- platforms : linux/amd64,linux/arm64
57- push : ${{ github.event_name != 'pull_request' }}
69+ file : ./Dockerfile
70+ platforms : linux/amd64
71+ push : false
5872 tags : ${{ steps.meta.outputs.tags }}
5973 labels : ${{ steps.meta.outputs.labels }}
6074 build-args : |
6175 PG_VERSION=${{ env.PG_VERSION }}
6276 cache-from : type=gha
6377 cache-to : type=gha,mode=max
78+
79+ - name : Build & push by digest
80+ if : github.event_name != 'pull_request'
81+ id : build
82+ uses : docker/build-push-action@v6
83+ with :
84+ context : .
85+ file : ./Dockerfile
86+ platforms : ${{ matrix.platform }}
87+ labels : ${{ steps.meta.outputs.labels }}
88+ outputs : type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,push=true
89+ build-args : |
90+ PG_VERSION=${{ env.PG_VERSION }}
91+ cache-from : type=gha
92+ cache-to : type=gha,mode=max
93+
94+ - name : Export digest
95+ if : github.event_name != 'pull_request'
96+ run : |
97+ mkdir -p "${{ runner.temp }}/digests"
98+ digest="${{ steps.build.outputs.digest }}"
99+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
100+
101+ - name : Upload digest
102+ if : github.event_name != 'pull_request'
103+ uses : actions/upload-artifact@v4
104+ with :
105+ name : digests-${{ matrix.arch }}
106+ path : ${{ runner.temp }}/digests/*
107+
108+ publish-postgres-plus-manifest :
109+ if : github.event_name != 'pull_request'
110+ runs-on : ubuntu-latest
111+ needs : build-postgres-plus
112+
113+ permissions :
114+ contents : read
115+ packages : write
116+
117+ steps :
118+ - name : Set up Docker Buildx
119+ uses : docker/setup-buildx-action@v3
120+
121+ - name : Log in to Container Registry
122+ uses : docker/login-action@v3
123+ with :
124+ registry : ${{ env.REGISTRY }}
125+ username : ${{ github.actor }}
126+ password : ${{ secrets.GITHUB_TOKEN }}
127+
128+ - name : Download digests
129+ uses : actions/download-artifact@v4
130+ with :
131+ pattern : digests-*
132+ path : ${{ runner.temp }}/digests
133+ merge-multiple : true
134+
135+ - name : Extract metadata
136+ id : meta
137+ uses : docker/metadata-action@v5
138+ with :
139+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
140+ tags : |
141+ type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
142+ type=raw,value=${{ env.PG_VERSION }},enable=${{ github.ref == 'refs/heads/main' }}
143+ type=sha,format=short,prefix=
144+ type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
145+ type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
146+
147+ - name : Create and push multi-arch manifests
148+ run : |
149+ set -euo pipefail
150+
151+ image="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}"
152+ digest_dir="${{ runner.temp }}/digests"
153+
154+ if [ ! -d "$digest_dir" ]; then
155+ echo "No digests directory found at $digest_dir"
156+ exit 1
157+ fi
158+
159+ digests=""
160+ for digest_file in "$digest_dir"/*; do
161+ digest="$(basename "$digest_file")"
162+ digests="$digests $image@sha256:$digest"
163+ done
164+
165+ if [ -z "$digests" ]; then
166+ echo "No digests found to create manifest"
167+ exit 1
168+ fi
169+
170+ echo "Creating manifests for tags:"
171+ echo "${{ steps.meta.outputs.tags }}"
172+
173+ echo "${{ steps.meta.outputs.tags }}" | while read -r tag; do
174+ [ -z "$tag" ] && continue
175+ echo "Creating multi-arch manifest for $tag"
176+ docker buildx imagetools create -t "$tag" $digests
177+ done
0 commit comments