From 01694459d66460dc094010d9e413d1e26cf1ce60 Mon Sep 17 00:00:00 2001 From: Hidetake Iwata Date: Fri, 26 Mar 2021 16:47:48 +0900 Subject: [PATCH] Use buildx multi-stage cache (#33) * Use buildx cache * Update Makefile * Use GITHUB_TOKEN --- .github/workflows/docker.yaml | 8 +++++++- Makefile | 9 ++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 29006cd..c09f0fa 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -27,11 +27,17 @@ jobs: - uses: actions/checkout@v2 - uses: docker/setup-qemu-action@v1 - uses: docker/setup-buildx-action@v1 + - uses: actions/cache@v2 + with: + path: /tmp/buildx + key: buildx-${{ runner.os }}-${{ github.sha }} + restore-keys: | + buildx-${{ runner.os }}- - uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.repository_owner }} - password: ${{ secrets.CR_PAT }} + password: ${{ secrets.GITHUB_TOKEN }} - run: make docker-build if: github.event_name == 'pull_request' - run: make docker-build-push diff --git a/Makefile b/Makefile index cbd2497..8f14ebf 100644 --- a/Makefile +++ b/Makefile @@ -41,16 +41,19 @@ DOCKER_REPOSITORY := ghcr.io/int128/slack-docker .PHONY: docker-build docker-build: Dockerfile docker buildx build . \ - --cache-from=type=registry,ref=$(DOCKER_REPOSITORY):latest \ + --output=type=image,push=false \ + --cache-from=type=local,src=/tmp/buildx \ + --cache-to=type=local,mode=max,dest=/tmp/buildx.new \ --platform=linux/amd64,linux/arm64 + rm -fr /tmp/buildx + mv /tmp/buildx.new /tmp/buildx .PHONY: docker-build-push docker-build-push: Dockerfile docker buildx build . \ --build-arg=VERSION=$(VERSION) \ --tag=$(DOCKER_REPOSITORY):$(VERSION) \ - --cache-from=type=registry,ref=$(DOCKER_REPOSITORY):latest \ - --cache-to=type=inline \ + --cache-from=type=local,src=/tmp/buildx \ --platform=linux/amd64,linux/arm64 \ --push