Skip to content

Improved production Docker build caching#28080

Merged
9larsons merged 1 commit into
mainfrom
codex/improve-production-docker-cache
May 23, 2026
Merged

Improved production Docker build caching#28080
9larsons merged 1 commit into
mainfrom
codex/improve-production-docker-cache

Conversation

@9larsons
Copy link
Copy Markdown
Contributor

Summary

  • enables plain BuildKit progress for the production Docker build steps so cache behavior is visible in CI logs
  • copies only dependency metadata and component tarballs before pnpm install --prod
  • copies the rest of the app after the production dependency install layer
  • moves GHOST_BUILD_VERSION until after the expensive install/setup layers so per-commit build versions do not invalidate dependency installation

Expected impact

The current Dockerfile copies the whole packed app and sets GHOST_BUILD_VERSION before running production dependency installation. Because PR builds set GHOST_BUILD_VERSION to the package version plus short SHA, that per-commit value can invalidate the pnpm install --prod layer even when production dependencies are unchanged.

This should make the expensive dependency layer reusable when only app source/admin assets change. The CI logs should also show clearer CACHED/rebuilt layer behavior for the Build & push core image and Build & push full image steps.

Follow-up ideas kept for later

  • inspect the first few CI runs after this change and compare Docker layer cache hits/misses with the historic Build & push core image and Build & push full image timings
  • consider whether PR E2E needs the exact release-grade image path, or whether main/tags can keep release fidelity while PRs use a faster image path
  • consider a docker bake/single multi-target build if the two separate build-push-action calls still duplicate work

Testing

  • pnpm --filter ghost archive
  • docker buildx build --check --target core -f Dockerfile.production ghost/core/package
  • docker buildx build --check --target full -f Dockerfile.production ghost/core/package
  • git diff --check

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 74bca1dd-1228-4c89-833d-18f8ff55774f

📥 Commits

Reviewing files that changed from the base of the PR and between 6f36260 and fb01e7c.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • Dockerfile.production
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/ci.yml

Walkthrough

This PR sets BUILDKIT_PROGRESS=plain in step-local env blocks for the CI docker/build-push-action steps that build the core and full images. It also updates Dockerfile.production's core stage: adds ENV NODE_ENV=production near the start, moves corepack enable earlier, narrows initial COPYs to dependency/workspace/registry files plus components, runs pnpm install (and build deps) before copying the rest of the context, separates apt cleanup from subsequent filesystem/setup steps, and relocates ARG/ENV GHOST_BUILD_VERSION to the end of the dependency/setup block.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improved production Docker build caching' directly matches the main objective of the changeset - optimizing Docker layer caching in production builds.
Description check ✅ Passed The description is closely related to the changeset, explaining the rationale behind the Docker build and CI workflow changes with clear details about caching improvements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/improve-production-docker-cache

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.81%. Comparing base (88d5d08) to head (6f36260).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #28080   +/-   ##
=======================================
  Coverage   73.80%   73.81%           
=======================================
  Files        1528     1528           
  Lines      129417   129417           
  Branches    15504    15506    +2     
=======================================
+ Hits        95521    95527    +6     
- Misses      32917    32934   +17     
+ Partials      979      956   -23     
Flag Coverage Δ
admin-tests 54.03% <ø> (ø)
e2e-tests 73.81% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The production image copied the full app and set the per-commit build version before installing production dependencies, so ordinary source changes could invalidate the expensive pnpm install layer. Copying dependency metadata first and setting the build version later makes cache hits easier to diagnose and reuse.
@9larsons 9larsons force-pushed the codex/improve-production-docker-cache branch from 6f36260 to fb01e7c Compare May 23, 2026 11:44
@9larsons 9larsons enabled auto-merge (squash) May 23, 2026 11:45
@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.81%. Comparing base (a304042) to head (fb01e7c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #28080   +/-   ##
=======================================
  Coverage   73.81%   73.81%           
=======================================
  Files        1528     1528           
  Lines      129417   129417           
  Branches    15506    15506           
=======================================
  Hits        95527    95527           
+ Misses      32934    32910   -24     
- Partials      956      980   +24     
Flag Coverage Δ
admin-tests 54.03% <ø> (ø)
e2e-tests 73.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@9larsons 9larsons merged commit 04f55ed into main May 23, 2026
81 of 94 checks passed
@9larsons 9larsons deleted the codex/improve-production-docker-cache branch May 23, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant