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 1/4] 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 # ================================================================= From 3832530587ea044d35189ee4d15280cba748dfca Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sat, 13 Dec 2025 22:44:10 +0100 Subject: [PATCH 2/4] test: trigger build to verify cache optimization --- config/app.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/app.php b/config/app.php index a94cfadd8..81034bab1 100644 --- a/config/app.php +++ b/config/app.php @@ -1,5 +1,7 @@ Date: Sat, 13 Dec 2025 22:48:03 +0100 Subject: [PATCH 3/4] Add Docker build caching to production workflow --- .github/workflows/coolify-production-build.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/coolify-production-build.yml b/.github/workflows/coolify-production-build.yml index 477274751..b388591f2 100644 --- a/.github/workflows/coolify-production-build.yml +++ b/.github/workflows/coolify-production-build.yml @@ -59,6 +59,9 @@ jobs: run: | echo "VERSION=$(docker run --rm -v "$(pwd):/app" -w /app php:8.2-alpine3.16 php bootstrap/getVersion.php)"|xargs >> $GITHUB_OUTPUT + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and Push Image (${{ matrix.arch }}) uses: docker/build-push-action@v6 with: @@ -69,6 +72,12 @@ jobs: tags: | ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-${{ matrix.arch }} ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.VERSION }}-${{ matrix.arch }} + cache-from: | + type=gha,scope=prod-build-${{ matrix.arch }} + type=registry,ref=${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}:prod-buildcache-${{ matrix.arch }} + cache-to: | + type=gha,mode=max,scope=prod-build-${{ matrix.arch }} + type=registry,ref=${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}:prod-buildcache-${{ matrix.arch }},mode=max merge-manifest: runs-on: ubuntu-24.04 From 1807ecaaddb0a2d8d7c6aa7988ace5b72f469f73 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sat, 13 Dec 2025 22:49:29 +0100 Subject: [PATCH 4/4] revert: remove test comment from config/app.php --- config/app.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/app.php b/config/app.php index 81034bab1..a94cfadd8 100644 --- a/config/app.php +++ b/config/app.php @@ -1,7 +1,5 @@