diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a2674df6..367782d6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,17 +15,20 @@ jobs: ARCH: [x86_64, i386, armhf, aarch64] BUILD_TYPE: ["appimage"] USE_STATIC_RUNTIME: [""] + DISABLE_PUSH: [""] include: # test build - ARCH: x86_64 DOCKER_ARCH: amd64 BUILD_TYPE: coverage + DISABLE_PUSH: 1 # experimental build - ARCH: x86_64 BUILD_TYPE: appimage USE_STATIC_RUNTIME: 1 + DISABLE_PUSH: 1 fail-fast: false @@ -48,8 +51,15 @@ jobs: - name: Set up QEMU integration for Docker run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + # needed for Docker buildx caching to GitHub actions cache + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build run: bash ci/build-in-docker.sh + env: + CACHE_FROM: 1 + PUSH_IMAGE: ${{ (matrix.DISABLE_PUSH == '' && github.event_name != 'pull_request') && '1' || '' }} - name: Archive artifacts uses: actions/upload-artifact@v2 diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index 322a0b59..7a25de57 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -59,18 +59,34 @@ fi image_tag="linuxdeploy-build:$ARCH" -docker build \ - --build-arg ARCH="$ARCH" \ - --build-arg docker_arch="$docker_arch" \ - "${build_args[@]}" \ - -t "$image_tag" \ - "$this_dir"/docker +docker_build_command=("docker" "build") + +if [[ "${GITHUB_ACTION:-}" != "" ]]; then + warning "using GitHub actions cache" + + build_args+=( + "--cache-from" "type=gha" + "--cache-to" "type=gha" + ) + + docker_build_command=("docker" "buildx" "build" "--load") +fi + +( + set -x + "${docker_build_command[@]}" \ + --build-arg ARCH="$ARCH" \ + --build-arg docker_arch="$docker_arch" \ + "${build_args[@]}" \ + -t "$image_tag" \ + "$this_dir"/docker +) docker_args=() # only if there's more than 1G of free space in RAM, we can build in a RAM disk if [[ "${GITHUB_ACTIONS:-}" != "" ]]; then warning "Building on GitHub actions, which does not support --tmpfs flag -> building on regular disk" -elif [[ "$(free -m | grep "Mem:" | awk '{print $4}')" -gt 1024 ]]; then +elif [[ "$(env LC_ALL=C free -m | grep "Mem:" | awk '{print $4}')" -gt 1024 ]]; then info "Host system has enough free memory -> building in RAM disk" docker_args+=( "--tmpfs" @@ -92,7 +108,6 @@ if [ -t 1 ]; then docker_args+=("-t") fi -DOCKER_OPTS=() # fix for https://stackoverflow.com/questions/51195528/rcc-error-in-resource-qrc-cannot-find-file-png if [ "${CI:-}" != "" ]; then docker_args+=( @@ -106,17 +121,20 @@ fi # b) allow the build scripts to "mv" the binaries into the /out directory uid="${UID:-"$(id -u)"}" info "Running build with uid $uid" -docker run \ - --rm \ - -i \ - -e GITHUB_RUN_NUMBER \ - -e ARCH \ - -e BUILD_TYPE \ - -e USE_STATIC_RUNTIME \ - -e CI \ - --user "$uid" \ - "${docker_args[@]}" \ - -v "$(readlink -f "$this_dir"/..):/ws" \ - -w /ws \ - "$image_tag" \ - bash -xc "$build_script" +( + set -x + docker run \ + --rm \ + -i \ + -e GITHUB_RUN_NUMBER \ + -e ARCH \ + -e BUILD_TYPE \ + -e USE_STATIC_RUNTIME \ + -e CI \ + --user "$uid" \ + "${docker_args[@]}" \ + -v "$(readlink -f "$this_dir"/..):/ws" \ + -w /ws \ + "$image_tag" \ + bash -xc "$build_script" +)