Skip to content

Commit 51075fe

Browse files
committed
Cache Docker images on GitHub container registry
1 parent 362e637 commit 51075fe

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
submodules: recursive
2121
- name: Set up QEMU integration for Docker
2222
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
23+
- name: Login to GitHub Container Registry
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
2329
- name: Build AppImage in Docker
2430
run: bash -ex ci/build-in-docker.sh
2531
- name: Archive artifacts

ci/build-in-docker.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,26 @@ CMAKE_ARCH="${CMAKE_ARCH:-"$ARCH"}"
3131
cwd="$PWD"
3232
repo_root="$(readlink -f "$(dirname "$0")"/..)"
3333

34-
# needed to keep user ID in and outside Docker in sync to be able to write to workspace directory
35-
image=appimageupdate-build
34+
image=ghcr.io/appimage/appimageupdate-build
35+
cache_image="${image}-cache"
36+
37+
# push only on default branch
38+
if [[ "${GITHUB_ACTIONS:-}" ]]; then
39+
echo "Building on GitHub actions, checking if on default branch"
40+
if [[ "refs/heads/${GITHUB_HEAD_REF}" == "${GITHUB_DEFAULT_BRANCH}" ]]; then
41+
echo "Building on default branch, pushing to cache"
42+
cache_build_args+=(
43+
--cache-to type="registry,ref=$cache_image"
44+
--push
45+
)
46+
fi
47+
else
48+
echo "Not building on GitHub actions, not publishing cache"
49+
fi
3650

3751
# building local image to "cache" installed dependencies for subsequent builds
3852
docker build \
53+
--cache-from "type=registry,ref=$cache_image" \
3954
--platform "$docker_platform" \
4055
-t "$image" \
4156
--build-arg ARCH="$ARCH" \

0 commit comments

Comments
 (0)