Improve Docker build caching for staging workflow

- Add registry cache persistence to fallback when GHA cache expires
- Optimize static-assets stage with selective COPY for frontend files
- Reduces context from 44MB to 3.2MB, preventing cache invalidation on backend changes
- Backend-only changes no longer trigger unnecessary frontend rebuilds
This commit is contained in:
Andras Bacsai 2025-12-13 22:39:42 +01:00
parent ad013ca7da
commit b7a6f1a4fa
2 changed files with 19 additions and 3 deletions

View file

@ -80,7 +80,9 @@ jobs:
cache-from: |
type=gha,scope=build-${{ matrix.arch }}
type=registry,ref=${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=build-${{ matrix.arch }}
cache-to: |
type=gha,mode=max,scope=build-${{ matrix.arch }}
type=registry,ref=${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max
merge-manifest:
runs-on: ubuntu-24.04

View file

@ -38,10 +38,24 @@ USER www-data
FROM node:24-alpine AS static-assets
WORKDIR /app
COPY package*.json vite.config.js postcss.config.cjs ./
# Layer 1: Package dependencies (rarely changes)
COPY package*.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci
COPY . .
# Layer 2: Build config (rarely changes)
COPY vite.config.js postcss.config.cjs ./
# Layer 3: Frontend source files
COPY resources/css/ ./resources/css/
COPY resources/js/ ./resources/js/
COPY resources/fonts/ ./resources/fonts/
# Layer 4: Blade templates for Tailwind class detection
COPY resources/views/ ./resources/views/
# Build frontend assets
RUN npm run build
# =================================================================