Skip to content

Commit 35a7497

Browse files
authored
fix: skip build/push image if it already exists (#108)
When building the Helm chart, we do not need to build/push images that already exist. By skipping that, we can save up to ~1h of build time (if we sum up all the durations in all the build/push jobs) and ~10min of waiting (the maximum duration is ~10min, for the github_hooks application) on the "Generate Helm chart" promotion.
1 parent 4598b01 commit 35a7497

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.semaphore/generate-helm-chart.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ blocks:
1414
value: "prod"
1515
- name: DOCKER_BUILDKIT
1616
value: "1"
17+
- name: REGISTRY_HOST
18+
value: "ghcr.io/semaphoreio"
1719
jobs:
1820
- name: Build and push images
1921
matrix:
@@ -34,7 +36,6 @@ blocks:
3436
- "PublicApiGateway"
3537
- "HooksProcessor"
3638
- "HooksReceiver"
37-
- "Self Hosted Hub"
3839
- "Keycloak image"
3940
- "Keycloak setup"
4041
- "Bootstrapper"
@@ -60,9 +61,14 @@ blocks:
6061
- if git rev-parse --is-shallow-repository | grep -q true; then git fetch --unshallow --tags; else git fetch --tags; fi
6162
- export APP_NAME=$(jq -r --arg application "$APPLICATION" '.services[$application][]["app"]' .semaphore/services.json)
6263
- cd $(jq -r --arg application "$APPLICATION" '.services[$application][]["path"]' .semaphore/services.json)
64+
- |
65+
if docker manifest inspect $(make registry.image); then
66+
echo "Image $(make registry.image) already exists - skipping"
67+
export SEMAPHORE_JOB_RESULT=passed
68+
return 130
69+
fi
6370
- make build NO_BUILD_CACHE=true
6471
- 'if [[ -n $SEMAPHORE_GIT_TAG_NAME ]]; then make configure.sign; fi'
65-
- export REGISTRY_HOST=ghcr.io/semaphoreio
6672
- make registry.configure
6773
- make registry.push
6874
- 'if [[ -n $SEMAPHORE_GIT_TAG_NAME ]]; then make registry.sign; fi'

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ registry.sign: cosign.install
268268
--identity-token $$(cat /tmp/sigstore-token) \
269269
$(shell docker inspect --format='{{index .RepoDigests 0}}' $(REGISTRY_HOST)/$(APP_NAME):$(RELEASE_TAG))
270270

271+
registry.image:
272+
@echo $(REGISTRY_HOST)/$(APP_NAME):$(RELEASE_TAG)
273+
271274
registry.configure:
272275
@printf "%s" "$(GITHUB_TOKEN)" | docker login ghcr.io -u "$(GITHUB_USERNAME)" --password-stdin
273276

0 commit comments

Comments
 (0)