diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b80bd0f..2239950 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,12 +14,25 @@ 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: 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: 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 - name: Archive artifacts diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index 5ce8d9f..a292b75 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -31,13 +31,29 @@ 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 +# use docker image tag provided by GitHub actions if possible +docker_tag="ghcr.io/appimagecommunity/appimageupdate-build:$(cut -d: -f2- <<<"${DOCKER_METADATA_OUTPUT_TAGS:-:local-build}")" + +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, storing cache on registry" + extra_build_args+=( + --cache-to "type=registry,ref=${docker_tag}" + ) +else + echo "Local build, not storing cache on registry" +fi # building local image to "cache" installed dependencies for subsequent builds -docker build \ +docker buildx build \ --platform "$docker_platform" \ - -t "$image" \ + "${extra_build_args[@]}" \ + --cache-from "type=registry,ref=${docker_tag}" \ + --cache-from "type=registry,ref=${default_branch_tag}" \ + -t "$docker_tag" \ --build-arg ARCH="$ARCH" \ --build-arg CMAKE_ARCH="$CMAKE_ARCH" \ "$repo_root"/ci @@ -54,6 +70,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[@]}" \ @@ -63,5 +80,5 @@ docker run \ -v "$cwd":/out \ -w /out \ --user "$uid" \ - "$image" \ + "$docker_tag" \ bash /ws/ci/build-appimages.sh