From a1f46060fa2be4787e7532a8284cd2079876f6f4 Mon Sep 17 00:00:00 2001 From: Greg Lin Date: Mon, 15 Aug 2022 18:14:43 -0500 Subject: [PATCH] Try local Docker image caching in GHA --- .github/workflows/test.yml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 565c63f..5f659e6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,12 +58,32 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: - driver: docker install: true + # Enable Docker layer caching without having to push to a registry. + # https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#local-cache + # This may eventually be migrated to the GitHub Actions cache backend, + # which is still considered experimental. + # https://github.com/moby/buildkit#github-actions-cache-experimental + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ matrix.platform }}-buildx-${{ github.sha }} + restore-keys: ${{ matrix.platform }}-buildx- + + # Use docker buildx instead of docker-compose here because cache exporting + # does not seem to work as of docker-compose v2.6.0 and buildx v0.8.2, even + # though it works with buildx individually. - name: Build R run: | for version in ${{ env.R_VERSIONS }}; do + docker buildx build -t r-builds:${{ matrix.platform }} \ + --file builder/Dockerfile.${{ matrix.platform }} \ + --cache-from "type=local,src=/tmp/.buildx-cache" \ + --cache-to "type=local,dest=/tmp/.buildx-cache-new,mode=max" \ + --load \ + builder R_VERSION=$version make build-r-${{ matrix.platform }} done @@ -72,3 +92,11 @@ jobs: for version in ${{ env.R_VERSIONS }}; do R_VERSION=$version make test-r-${{ matrix.platform }} done + + # Temporary workaround for unbounded GHA cache growth with the local cache mode. + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache