@@ -54,6 +54,14 @@ inputs:
5454 description : " URL of the Bazel remote cache to use for building the image"
5555 required : true
5656 default : " "
57+ ENABLE_BAZEL_DISK_CACHE :
58+ description : " Enable Bazel disk cache via actions/cache"
59+ required : false
60+ default : " false"
61+ ENABLE_BAZEL_REPO_CACHE :
62+ description : " Enable Bazel repository cache via actions/cache"
63+ required : false
64+ default : " false"
5765
5866outputs :
5967 DOCKER_TAG_MEALKIT :
@@ -106,6 +114,32 @@ runs:
106114 mv version.py .github/container/nsys_jax/nsys_jax/
107115 cat .github/container/nsys_jax/nsys_jax/version.py
108116
117+ # BAZEL CACHE RESTORE
118+ - name : Restore Bazel disk cache
119+ if : inputs.ENABLE_BAZEL_DISK_CACHE == 'true'
120+ uses : actions/cache/restore@v4
121+ with :
122+ path : /tmp/bazel-disk-cache
123+ key : bazel-disk-cache-${{ inputs.ARCHITECTURE }}-${{ github.run_id }}
124+ restore-keys : |
125+ bazel-disk-cache-${{ inputs.ARCHITECTURE }}-
126+
127+ - name : Restore Bazel repo cache
128+ if : inputs.ENABLE_BAZEL_REPO_CACHE == 'true'
129+ uses : actions/cache/restore@v4
130+ with :
131+ path : /tmp/bazel-repo-cache
132+ key : bazel-repo-cache-${{ inputs.ARCHITECTURE }}-${{ github.run_id }}
133+ restore-keys : |
134+ bazel-repo-cache-${{ inputs.ARCHITECTURE }}-
135+
136+ # Always create the seed dirs so --build-context is always valid (no-op if empty)
137+ - name : Prepare Bazel cache seed directories
138+ shell : bash
139+ run : |
140+ mkdir -p /tmp/bazel-disk-cache
141+ mkdir -p /tmp/bazel-repo-cache
142+
109143 # MEALKIT BUILD
110144 - name : Set docker metadata - mealkit
111145 id : mealkit-metadata
@@ -134,6 +168,8 @@ runs:
134168 ssh : default
135169 secret-files : |
136170 "SSH_KNOWN_HOSTS=${{ steps.setup-ssh.outputs.known-hosts-file }}"
171+ build-contexts : |
172+ bazel-disk-seed=/tmp/bazel-disk-cache
137173 build-args : |
138174 BASE_IMAGE=${{ inputs.BASE_IMAGE }}
139175 BAZEL_CACHE=${{ inputs.bazel-remote-cache-url }}
@@ -173,6 +209,53 @@ runs:
173209 BUILD_DATE=${{ inputs.BUILD_DATE }}
174210 ${{ inputs.EXTRA_BUILD_ARGS }}
175211
212+ # BAZEL CACHE EXPORT
213+ - name : Export Bazel disk cache
214+ if : inputs.ENABLE_BAZEL_DISK_CACHE == 'true'
215+ uses : docker/build-push-action@v5
216+ with :
217+ context : ${{ inputs.DOCKER_CONTEXT }}
218+ push : false
219+ file : ${{ inputs.DOCKERFILE }}
220+ platforms : linux/${{ inputs.ARCHITECTURE }}
221+ target : bazel-disk-export
222+ outputs : type=local,dest=/tmp/bazel-disk-cache-new
223+ build-contexts : |
224+ bazel-disk-seed=/tmp/bazel-disk-cache
225+ build-args : |
226+ BASE_IMAGE=${{ inputs.BASE_IMAGE }}
227+ BUILD_DATE=${{ inputs.BUILD_DATE }}
228+ ${{ inputs.EXTRA_BUILD_ARGS }}
229+
230+ - name : Save Bazel disk cache
231+ if : inputs.ENABLE_BAZEL_DISK_CACHE == 'true'
232+ uses : actions/cache/save@v4
233+ with :
234+ path : /tmp/bazel-disk-cache-new
235+ key : bazel-disk-cache-${{ inputs.ARCHITECTURE }}-${{ github.run_id }}
236+
237+ - name : Export Bazel repo cache
238+ if : inputs.ENABLE_BAZEL_REPO_CACHE == 'true'
239+ uses : docker/build-push-action@v5
240+ with :
241+ context : ${{ inputs.DOCKER_CONTEXT }}
242+ push : false
243+ file : ${{ inputs.DOCKERFILE }}
244+ platforms : linux/${{ inputs.ARCHITECTURE }}
245+ target : bazel-repo-export
246+ outputs : type=local,dest=/tmp/bazel-repo-cache-new
247+ build-args : |
248+ BASE_IMAGE=${{ inputs.BASE_IMAGE }}
249+ BUILD_DATE=${{ inputs.BUILD_DATE }}
250+ ${{ inputs.EXTRA_BUILD_ARGS }}
251+
252+ - name : Save Bazel repo cache
253+ if : inputs.ENABLE_BAZEL_REPO_CACHE == 'true'
254+ uses : actions/cache/save@v4
255+ with :
256+ path : /tmp/bazel-repo-cache-new
257+ key : bazel-repo-cache-${{ inputs.ARCHITECTURE }}-${{ github.run_id }}
258+
176259 # SITREP GENERATION
177260 - name : Generate sitrep
178261 if : " !cancelled()"
0 commit comments