From 0912ece617d8b2ecc587506675970c267bdbe8d5 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 18 Apr 2021 19:31:19 +0900 Subject: [PATCH 1/7] build: Specify cache-from and -to --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91eef1bc..a647911e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,11 @@ jobs: - name: Build uses: docker/build-push-action@v2 with: - cache-to: type=inline + # This cache-from value is the default and just for documentation purpose. + cache-from: type=registry,ref=ghcr.io/femiwiki/mediawiki:latest + cache-to: | + type=inline + type=local,src=/tmp/.buildx-cache platforms: linux/amd64 load: true tags: | @@ -126,6 +130,9 @@ jobs: - name: Build and push uses: docker/build-push-action@v2 with: + cache-from: | + type=registry,ref=ghcr.io/femiwiki/mediawiki:latest + type=local,src=/tmp/.buildx-cache cache-to: type=inline platforms: linux/amd64,linux/arm64 push: ${{ github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' }} From 0b6bcf9e0efa57e88d40cc8c7c4114fb5fb21b34 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 18 Apr 2021 19:33:11 +0900 Subject: [PATCH 2/7] Fix 'local cache exporter requires dest' --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a647911e..8983ac52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: cache-from: type=registry,ref=ghcr.io/femiwiki/mediawiki:latest cache-to: | type=inline - type=local,src=/tmp/.buildx-cache + type=local,dest=/tmp/.buildx-cache platforms: linux/amd64 load: true tags: | From 76d5cf9fcef319b688e474a6016dd304972c6ddb Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 18 Apr 2021 20:19:39 +0900 Subject: [PATCH 3/7] Make builds use the cache as much as possible --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8983ac52..6ce32fd5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,21 +64,29 @@ jobs: - run: echo "::set-output name=version::$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)" id: version - # Build amd64 only for testing, do not push. - - name: Build + # Pull cache from registry and save to local + # Due to specifying multiple cache exports is not supported by buildx currently + # https://github.com/moby/buildkit/blob/9065b18b/control/control.go#L253 + - name: Build and local cache + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64,linux/arm64 + cache-from: type=registry,ref=ghcr.io/femiwiki/mediawiki:cache + cache-to: mode=max,type=local,dest=/tmp/.buildx-cache + load: false + push: false + tags: ghcr.io/femiwiki/mediawiki:cache + + # Build amd64 only for testing, without pushing. + - name: Build a test image uses: docker/build-push-action@v2 with: - # This cache-from value is the default and just for documentation purpose. - cache-from: type=registry,ref=ghcr.io/femiwiki/mediawiki:latest - cache-to: | - type=inline - type=local,dest=/tmp/.buildx-cache platforms: linux/amd64 + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: mode=max,type=local,dest=/tmp/.buildx-cache-amd64 load: true - tags: | - ghcr.io/femiwiki/mediawiki:latest - ghcr.io/femiwiki/mediawiki:docker-test - ghcr.io/femiwiki/mediawiki:${{ steps.version.outputs.version }} + push: false + tags: ghcr.io/femiwiki/mediawiki:docker-test - name: Initialize docker swarm and start services run: | @@ -130,12 +138,14 @@ jobs: - name: Build and push uses: docker/build-push-action@v2 with: + platforms: linux/amd64,linux/arm64 cache-from: | - type=registry,ref=ghcr.io/femiwiki/mediawiki:latest type=local,src=/tmp/.buildx-cache - cache-to: type=inline - platforms: linux/amd64,linux/arm64 + type=local,src=/tmp/.buildx-cache-amd64 + cache-to: mode=max,type=inline + load: false push: ${{ github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' }} tags: | ghcr.io/femiwiki/mediawiki:latest + ghcr.io/femiwiki/mediawiki:cache ghcr.io/femiwiki/mediawiki:${{ steps.version.outputs.version }} From b9d098aefb95d0747342a013056e9d0149dddc1c Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 18 Apr 2021 20:22:28 +0900 Subject: [PATCH 4/7] Use latest as cache too --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ce32fd5..046c772c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,7 +71,9 @@ jobs: uses: docker/build-push-action@v2 with: platforms: linux/amd64,linux/arm64 - cache-from: type=registry,ref=ghcr.io/femiwiki/mediawiki:cache + cache-from: | + ghcr.io/femiwiki/mediawiki:latest + ghcr.io/femiwiki/mediawiki:cache cache-to: mode=max,type=local,dest=/tmp/.buildx-cache load: false push: false From 304f095f6183beb0ea00037c35b4fdac3aab74f3 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 18 Apr 2021 20:41:16 +0900 Subject: [PATCH 5/7] build: Reduce a step --- .github/workflows/ci.yml | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 046c772c..c7f88e82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,28 +64,14 @@ jobs: - run: echo "::set-output name=version::$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)" id: version - # Pull cache from registry and save to local - # Due to specifying multiple cache exports is not supported by buildx currently - # https://github.com/moby/buildkit/blob/9065b18b/control/control.go#L253 - - name: Build and local cache + # Build and save the cache to local + - name: Build a test image on amd64 uses: docker/build-push-action@v2 with: - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 cache-from: | ghcr.io/femiwiki/mediawiki:latest - ghcr.io/femiwiki/mediawiki:cache cache-to: mode=max,type=local,dest=/tmp/.buildx-cache - load: false - push: false - tags: ghcr.io/femiwiki/mediawiki:cache - - # Build amd64 only for testing, without pushing. - - name: Build a test image - uses: docker/build-push-action@v2 - with: - platforms: linux/amd64 - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: mode=max,type=local,dest=/tmp/.buildx-cache-amd64 load: true push: false tags: ghcr.io/femiwiki/mediawiki:docker-test @@ -137,17 +123,16 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push + - name: Build a multi-platform docker image and push uses: docker/build-push-action@v2 with: platforms: linux/amd64,linux/arm64 cache-from: | + ghcr.io/femiwiki/mediawiki:latest type=local,src=/tmp/.buildx-cache - type=local,src=/tmp/.buildx-cache-amd64 cache-to: mode=max,type=inline load: false push: ${{ github.repository_owner == 'femiwiki' && github.ref == 'refs/heads/main' }} tags: | ghcr.io/femiwiki/mediawiki:latest - ghcr.io/femiwiki/mediawiki:cache ghcr.io/femiwiki/mediawiki:${{ steps.version.outputs.version }} From 1ca5cdea892ae896f9aea72256bf572cf08e8fe7 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 18 Apr 2021 20:46:01 +0900 Subject: [PATCH 6/7] Cleanup --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7f88e82..81d963fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,8 +69,7 @@ jobs: uses: docker/build-push-action@v2 with: platforms: linux/amd64 - cache-from: | - ghcr.io/femiwiki/mediawiki:latest + cache-from: ghcr.io/femiwiki/mediawiki:latest cache-to: mode=max,type=local,dest=/tmp/.buildx-cache load: true push: false From 47abeca162f585ed549d2345e160657da953a269 Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sun, 18 Apr 2021 20:46:30 +0900 Subject: [PATCH 7/7] Cleanup --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81d963fa..1300aae1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,8 +64,7 @@ jobs: - run: echo "::set-output name=version::$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)" id: version - # Build and save the cache to local - - name: Build a test image on amd64 + - name: Build a test image on amd64 and cache uses: docker/build-push-action@v2 with: platforms: linux/amd64