From f0d2438e8c147af5ab4f498069df2a7ed771c1f3 Mon Sep 17 00:00:00 2001 From: plowsof Date: Mon, 7 Oct 2024 21:48:16 +0100 Subject: [PATCH 1/2] build.yml: use cache for Docker build envs --- .github/workflows/build.yml | 101 ++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 709ebd05f7..17703d9fae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,21 +102,36 @@ jobs: - uses: actions/checkout@v1 with: submodules: recursive - - uses: satackey/action-docker-layer-caching@v0.0.11 - if: "!startsWith(github.ref, 'refs/tags/v')" - continue-on-error: true - with: - key: docker-linux-static-{hash} - restore-keys: | - docker-linux-static- - name: install dependencies run: sudo apt -y install xvfb libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xkb1 libxcb-shape0 libxkbcommon-x11-0 + - name: get Dockerfile.linux hash + id: dockerfile_linux_hash + run: echo "hash=$(sha256sum Dockerfile.linux | awk '{ print $1 }')" >> $GITHUB_OUTPUT + - uses: actions/cache@v4 + id: docker_cache + with: + path: /tmp/linux-docker-image + key: linux-docker-${{ steps.dockerfile_linux_hash.outputs.hash }} - name: free up diskspace run: ${{env.FREE_DISKSPACE}} + - name: load cached docker build env image + if: steps.docker_cache.outputs.cache-hit == 'true' + run: docker load -i /tmp/linux-docker-image/image.tar - name: prepare build environment - run: docker build --tag monero:build-env-linux --build-arg THREADS=3 --file Dockerfile.linux . + run: | + if [[ "$(docker images -q monero:build-env-linux 2> /dev/null)" == "" ]]; then + echo "Building new image..." + docker build --tag monero:build-env-linux --build-arg THREADS=4 --file Dockerfile.linux . + else + echo "Using cached image..." + fi + - name: save build env image to cache + if: steps.docker_cache.outputs.cache-hit != 'true' + run: | + mkdir -p /tmp/linux-docker-image + docker save monero:build-env-linux > /tmp/linux-docker-image/image.tar - name: build - run: docker run --rm -v /home/runner/work/monero-gui/monero-gui:/monero-gui -w /monero-gui monero:build-env-linux sh -c 'make release-static -j3' + run: docker run --rm -v /home/runner/work/monero-gui/monero-gui:/monero-gui -w /monero-gui monero:build-env-linux sh -c 'make release-static -j4' - name: sha256sum run: shasum -a256 /home/runner/work/monero-gui/monero-gui/build/release/bin/monero-wallet-gui - name: test qml @@ -134,19 +149,34 @@ jobs: - uses: actions/checkout@v1 with: submodules: recursive - - uses: satackey/action-docker-layer-caching@v0.0.11 - if: "!startsWith(github.ref, 'refs/tags/v')" - continue-on-error: true - with: - key: docker-windows-static-{hash} - restore-keys: | - docker-windows-static- + - name: get Dockerfile.windows hash + id: dockerfile_windows_hash + run: echo "hash=$(sha256sum Dockerfile.windows | awk '{ print $1 }')" >> $GITHUB_OUTPUT + - uses: actions/cache@v4 + id: docker_cache + with: + path: /tmp/windows-docker-image + key: windows-docker-${{ steps.dockerfile_windows_hash.outputs.hash }} - name: free up diskspace run: ${{env.FREE_DISKSPACE}} + - name: load cached docker build env image + if: steps.docker_cache.outputs.cache-hit == 'true' + run: docker load -i /tmp/windows-docker-image/image.tar - name: prepare build environment - run: docker build --tag monero:build-env-windows --build-arg THREADS=3 --file Dockerfile.windows . + run: | + if [[ "$(docker images -q monero:build-env-windows 2> /dev/null)" == "" ]]; then + echo "Building new image..." + docker build --tag monero:build-env-windows --build-arg THREADS=4 --file Dockerfile.windows . + else + echo "Using cached image..." + fi + - name: save build env image to cache + if: steps.docker_cache.outputs.cache-hit != 'true' + run: | + mkdir -p /tmp/windows-docker-image + docker save monero:build-env-windows > /tmp/windows-docker-image/image.tar - name: build - run: docker run --rm -v /home/runner/work/monero-gui/monero-gui:/monero-gui -w /monero-gui monero:build-env-windows sh -c 'make depends root=/depends target=x86_64-w64-mingw32 tag=win-x64 -j3' + run: docker run --rm -v /home/runner/work/monero-gui/monero-gui:/monero-gui -w /monero-gui monero:build-env-windows sh -c 'make depends root=/depends target=x86_64-w64-mingw32 tag=win-x64 -j4' - name: sha256sum run: shasum -a256 /home/runner/work/monero-gui/monero-gui/build/x86_64-w64-mingw32/release/bin/monero-wallet-gui.exe - uses: actions/upload-artifact@v4 @@ -162,19 +192,36 @@ jobs: - uses: actions/checkout@v1 with: submodules: recursive - - uses: satackey/action-docker-layer-caching@v0.0.11 - if: "!startsWith(github.ref, 'refs/tags/v')" - continue-on-error: true - with: - key: docker-android-static-{hash} - restore-keys: | - docker-android-static- + - name: get Dockerfile.android hash + id: dockerfile_android_hash + run: echo "hash=$(sha256sum Dockerfile.android | awk '{ print $1 }')" >> $GITHUB_OUTPUT + - uses: actions/cache@v4 + id: docker_cache + with: + path: /tmp/android-docker-image + key: android-docker-${{ steps.dockerfile_android_hash.outputs.hash }} - name: free up diskspace run: ${{env.FREE_DISKSPACE}} + - name: load cached docker build env image + if: steps.docker_cache.outputs.cache-hit == 'true' + run: docker load -i /tmp/android-docker-image/image.tar - name: prepare build environment - run: docker build --tag monero:build-env-android --build-arg THREADS=3 --file Dockerfile.android . + run: | + if [[ "$(docker images -q monero:build-env-android 2> /dev/null)" == "" ]]; then + echo "Building new image..." + docker build --tag monero:build-env-android --build-arg THREADS=4 --file Dockerfile.android . + else + echo "Using cached image..." + fi + - name: save build env image to cache + if: steps.docker_cache.outputs.cache-hit != 'true' + run: | + mkdir -p /tmp/android-docker-image + docker save monero:build-env-android > /tmp/android-docker-image/image.tar - name: build - run: docker run --rm -v /home/runner/work/monero-gui/monero-gui:/monero-gui -e THREADS=3 monero:build-env-android + run: docker run --rm -v /home/runner/work/monero-gui/monero-gui:/monero-gui -e THREADS=4 monero:build-env-android + - name: free up diskspace + run: ${{env.FREE_DISKSPACE}} - name: Remove obsolete docker layers run: docker images -a | grep none | awk '{ print $3; }' | xargs docker rmi || true - uses: actions/upload-artifact@v4 From e336bd0f7e103610bba4d43907f1bd32d70d37f5 Mon Sep 17 00:00:00 2001 From: plowsof Date: Wed, 9 Oct 2024 19:49:37 +0100 Subject: [PATCH 2/2] no cache on tag --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17703d9fae..a69988ac50 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -109,6 +109,7 @@ jobs: run: echo "hash=$(sha256sum Dockerfile.linux | awk '{ print $1 }')" >> $GITHUB_OUTPUT - uses: actions/cache@v4 id: docker_cache + if: "!startsWith(github.ref, 'refs/tags/v')" with: path: /tmp/linux-docker-image key: linux-docker-${{ steps.dockerfile_linux_hash.outputs.hash }} @@ -154,6 +155,7 @@ jobs: run: echo "hash=$(sha256sum Dockerfile.windows | awk '{ print $1 }')" >> $GITHUB_OUTPUT - uses: actions/cache@v4 id: docker_cache + if: "!startsWith(github.ref, 'refs/tags/v')" with: path: /tmp/windows-docker-image key: windows-docker-${{ steps.dockerfile_windows_hash.outputs.hash }} @@ -197,6 +199,7 @@ jobs: run: echo "hash=$(sha256sum Dockerfile.android | awk '{ print $1 }')" >> $GITHUB_OUTPUT - uses: actions/cache@v4 id: docker_cache + if: "!startsWith(github.ref, 'refs/tags/v')" with: path: /tmp/android-docker-image key: android-docker-${{ steps.dockerfile_android_hash.outputs.hash }}