Skip to content

Commit 8027e2e

Browse files
authored
Merge pull request #71 from joshuanianji/improve-cache
Improve cache
2 parents 06eeac0 + 666cac5 commit 8027e2e

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

.github/actions/build-base-img/action.yml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ runs:
3333
- name: Get Latest Idris Commit SHA
3434
id: get-sha
3535
uses: ./.github/actions/get-idris-sha
36+
37+
# if platforms is not equal to linux/amd64, do not cache-to (output empty string)
38+
# See: https://github.com/joshuanianji/idris-2-docker/pull/71
39+
- name: Calculate cache-to
40+
id: calculate-cache-to
41+
run: |
42+
if [ "${{ inputs.platforms }}" == "linux/amd64" ]; then
43+
echo "cache-to=type=gha,mode=max,scope=build-base-${{ inputs.idris-version }}" >> $GITHUB_OUTPUT
44+
else
45+
echo "cache-to=" >> $GITHUB_OUTPUT
46+
fi
47+
shell: bash
3648

3749
- name: Build Base (versioned)
3850
uses: docker/build-push-action@v5
@@ -47,10 +59,13 @@ runs:
4759
load: ${{ inputs.load }}
4860
push: ${{ inputs.push }}
4961
labels: ${{ inputs.labels }}
50-
# When doing matrix builds, we need to scope the image
51-
# https://github.com/moby/buildkit/issues/2885
52-
cache-from: type=gha,scope=build-base-${{ inputs.idris-version }}
53-
cache-to: type=gha,mode=max,scope=build-base-${{ inputs.idris-version }}
62+
# Along with caching from gha, also cache from gh registry
63+
# the gha cache is limited to 10GB and I think i cause a lot of cache thrashing
64+
# when I also make PRs, it seems that the cache is not shared, so I'll need to look into this
65+
cache-from: |
66+
type=gha,scope=build-base-${{ inputs.idris-version }}
67+
type=registry,ref=ghcr.io/joshuanianji/idris-2-docker/base:${{ inputs.idris-version }}
68+
cache-to: ${{ steps.calculate-cache-to.outputs.cache-to }}
5469

5570
- name: Build Base (latest)
5671
uses: docker/build-push-action@v5
@@ -66,7 +81,7 @@ runs:
6681
load: ${{ inputs.load }}
6782
push: ${{ inputs.push }}
6883
labels: ${{ inputs.labels }}
69-
# When doing matrix builds, we need to scope the image
70-
# https://github.com/moby/buildkit/issues/2885
71-
cache-from: type=gha,scope=build-base-${{ inputs.idris-version }}
72-
cache-to: type=gha,mode=max,scope=build-base-${{ inputs.idris-version }}
84+
cache-from: |
85+
type=gha,scope=build-base-${{ inputs.idris-version }}
86+
type=registry,ref=ghcr.io/joshuanianji/idris-2-docker/base:${{ inputs.idris-version }}
87+
cache-to: ${{ steps.calculate-cache-to.outputs.cache-to }}

.github/actions/build-devcontainer-img/action.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ runs:
4141
id: get-sha
4242
uses: ./.github/actions/get-idris-sha
4343

44+
# if platforms is not equal to linux/amd64, do not cache-to (output empty string)
45+
# See: https://github.com/joshuanianji/idris-2-docker/pull/71
46+
- name: Calculate cache-to
47+
id: calculate-cache-to
48+
run: |
49+
if [ "${{ inputs.platforms }}" == "linux/amd64" ]; then
50+
echo "cache-to=type=gha,mode=max,scope=build-devcontainer-${{ inputs.idris-version }}" >> $GITHUB_OUTPUT
51+
else
52+
echo "cache-to=" >> $GITHUB_OUTPUT
53+
fi
54+
shell: bash
55+
4456
- name: Build Devcontainer (versioned)
4557
if: ${{ inputs.idris-lsp-version != 'latest' }}
4658
uses: docker/build-push-action@v5
@@ -56,8 +68,10 @@ runs:
5668
load: ${{ inputs.load }}
5769
push: ${{ inputs.push }}
5870
labels: ${{ inputs.labels }}
59-
cache-from: type=gha,scope=build-devcontainer-${{ inputs.idris-lsp-version }}
60-
cache-to: type=gha,mode=max,scope=build-devcontainer-${{ inputs.idris-lsp-version }}
71+
cache-from: |
72+
type=gha,scope=build-devcontainer-${{ inputs.idris-version }}
73+
type=registry,ref=ghcr.io/joshuanianji/idris-2-docker/devcontainer:${{ inputs.idris-version }}
74+
cache-to: ${{ steps.calculate-cache-to.outputs.cache-to }}
6175

6276
- name: Build Devcontainer (latest)
6377
if: ${{ inputs.idris-lsp-version == 'latest' }}
@@ -76,5 +90,7 @@ runs:
7690
load: ${{ inputs.load }}
7791
push: ${{ inputs.push }}
7892
labels: ${{ inputs.labels }}
79-
cache-from: type=gha,scope=build-devcontainer-${{ inputs.idris-lsp-version }}
80-
cache-to: type=gha,mode=max,scope=build-devcontainer-${{ inputs.idris-lsp-version }}
93+
cache-from: |
94+
type=gha,scope=build-devcontainer-${{ inputs.idris-version }}
95+
type=registry,ref=ghcr.io/joshuanianji/idris-2-docker/devcontainer:${{ inputs.idris-version }}
96+
cache-to: ${{ steps.calculate-cache-to.outputs.cache-to }}

.github/workflows/version-devcontainer-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
idris-lsp-version: ${{ inputs.idris-lsp-version }}
5959
idris-version: ${{ inputs.idris-version }}
6060
push: true
61-
tags: ghcr.io/${{ github.repository }}/base:${{ inputs.idris-lsp-version }}
61+
tags: ghcr.io/${{ github.repository }}/devcontainer:${{ inputs.idris-version }}
6262
labels: ${{ steps.create-meta.outputs.labels }}
6363
base-tag: ghcr.io/joshuanianji/idris-2-docker/base:${{ inputs.idris-version }}
6464
platforms: linux/arm64,linux/amd64

0 commit comments

Comments
 (0)