Skip to content

Commit e6d53e0

Browse files
committed
fixup! fixup! Cache Docker images on GitHub container registry
1 parent d37a5f9 commit e6d53e0

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ jobs:
2828
registry: ghcr.io
2929
username: ${{ github.actor }}
3030
password: ${{ secrets.GITHUB_TOKEN }}
31+
- name: Extract metadata (tags, labels) for Docker
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3136
- name: Build AppImage in Docker
3237
run: bash -ex ci/build-in-docker.sh
38+
env:
39+
DOCKER_TAG: ${{ steps.meta.outputs.tags[0] }}
3340
- name: Archive artifacts
3441
uses: actions/upload-artifact@v4
3542
with:

ci/build-in-docker.sh

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

34-
image=ghcr.io/appimage/appimageupdate-build
35-
cache_image="${image}-cache"
34+
# use docker image tag provided by GitHub actions if possible
35+
DOCKER_TAG="${DOCKER_TAG:-ghcr.io/appimage/appimageupdate-build:local-build}"
3636

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
37+
default_branch_tag="${echo "$DOCKER_TAG" | cut -d: -f1):$(echo "$GITHUB_DEFAULT_BRANCH" | rev | cut -d/ -f1 | rev)"
5038
5139
# building local image to "cache" installed dependencies for subsequent builds
5240
docker build \
53-
--cache-from "type=registry,ref=$cache_image" \
41+
--cache-to inline \
42+
--cache-from "type=registry,ref=${DOCKER_TAG}" \
43+
--cache-from "type=registry,ref=${default_branch_tag}" \
5444
--platform "$docker_platform" \
55-
-t "$image" \
45+
-t "$DOCKER_TAG" \
5646
--build-arg ARCH="$ARCH" \
5747
--build-arg CMAKE_ARCH="$CMAKE_ARCH" \
5848
"$repo_root"/ci

0 commit comments

Comments
 (0)