Skip to content

Commit 3390c64

Browse files
authored
chore(ci): added git short hash to docker images tags (#8152)
1 parent b76806d commit 3390c64

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

.github/workflows/build-and-dockerize.yaml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ jobs:
158158
string: ${{ github.ref }}-${{ inputs.targets }}-${{ matrix.platform }}
159159
replace-with: '_'
160160

161+
- name: docker image short sha
162+
id: git_hash
163+
run: |
164+
# if in a PR, use the PR SHA; otherwise, use the commit SHA
165+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
166+
FULL_PR_SHA=${{ github.event.pull_request.head.sha }}
167+
echo "sha_short=${FULL_PR_SHA:0:7}" >> $GITHUB_OUTPUT
168+
else
169+
echo "sha_short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
170+
fi
171+
161172
- name: build docker images (${{ matrix.platform }})
162173
timeout-minutes: 60
163174
id: docker-bake
@@ -166,6 +177,7 @@ jobs:
166177
env:
167178
DOCKER_REGISTRY: ${{ inputs.registry }}/${{ inputs.imageName }}/
168179
COMMIT_SHA: ${{ inputs.imageTag }}
180+
COMMIT_SHORT_SHA: ${{ steps.git_hash.outputs.sha_short }}
169181
RELEASE: ${{ inputs.imageTag }}
170182
BRANCH_NAME: ${{ steps.branch_name_fix.outputs.replaced }}
171183
BUILD_TYPE: 'publish'
@@ -192,13 +204,13 @@ jobs:
192204
with:
193205
header: ${{ github.workflow }}
194206
message: |
195-
🐋 This PR was built and pushed to the following [Docker images](https://github.com/graphql-hive?ecosystem=container&tab=packages&visibility=public):
207+
🐋 This PR was built and pushed to the following [Docker images](https://github.com/orgs/graphql-hive/packages?ecosystem=container&repo_name=console):
196208
197209
**Targets**: `${{ inputs.targets }}`
198210
199211
**Platforms**: `${{ matrix.platform }}`
200212
201-
**Image Tag**: `${{ inputs.imageTag }}`
213+
**Image Tags**: `${{ inputs.imageTag }}`, `${{ steps.git_hash.outputs.sha_short }}`
202214
203215
- name: upload sourcemaps to Sentry
204216
if: ${{ inputs.publishSourceMaps }}
@@ -249,6 +261,36 @@ jobs:
249261
docker manifest push $image_name
250262
done
251263
264+
- name: docker image short sha
265+
id: git_hash
266+
run: |
267+
# if in a PR, use the PR SHA; otherwise, use the commit SHA
268+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
269+
FULL_PR_SHA=${{ github.event.pull_request.head.sha }}
270+
echo "sha_short=${FULL_PR_SHA:0:7}" >> $GITHUB_OUTPUT
271+
else
272+
echo "sha_short=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
273+
fi
274+
275+
- name: 'publish docker multiarch manifest (tag: ${{ steps.git_hash.outputs.sha_short }})'
276+
env:
277+
TARGETS: ${{ inputs.targets }}
278+
REGISTRY: ${{ inputs.registry }}
279+
IMAGE_NAME: ${{ inputs.imageName }}
280+
IMAGE_TAG: ${{ steps.git_hash.outputs.sha_short }}
281+
run: |
282+
targets=$(docker buildx bake -f docker/docker.hcl --print "$TARGETS" | jq -r '.group."'"$TARGETS"'".targets[]')
283+
284+
for target in $targets
285+
do
286+
echo "publishing multi-arch manifest for $target"
287+
image_name="$REGISTRY/$IMAGE_NAME/$target:$IMAGE_TAG"
288+
echo "image name: $image_name"
289+
290+
docker manifest create $image_name --amend "$image_name-arm64" --amend "$image_name-amd64"
291+
docker manifest push $image_name
292+
done
293+
252294
- name: 'publish docker multiarch manifest (tag: latest)'
253295
if: ${{ inputs.publishLatest }}
254296
env:

docker/docker.hcl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ variable "COMMIT_SHA" {
1414
default = ""
1515
}
1616

17+
variable "COMMIT_SHORT_SHA" {
18+
default = ""
19+
}
20+
1721
variable "BRANCH_NAME" {
1822
default = ""
1923
}
@@ -126,6 +130,7 @@ target "schema" {
126130
local_image_tag("schema"),
127131
stable_image_tag("schema"),
128132
image_tag("schema", COMMIT_SHA),
133+
image_tag("schema", COMMIT_SHORT_SHA),
129134
image_tag("schema", BRANCH_NAME)
130135
]
131136
}
@@ -147,6 +152,7 @@ target "policy" {
147152
local_image_tag("policy"),
148153
stable_image_tag("policy"),
149154
image_tag("policy", COMMIT_SHA),
155+
image_tag("policy", COMMIT_SHORT_SHA),
150156
image_tag("policy", BRANCH_NAME)
151157
]
152158
}
@@ -168,6 +174,7 @@ target "server" {
168174
local_image_tag("server"),
169175
stable_image_tag("server"),
170176
image_tag("server", COMMIT_SHA),
177+
image_tag("server", COMMIT_SHORT_SHA),
171178
image_tag("server", BRANCH_NAME)
172179
]
173180
}
@@ -186,6 +193,7 @@ target "storage" {
186193
local_image_tag("storage"),
187194
stable_image_tag("storage"),
188195
image_tag("storage", COMMIT_SHA),
196+
image_tag("storage", COMMIT_SHORT_SHA),
189197
image_tag("storage", BRANCH_NAME)
190198
]
191199
}
@@ -207,6 +215,7 @@ target "commerce" {
207215
local_image_tag("commerce"),
208216
stable_image_tag("commerce"),
209217
image_tag("commerce", COMMIT_SHA),
218+
image_tag("commerce", COMMIT_SHORT_SHA),
210219
image_tag("commerce", BRANCH_NAME)
211220
]
212221
}
@@ -228,6 +237,7 @@ target "tokens" {
228237
local_image_tag("tokens"),
229238
stable_image_tag("tokens"),
230239
image_tag("tokens", COMMIT_SHA),
240+
image_tag("tokens", COMMIT_SHORT_SHA),
231241
image_tag("tokens", BRANCH_NAME)
232242
]
233243
}
@@ -249,6 +259,7 @@ target "usage-ingestor" {
249259
local_image_tag("usage-ingestor"),
250260
stable_image_tag("usage-ingestor"),
251261
image_tag("usage-ingestor", COMMIT_SHA),
262+
image_tag("usage-ingestor", COMMIT_SHORT_SHA),
252263
image_tag("usage-ingestor", BRANCH_NAME)
253264
]
254265
}
@@ -270,6 +281,7 @@ target "usage" {
270281
local_image_tag("usage"),
271282
stable_image_tag("usage"),
272283
image_tag("usage", COMMIT_SHA),
284+
image_tag("usage", COMMIT_SHORT_SHA),
273285
image_tag("usage", BRANCH_NAME)
274286
]
275287
}
@@ -291,6 +303,7 @@ target "workflows" {
291303
local_image_tag("workflows"),
292304
stable_image_tag("workflows"),
293305
image_tag("workflows", COMMIT_SHA),
306+
image_tag("workflows", COMMIT_SHORT_SHA),
294307
image_tag("workflows", BRANCH_NAME)
295308
]
296309
}
@@ -312,6 +325,7 @@ target "composition-federation-2" {
312325
local_image_tag("composition-federation-2"),
313326
stable_image_tag("composition-federation-2"),
314327
image_tag("composition-federation-2", COMMIT_SHA),
328+
image_tag("composition-federation-2", COMMIT_SHORT_SHA),
315329
image_tag("composition-federation-2", BRANCH_NAME)
316330
]
317331
}
@@ -333,6 +347,7 @@ target "app" {
333347
local_image_tag("app"),
334348
stable_image_tag("app"),
335349
image_tag("app", COMMIT_SHA),
350+
image_tag("app", COMMIT_SHORT_SHA),
336351
image_tag("app", BRANCH_NAME)
337352
]
338353
}
@@ -348,6 +363,7 @@ target "otel-collector" {
348363
local_image_tag("otel-collector"),
349364
stable_image_tag("otel-collector"),
350365
image_tag("otel-collector", COMMIT_SHA),
366+
image_tag("otel-collector", COMMIT_SHORT_SHA),
351367
image_tag("otel-collector", BRANCH_NAME)
352368
]
353369
}
@@ -365,6 +381,7 @@ target "cli" {
365381
local_image_tag("cli"),
366382
stable_image_tag("cli"),
367383
image_tag("cli", COMMIT_SHA),
384+
image_tag("cli", COMMIT_SHORT_SHA),
368385
image_tag("cli", BRANCH_NAME)
369386
]
370387
}

0 commit comments

Comments
 (0)