From 5b877ccd6ded45cc4dea3403d0ab5537446f2d70 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 | 28 +++++++++++---- .github/workflows/build_and_push_images.yml | 40 ++++++++++++++++++--- Makefile | 1 - 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index e64bcb7..b56a25a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -44,7 +44,13 @@ 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 }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- - name: Build and push bench image uses: docker/build-push-action@v5 with: @@ -53,7 +59,7 @@ jobs: file: ./docker/benchmarker/Dockerfile tags: ${{ env.UNAME }}/ishocon2-bench:${{ env.DATE }},ishocon2-bench:latest 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 +67,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 +77,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 +89,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 0d38da8..f7c697d 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,13 @@ 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-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- - run: make pull-app - name: Build and push app image uses: docker/build-push-action@v5 @@ -84,6 +106,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 aaff86d..fff72f5 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: