From b7a6f1a4fad743f55beb367be9db6f2e26a851e3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sat, 13 Dec 2025 22:39:42 +0100 Subject: [PATCH] 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 --- .github/workflows/coolify-staging-build.yml | 4 +++- docker/production/Dockerfile | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coolify-staging-build.yml b/.github/workflows/coolify-staging-build.yml index 494ef6939..11e5dff9d 100644 --- a/.github/workflows/coolify-staging-build.yml +++ b/.github/workflows/coolify-staging-build.yml @@ -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 diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile index 2ce8c834e..65f062d2d 100644 --- a/docker/production/Dockerfile +++ b/docker/production/Dockerfile @@ -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 # =================================================================