Skip to content

Commit 38c39e4

Browse files
use registry cache
1 parent 6b581a4 commit 38c39e4

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ RUN curl -sL https://deb.nodesource.com/setup_24.x | bash - && \
2222
# ============================================================
2323
# UI Build Stages - Run in parallel with separate caches
2424
# ============================================================
25+
# These stages use registry cache with mode=max, which means:
26+
# - Each stage is cached independently in the registry
27+
# - Only stages with changed dependencies will rebuild
28+
# - Cache mounts persist across builds for faster npm installs
29+
# - Changes to docs/ won't invalidate config_portal or webui caches
30+
# ============================================================
2531

2632
# Build Config Portal UI
2733
FROM base AS ui-config-portal
@@ -55,6 +61,12 @@ RUN npm run build
5561
# ============================================================
5662
# Python Build Stage
5763
# ============================================================
64+
# This stage uses registry cache with mode=max for optimal caching:
65+
# - uv cache mount (/root/.cache/uv) speeds up package downloads
66+
# - Lock file changes only rebuild dependency installation layer
67+
# - Source code changes only rebuild the wheel build layer
68+
# - Independent from UI build stages - Python changes don't rebuild UI
69+
# ============================================================
5870

5971
# Builder stage for creating wheels and runtime environment
6072
FROM base AS builder
@@ -130,6 +142,8 @@ RUN playwright install-deps chromium
130142

131143
# Install Playwright browsers with cache (cached layer)
132144
# This layer stays cached because it doesn't depend on builder stage
145+
# Registry cache with mode=max ensures this expensive download is cached
146+
# sharing=locked prevents concurrent builds from corrupting the cache
133147
RUN --mount=type=cache,target=/var/cache/playwright,sharing=locked \
134148
PLAYWRIGHT_BROWSERS_PATH=/var/cache/playwright playwright install chromium
135149

0 commit comments

Comments
 (0)