Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 6, 2025

The Docker stages were copying application source code before installing packages, which caused unnecessary cache invalidation. When app files changed, it would force rebuilding expensive package installation layers even though the dependencies hadn't changed.

Problem

FROM base AS debug
COPY . /app/src          # ❌ App changes invalidate package cache
RUN apt-get install...   # ❌ Rebuilds when app changes

FROM base AS tests  
COPY . /app/src              # ❌ App changes invalidate package cache
RUN apt-get install...      # ❌ Rebuilds when app changes
RUN npx playwright install  # ❌ Expensive operation rebuilds unnecessarily

Solution

FROM base AS debug
RUN apt-get install...   # ✅ Cached independently of app changes
COPY . /app/src          # ✅ Only invalidates when needed

FROM base AS tests
RUN apt-get install...      # ✅ Cached independently of app changes  
RUN npx playwright install  # ✅ Expensive operation stays cached
COPY . /app/src             # ✅ Only invalidates when needed

Impact

  • Improved build performance: Package installations now cache properly across app changes
  • Reduced CI/CD build times: Expensive operations like Playwright installation only run when dependencies change
  • Better layer caching: Each Docker layer caches independently based on its actual dependencies
  • Faster development iteration: App code changes don't trigger unnecessary package reinstalls

The changes move COPY . /app/src commands to the end of each stage, after all package installations are complete. This ensures optimal Docker layer caching behavior.

Fixes #245.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@dannystaple
Copy link
Member

I left a typo in the original ticket (typed on a mobile). IT should read "base docker stage" and has nothing to do with sockets.

Co-authored-by: dannystaple <426859+dannystaple@users.noreply.github.com>
Copilot AI changed the title [WIP] The base socket stage shouldn't copy app Fix Docker base stage caching by moving app copy to consuming stages Aug 6, 2025
Copilot AI requested a review from dannystaple August 6, 2025 08:32
Copilot finished work on behalf of dannystaple August 6, 2025 08:32
- Move app source copy in debug stage after apt package installations
- Move app source copy in tests stage after Playwright installation
- Improves Docker layer caching by preventing app changes from invalidating package installation layers

Co-authored-by: dannystaple <426859+dannystaple@users.noreply.github.com>
Copilot AI changed the title Fix Docker base stage caching by moving app copy to consuming stages Optimize Docker stage caching by moving app copy after package installations Aug 6, 2025
Copilot AI requested a review from dannystaple August 6, 2025 11:44
Copilot finished work on behalf of dannystaple August 6, 2025 11:44
@dannystaple dannystaple marked this pull request as ready for review August 6, 2025 12:05
@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2025

🦙 MegaLinter status: ❌ ERROR

Descriptor Linter Files Fixed Errors Warnings Elapsed time
❌ ACTION actionlint 5 6 0 0.09s
✅ BASH bash-exec 1 0 0 0.0s
✅ BASH shellcheck 1 0 0 0.05s
⚠️ BASH shfmt 1 1 0 0.0s
❌ C cppcheck 8 8 0 0.23s
❌ CPP cppcheck 8 8 0 0.33s
✅ JSON npm-package-json-lint yes no no 0.48s
✅ JSON v8r 12 0 0 9.34s
❌ MARKDOWN markdown-link-check 736 213 0 38.45s
✅ REPOSITORY gitleaks yes no no 14.14s
✅ REPOSITORY git_diff yes no no 0.69s
✅ REPOSITORY grype yes no no 34.36s
✅ REPOSITORY secretlint yes no no 44.79s
✅ REPOSITORY syft yes no no 1.97s
✅ REPOSITORY trivy-sbom yes no no 3.19s
✅ REPOSITORY trufflehog yes no no 4.72s
✅ XML xmllint 1 0 0 189.22s
✅ YAML v8r 13 0 0 7.84s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

@dannystaple dannystaple merged commit a825565 into master Aug 6, 2025
4 checks passed
@dannystaple dannystaple deleted the copilot/fix-245 branch August 6, 2025 18:30
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.

The base docker stage shouldn't copy app

2 participants