Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

Commit 6f8fddd

Browse files
author
Shawn Reuland
committed
#92: use gha caches for docker build layer caching
1 parent f396c7a commit 6f8fddd

2 files changed

Lines changed: 35 additions & 70 deletions

File tree

.github/workflows/test-workflow.yml

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ name: Systems test workflow, next gen, uses quickstart pipelines
22

33
on:
44
workflow_call:
5-
secrets:
6-
DOCKERHUB_USERNAME:
7-
required: false
8-
DOCKERHUB_TOKEN:
9-
required: false
105
inputs:
116
runner:
127
description: "GitHub runner to use"
@@ -123,25 +118,14 @@ on:
123118

124119
env:
125120
SYSTEM_TEST_IMAGE: stellar/system-test:cache
126-
SYSTEM_TEST_IMAGE_CACHE_REGISTRY: docker.io
127-
121+
128122
jobs:
129123
prepare-config:
130124
runs-on: ubuntu-latest
131125
outputs:
132126
images-config: ${{ steps.set-config.outputs.images }}
133-
system-test-image-cache-registry: ${{ env.SYSTEM_TEST_IMAGE_CACHE_REGISTRY }}
134127
system-test-image-cached: "${{ env.SYSTEM_TEST_IMAGE}}_${{ steps.set-cache-key.outputs.cache-key }}"
135-
registry_allowed: ${{ steps.check-registry.outputs.registry-allowed }}
136128
steps:
137-
- id: check-registry
138-
name: Check if registry access is allowed
139-
run: |
140-
if [ -z "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
141-
echo "registry-allowed=false" >> $GITHUB_OUTPUT
142-
else
143-
echo "registry-allowed=true" >> $GITHUB_OUTPUT
144-
fi
145129
- id: set-cache-key
146130
run: |
147131
# Fetch commit SHAs for each dependency repo
@@ -216,27 +200,9 @@ jobs:
216200
images: ${{ needs.prepare-config.outputs.images-config }}
217201
archs: '["amd64"]'
218202

219-
check-system-test-cache:
220-
runs-on: ubuntu-latest
221-
needs: prepare-config
222-
outputs:
223-
cache-hit: ${{ steps.check.outputs.exists }}
224-
steps:
225-
- id: check
226-
name: Check if cached system-test image exists
227-
run: |
228-
if docker manifest inspect ${{ needs.prepare-config.outputs.system-test-image-cache-registry }}/${{ needs.prepare-config.outputs.system-test-image-cached }} > /dev/null 2>&1; then
229-
echo "Image exists in registry"
230-
echo "exists=true" >> $GITHUB_OUTPUT
231-
else
232-
echo "Image not found in registry"
233-
echo "exists=false" >> $GITHUB_OUTPUT
234-
fi
235-
236203
build-system-test:
237204
runs-on: ubuntu-latest-4-cores
238-
needs: [prepare-config, check-system-test-cache]
239-
if: needs.check-system-test-cache.outputs.cache-hit != 'true'
205+
needs: [prepare-config]
240206
env:
241207
SYSTEM_TEST_IMAGE: ${{ needs.prepare-config.outputs.system-test-image-cached }}
242208
steps:
@@ -275,34 +241,20 @@ jobs:
275241
fi
276242
277243
make \
244+
USE_GHA_CACHE=true \
278245
STELLAR_CLI_GIT_REF=$STELLAR_CLI_GIT_REF \
279246
STELLAR_CLI_CRATE_VERSION=$STELLAR_CLI_CRATE_VERSION \
280247
RUST_TOOLCHAIN_VERSION=${{ inputs.rust-toolchain-version }} \
281248
JS_STELLAR_SDK_NPM_VERSION=$JS_STELLAR_SDK_REF \
282249
SYSTEM_TEST_IMAGE=$SYSTEM_TEST_IMAGE \
283250
build
284-
- name: login to registry
285-
if: needs.prepare-config.outputs.registry_allowed == 'true'
286-
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
287-
with:
288-
registry: ${{ needs.prepare-config.outputs.system-test-image-cache-registry }}
289-
username: ${{ secrets.DOCKERHUB_USERNAME }}
290-
password: ${{ secrets.DOCKERHUB_TOKEN }}
291-
- name: Publish system-test image
292-
if: needs.prepare-config.outputs.registry_allowed == 'true'
293-
run: |
294-
docker tag $SYSTEM_TEST_IMAGE ${{ needs.prepare-config.outputs.system-test-image-cache-registry }}/$SYSTEM_TEST_IMAGE
295-
docker push ${{ needs.prepare-config.outputs.system-test-image-cache-registry }}/$SYSTEM_TEST_IMAGE
296-
297-
- name: extract image to artifact when no registry
298-
if: needs.prepare-config.outputs.registry_allowed != 'true'
251+
- name: extract image to file
299252
run: |
300253
docker save $SYSTEM_TEST_IMAGE -o /tmp/image.tar
301-
- name: save to artifact when no registry
302-
if: needs.prepare-config.outputs.registry_allowed != 'true'
303-
uses: actions/upload-artifact@v4
254+
- name: save file to cache
255+
uses: actions/cache@v4
304256
with:
305-
name: image-system-test
257+
key: ${{ env.SYSTEM_TEST_IMAGE }}
306258
path: /tmp/image.tar
307259

308260
integration:
@@ -324,21 +276,19 @@ jobs:
324276
artifact: image-quickstart-rpc-custom-amd64.tar
325277
tag: rpc-custom-amd64
326278
enable: core,rpc
327-
- name: download system-test image
328-
if: needs.build-system-test.result == 'skipped'
329-
run: |
330-
docker pull ${{ needs.prepare-config.outputs.system-test-image-cache-registry }}/$SYSTEM_TEST_IMAGE
331-
docker tag ${{ needs.prepare-config.outputs.system-test-image-cache-registry }}/$SYSTEM_TEST_IMAGE $SYSTEM_TEST_IMAGE
332-
333-
- name: download artifact if no registry
334-
if: needs.build-system-test.result != 'skipped' && needs.prepare-config.outputs.registry_allowed != 'true'
335-
uses: actions/download-artifact@v4
279+
- name: Get system-test image from cache
280+
id: get-system-test-image
281+
uses: actions/cache/restore/v4
336282
with:
337-
name: image-system-test
338-
path: /tmp/
339-
340-
- name: load system-test image if no registry
341-
if: needs.build-system-test.result != 'skipped' && needs.prepare-config.outputs.registry_allowed != 'true'
283+
key: ${{ env.SYSTEM_TEST_IMAGE }}
284+
path: /tmp/image.tar
285+
- name: Fail if cache not found
286+
run: |
287+
if [ "${{ steps.get-system-test-image.outputs.cache-hit }}" != "true" ]; then
288+
echo "Required cache key $SYSTEM_TEST_IMAGE not found, failing job."
289+
exit 1
290+
fi
291+
- name: load system-test image from cache file
342292
run: |
343293
docker load -i /tmp/image.tar
344294

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,27 @@ RUST_TOOLCHAIN_VERSION=stable
3737
# the final image name that is created in local docker images store for system test
3838
SYSTEM_TEST_IMAGE=stellar/system-test:dev
3939

40+
# set to true to enable github actions cache for layer caching during build
41+
USE_GHA_CACHE=false
42+
43+
# github actions cache arguments for docker build
44+
GHA_CACHE_ARGS=--cache-from=type=gha --cache-to=type=gha,mode=max,compression=zstd
45+
46+
# set cache args based on USE_GHA_CACHE flag
47+
ifeq ($(USE_GHA_CACHE),true)
48+
CACHE_ARGS=$(GHA_CACHE_ARGS)
49+
else
50+
CACHE_ARGS=
51+
endif
52+
4053
build-stellar-cli:
4154
if [ -z "$(STELLAR_CLI_IMAGE)" ]; then \
4255
DOCKERHUB_RUST_VERSION=rust:$$( [ "$(RUST_TOOLCHAIN_VERSION)" = "stable" ] && echo "latest" || echo "$(RUST_TOOLCHAIN_VERSION)"); \
4356
docker buildx build -t "$(STELLAR_CLI_STAGE_IMAGE)" --target builder \
4457
--build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=true \
4558
--build-arg DOCKERHUB_RUST_VERSION="$$DOCKERHUB_RUST_VERSION" \
4659
--build-arg STELLAR_CLI_CRATE_VERSION="$(STELLAR_CLI_CRATE_VERSION)" \
60+
$(CACHE_ARGS) \
4761
-f- $(STELLAR_CLI_GIT_REF) < $(MAKEFILE_DIR)Dockerfile.stellar-cli; \
4862
fi
4963

@@ -56,4 +70,5 @@ build: build-stellar-cli
5670
--build-arg RUST_TOOLCHAIN_VERSION=$(RUST_TOOLCHAIN_VERSION) \
5771
--build-arg NODE_VERSION=$(NODE_VERSION) \
5872
--build-arg JS_STELLAR_SDK_NPM_VERSION=$(JS_STELLAR_SDK_NPM_VERSION) \
59-
--label org.opencontainers.image.revision="$(SYSTEM_TEST_SHA)" .;
73+
--label org.opencontainers.image.revision="$(SYSTEM_TEST_SHA)" \
74+
$(CACHE_ARGS) .;

0 commit comments

Comments
 (0)