From 20b7ee3ceafa81d73880b1d01d11200007042d7e Mon Sep 17 00:00:00 2001 From: mickamy Date: Sun, 7 Jan 2024 17:53:31 +0900 Subject: [PATCH] ci: use actions/cache for layer caching --- .github/workflows/benchmark.yml | 31 ++++++++++++---- .github/workflows/build_and_push_images.yml | 41 +++++++++++++++++++-- Makefile | 1 - 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e64bcb77..5b0d4d03 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -44,16 +44,23 @@ jobs: with: username: ${{ env.UNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - - run: make pull + - name: Cache docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-${{ matrix.language }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-${{ matrix.language }} + ${{ runner.os }}-buildx - name: Build and push bench image uses: docker/build-push-action@v5 with: context: . push: true file: ./docker/benchmarker/Dockerfile - tags: ${{ env.UNAME }}/ishocon2-bench:${{ env.DATE }},ishocon2-bench:latest + tags: ${{ env.UNAME }}/ishocon2-bench:${{ env.DATE }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max platforms: linux/amd64,linux/arm64/v8 - name: Build and push base image uses: docker/build-push-action@v5 @@ -61,9 +68,9 @@ jobs: context: . push: true file: ./docker/app/base/Dockerfile - tags: ${{ env.UNAME }}/ishocon2-app-base:${{ env.DATE }},ishocon2-app-base:latest + tags: ${{ env.UNAME }}/ishocon2-app-base:${{ env.DATE }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max platforms: linux/amd64,linux/arm64/v8 - name: Build and push app image uses: docker/build-push-action@v5 @@ -71,9 +78,10 @@ jobs: context: . push: true file: ./docker/app/base/Dockerfile - tags: ${{ env.UNAME }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:${{ env.DATE }},ishocon2-app-${{ env.ISHOCON_APP_LANG }}:latest + tags: ${{ env.UNAME }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:${{ env.DATE }} + build-args: BASE_IMAGE=${{ env.UNAME }}/ishocon2-app-base:${{ env.DATE }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max platforms: linux/amd64,linux/arm64/v8 - run: make build timeout-minutes: 10 @@ -82,3 +90,12 @@ jobs: - name: Dump docker logs uses: jwalton/gh-docker-logs@v2 if: ${{ always() }} + - name: Move new cache to the place where to be cached + run: | + echo "Temporary fix for cleaning up old cache." + echo "See isssues: + - https://github.com/docker/build-push-action/issues/252 + - https://github.com/moby/buildkit/issues/1896 + " + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.github/workflows/build_and_push_images.yml b/.github/workflows/build_and_push_images.yml index 0d38da85..0db323dd 100644 --- a/.github/workflows/build_and_push_images.yml +++ b/.github/workflows/build_and_push_images.yml @@ -27,7 +27,13 @@ jobs: with: username: ${{ env.UNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - - run: make pull-bench pull-base + - name: Cache docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- - name: Build and push bench image uses: docker/build-push-action@v5 with: @@ -36,7 +42,7 @@ jobs: file: ./docker/benchmarker/Dockerfile tags: ${{ env.UNAME }}/ishocon2-bench:latest,${{ env.UNAME }}/ishocon2-bench:${{ env.DATE }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max platforms: linux/amd64,linux/arm64/v8 - name: Build and push base image uses: docker/build-push-action@v5 @@ -46,8 +52,17 @@ jobs: file: ./docker/app/base/Dockerfile tags: ${{ env.UNAME }}/ishocon2-app-base:latest,${{ env.UNAME }}/ishocon2-app-base:${{ env.DATE }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max platforms: linux/amd64,linux/arm64/v8 + - name: Move new cache to the place where to be cached + run: | + echo "Temporary fix for cleaning up old cache." + echo "See isssues: + - https://github.com/docker/build-push-action/issues/252 + - https://github.com/moby/buildkit/issues/1896 + " + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache build-app-images: name: Build app images runs-on: ubuntu-latest @@ -76,6 +91,14 @@ jobs: with: username: ${{ env.UNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Cache docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ matrix.language }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-${{ matrix.language }} + ${{ runner.os }}-buildx - run: make pull-app - name: Build and push app image uses: docker/build-push-action@v5 @@ -84,6 +107,16 @@ jobs: push: true file: ./docker/app/base/Dockerfile tags: ${{ env.UNAME }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:latest,${{ env.UNAME }}/ishocon2-app-${{ env.ISHOCON_APP_LANG }}:${{ env.DATE }} + build-args: BASE_IMAGE=${{ env.UNAME }}/ishocon2-app-base:${{ env.DATE }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max platforms: linux/amd64,linux/arm64/v8 + - name: Move new cache to the place where to be cached + run: | + echo "Temporary fix for cleaning up old cache." + echo "See isssues: + - https://github.com/docker/build-push-action/issues/252 + - https://github.com/moby/buildkit/issues/1896 + " + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/Makefile b/Makefile index aaff86dc..fff72f5b 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,6 @@ build-base: -f ./docker/app/base/Dockerfile \ -t $(LOCAL_ISHOCON_BASE_IMAGE) \ -t $(UNAME)/ishocon2-app-base:latest \ - -t $(UNAME)/ishocon2-app-base:${ARCH} \ .; build-bench: