From 51075fe59e39f911097fc387905c2499ac085295 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 25 Dec 2024 16:51:27 +0100 Subject: [PATCH 1/8] Cache Docker images on GitHub container registry --- .github/workflows/main.yml | 6 ++++++ ci/build-in-docker.sh | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b80bd0f..a143834 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,6 +20,12 @@ jobs: submodules: recursive - name: Set up QEMU integration for Docker run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build AppImage in Docker run: bash -ex ci/build-in-docker.sh - name: Archive artifacts diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index 5ce8d9f..a93dafa 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -31,11 +31,26 @@ CMAKE_ARCH="${CMAKE_ARCH:-"$ARCH"}" cwd="$PWD" repo_root="$(readlink -f "$(dirname "$0")"/..)" -# needed to keep user ID in and outside Docker in sync to be able to write to workspace directory -image=appimageupdate-build +image=ghcr.io/appimage/appimageupdate-build +cache_image="${image}-cache" + +# push only on default branch +if [[ "${GITHUB_ACTIONS:-}" ]]; then + echo "Building on GitHub actions, checking if on default branch" + if [[ "refs/heads/${GITHUB_HEAD_REF}" == "${GITHUB_DEFAULT_BRANCH}" ]]; then + echo "Building on default branch, pushing to cache" + cache_build_args+=( + --cache-to type="registry,ref=$cache_image" + --push + ) + fi +else + echo "Not building on GitHub actions, not publishing cache" +fi # building local image to "cache" installed dependencies for subsequent builds docker build \ + --cache-from "type=registry,ref=$cache_image" \ --platform "$docker_platform" \ -t "$image" \ --build-arg ARCH="$ARCH" \ From d37a5f903cadcee65c16b10c9489f93655835475 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 25 Dec 2024 17:01:55 +0100 Subject: [PATCH 2/8] fixup! Cache Docker images on GitHub container registry --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a143834..cf6606d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,8 @@ jobs: env: ARCH: ${{ matrix.ARCH }} DIST: bionic + # not provided by GitHub by default + GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} steps: - uses: actions/checkout@v4 with: From e6d53e07894ac7712dab87c0eb4180604ad25a60 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 25 Dec 2024 20:09:28 +0100 Subject: [PATCH 3/8] fixup! fixup! Cache Docker images on GitHub container registry --- .github/workflows/main.yml | 7 +++++++ ci/build-in-docker.sh | 24 +++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cf6606d..e06ab32 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,8 +28,15 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Build AppImage in Docker run: bash -ex ci/build-in-docker.sh + env: + DOCKER_TAG: ${{ steps.meta.outputs.tags[0] }} - name: Archive artifacts uses: actions/upload-artifact@v4 with: diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index a93dafa..e00bd9b 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -31,28 +31,18 @@ CMAKE_ARCH="${CMAKE_ARCH:-"$ARCH"}" cwd="$PWD" repo_root="$(readlink -f "$(dirname "$0")"/..)" -image=ghcr.io/appimage/appimageupdate-build -cache_image="${image}-cache" +# use docker image tag provided by GitHub actions if possible +DOCKER_TAG="${DOCKER_TAG:-ghcr.io/appimage/appimageupdate-build:local-build}" -# push only on default branch -if [[ "${GITHUB_ACTIONS:-}" ]]; then - echo "Building on GitHub actions, checking if on default branch" - if [[ "refs/heads/${GITHUB_HEAD_REF}" == "${GITHUB_DEFAULT_BRANCH}" ]]; then - echo "Building on default branch, pushing to cache" - cache_build_args+=( - --cache-to type="registry,ref=$cache_image" - --push - ) - fi -else - echo "Not building on GitHub actions, not publishing cache" -fi +default_branch_tag="${echo "$DOCKER_TAG" | cut -d: -f1):$(echo "$GITHUB_DEFAULT_BRANCH" | rev | cut -d/ -f1 | rev)" # building local image to "cache" installed dependencies for subsequent builds docker build \ - --cache-from "type=registry,ref=$cache_image" \ + --cache-to inline \ + --cache-from "type=registry,ref=${DOCKER_TAG}" \ + --cache-from "type=registry,ref=${default_branch_tag}" \ --platform "$docker_platform" \ - -t "$image" \ + -t "$DOCKER_TAG" \ --build-arg ARCH="$ARCH" \ --build-arg CMAKE_ARCH="$CMAKE_ARCH" \ "$repo_root"/ci From 5408b1fde5d87740168ebe9fad3b9a4692c15f2a Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 25 Dec 2024 20:10:24 +0100 Subject: [PATCH 4/8] fixup! fixup! fixup! Cache Docker images on GitHub container registry --- ci/build-in-docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index e00bd9b..df624a8 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -34,7 +34,7 @@ repo_root="$(readlink -f "$(dirname "$0")"/..)" # use docker image tag provided by GitHub actions if possible DOCKER_TAG="${DOCKER_TAG:-ghcr.io/appimage/appimageupdate-build:local-build}" -default_branch_tag="${echo "$DOCKER_TAG" | cut -d: -f1):$(echo "$GITHUB_DEFAULT_BRANCH" | rev | cut -d/ -f1 | rev)" +default_branch_tag="$(echo "$DOCKER_TAG" | cut -d: -f1):$(echo "$GITHUB_DEFAULT_BRANCH" | rev | cut -d/ -f1 | rev)" # building local image to "cache" installed dependencies for subsequent builds docker build \ @@ -68,5 +68,5 @@ docker run \ -v "$cwd":/out \ -w /out \ --user "$uid" \ - "$image" \ + "$DOCKER_TAG" \ bash /ws/ci/build-appimages.sh From 634ada333328fe5823d92b890454275946fe20c7 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Wed, 25 Dec 2024 20:15:05 +0100 Subject: [PATCH 5/8] fixup! fixup! fixup! fixup! Cache Docker images on GitHub container registry --- ci/build-in-docker.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index df624a8..12774b8 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -34,11 +34,23 @@ repo_root="$(readlink -f "$(dirname "$0")"/..)" # use docker image tag provided by GitHub actions if possible DOCKER_TAG="${DOCKER_TAG:-ghcr.io/appimage/appimageupdate-build:local-build}" -default_branch_tag="$(echo "$DOCKER_TAG" | cut -d: -f1):$(echo "$GITHUB_DEFAULT_BRANCH" | rev | cut -d/ -f1 | rev)" +default_branch_tag="$(echo "$DOCKER_TAG" | cut -d: -f1):$(echo "${GITHUB_DEFAULT_BRANCH:-main}" | rev | cut -d/ -f1 | rev)" + +extra_build_args=() + +if [[ "${GITHUB_ACTIONS:-}" != "" ]]; then + echo "Building on GitHub actions, pushing cache" + extra_build_args+=( + --output "type=registry,ref=${DOCKER_TAG}" + --push + ) +else + echo "Local build, not pushing cache" +fi # building local image to "cache" installed dependencies for subsequent builds -docker build \ - --cache-to inline \ +docker buildx build \ + "${extra_build_args[@]}" \ --cache-from "type=registry,ref=${DOCKER_TAG}" \ --cache-from "type=registry,ref=${default_branch_tag}" \ --platform "$docker_platform" \ From 0f42b1752c573817fd275fb7c7c40c0640c819da Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 26 Dec 2024 01:29:27 +0100 Subject: [PATCH 6/8] fixup! fixup! fixup! fixup! fixup! Cache Docker images on GitHub container registry --- .github/workflows/main.yml | 2 -- ci/build-in-docker.sh | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e06ab32..2239950 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,8 +35,6 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - name: Build AppImage in Docker run: bash -ex ci/build-in-docker.sh - env: - DOCKER_TAG: ${{ steps.meta.outputs.tags[0] }} - name: Archive artifacts uses: actions/upload-artifact@v4 with: diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index 12774b8..be4d5e4 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -32,16 +32,16 @@ cwd="$PWD" repo_root="$(readlink -f "$(dirname "$0")"/..)" # use docker image tag provided by GitHub actions if possible -DOCKER_TAG="${DOCKER_TAG:-ghcr.io/appimage/appimageupdate-build:local-build}" +docker_tag="ghcr.io/appimagecommunity/appimageupdate-build:$(cut -d: -f2- <<<"${DOCKER_METADATA_OUTPUT_TAGS:-:local-build}")" -default_branch_tag="$(echo "$DOCKER_TAG" | cut -d: -f1):$(echo "${GITHUB_DEFAULT_BRANCH:-main}" | rev | cut -d/ -f1 | rev)" +default_branch_tag="$(cut -d: -f1 <<<"$docker_tag"):$(echo "${GITHUB_DEFAULT_BRANCH:-main}" | rev | cut -d/ -f1 | rev)" extra_build_args=() if [[ "${GITHUB_ACTIONS:-}" != "" ]]; then echo "Building on GitHub actions, pushing cache" extra_build_args+=( - --output "type=registry,ref=${DOCKER_TAG}" + --output "type=registry,ref=${docker_tag}" --push ) else @@ -51,10 +51,10 @@ fi # building local image to "cache" installed dependencies for subsequent builds docker buildx build \ "${extra_build_args[@]}" \ - --cache-from "type=registry,ref=${DOCKER_TAG}" \ + --cache-from "type=registry,ref=${docker_tag}" \ --cache-from "type=registry,ref=${default_branch_tag}" \ --platform "$docker_platform" \ - -t "$DOCKER_TAG" \ + -t "$docker_tag" \ --build-arg ARCH="$ARCH" \ --build-arg CMAKE_ARCH="$CMAKE_ARCH" \ "$repo_root"/ci @@ -80,5 +80,5 @@ docker run \ -v "$cwd":/out \ -w /out \ --user "$uid" \ - "$DOCKER_TAG" \ + "$docker_tag" \ bash /ws/ci/build-appimages.sh From dbbd26cb23e39d63d31762e483d9558b9bf39e3f Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 26 Dec 2024 01:43:27 +0100 Subject: [PATCH 7/8] fixup! fixup! fixup! fixup! fixup! fixup! Cache Docker images on GitHub container registry --- ci/build-in-docker.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index be4d5e4..3653250 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -50,10 +50,10 @@ fi # building local image to "cache" installed dependencies for subsequent builds docker buildx build \ + --platform "$docker_platform" \ "${extra_build_args[@]}" \ --cache-from "type=registry,ref=${docker_tag}" \ --cache-from "type=registry,ref=${default_branch_tag}" \ - --platform "$docker_platform" \ -t "$docker_tag" \ --build-arg ARCH="$ARCH" \ --build-arg CMAKE_ARCH="$CMAKE_ARCH" \ @@ -71,6 +71,7 @@ if [ -t 0 ]; then tty_args+=("-t"); fi # of course, this only works reliably if you don't run this script from that directory # but it's still not the worst idea to do so docker run \ + --platform "$docker_platform" \ --rm \ -i \ "${tty_args[@]}" \ From 0745eeb21a2b729790bcbd1a62106a8ee469f5b1 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Thu, 26 Dec 2024 01:55:09 +0100 Subject: [PATCH 8/8] fixup! fixup! fixup! fixup! fixup! fixup! fixup! Cache Docker images on GitHub container registry --- ci/build-in-docker.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index 3653250..a292b75 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -39,13 +39,12 @@ default_branch_tag="$(cut -d: -f1 <<<"$docker_tag"):$(echo "${GITHUB_DEFAULT_BRA extra_build_args=() if [[ "${GITHUB_ACTIONS:-}" != "" ]]; then - echo "Building on GitHub actions, pushing cache" + echo "Building on GitHub actions, storing cache on registry" extra_build_args+=( - --output "type=registry,ref=${docker_tag}" - --push + --cache-to "type=registry,ref=${docker_tag}" ) else - echo "Local build, not pushing cache" + echo "Local build, not storing cache on registry" fi # building local image to "cache" installed dependencies for subsequent builds