Skip to content

Commit

Permalink
ci: use actions/cache for layer caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mickamy committed Jan 7, 2024
1 parent 101bff8 commit 20b7ee3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
31 changes: 24 additions & 7 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,44 @@ 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
with:
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
with:
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
Expand All @@ -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
41 changes: 37 additions & 4 deletions .github/workflows/build_and_push_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 20b7ee3

Please sign in to comment.