@@ -181,7 +181,7 @@ jobs:
181181 if : fromJSON(needs.prepare-metadata.outputs.docker_push)
182182 uses : aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
183183
184- - name : Determine Image Name
184+ - name : Determine Image Name and Cache Configuration
185185 id : image_name
186186 run : |
187187 if [[ "${{ fromJSON(needs.prepare-metadata.outputs.use_ecr) }}" == "true" ]]; then
@@ -193,6 +193,23 @@ jobs:
193193 fi
194194 echo "image_name=${image_name}" >> $GITHUB_OUTPUT
195195
196+ # Configure cache settings
197+ cache_ref="${image_name}:buildcache-${{ matrix.platform.tag_suffix }}"
198+ echo "cache_ref=${cache_ref}" >> $GITHUB_OUTPUT
199+
200+ # For PR builds, use gha cache as fallback since we can't push to registry
201+ # For push builds, use registry cache for better persistence and sharing
202+ if [[ "${{ fromJSON(needs.prepare-metadata.outputs.docker_push) }}" == "true" ]]; then
203+ echo "cache_from=type=registry,ref=${cache_ref}" >> $GITHUB_OUTPUT
204+ echo "cache_to=type=registry,ref=${cache_ref},mode=max" >> $GITHUB_OUTPUT
205+ echo "Using registry cache (can read and write)"
206+ else
207+ # PR builds: try to read from registry cache, write to gha cache
208+ echo "cache_from=type=registry,ref=${cache_ref}" >> $GITHUB_OUTPUT
209+ echo "cache_to=type=gha,scope=${{ matrix.platform.tag_suffix }},mode=max" >> $GITHUB_OUTPUT
210+ echo "Using registry cache for reading, gha cache for writing (PR build)"
211+ fi
212+
196213 - name : Build and Push Platform-Specific Image
197214 uses : docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0
198215 with :
@@ -201,8 +218,8 @@ jobs:
201218 platforms : ${{ matrix.platform.name }}
202219 tags : ${{ steps.image_name.outputs.image_name }}:${{ needs.prepare-metadata.outputs.version }}-${{ needs.prepare-metadata.outputs.short_sha }}-${{ matrix.platform.tag_suffix }}
203220 push : ${{ fromJSON(needs.prepare-metadata.outputs.docker_push) }}
204- cache-from : type=gha,scope= ${{ matrix.platform.tag_suffix }}
205- cache-to : type=gha,scope= ${{ matrix.platform.tag_suffix }},mode=max
221+ cache-from : ${{ steps.image_name.outputs.cache_from }}
222+ cache-to : ${{ steps.image_name.outputs.cache_to }}
206223 provenance : false
207224 sbom : false
208225
0 commit comments