Skip to content

Optimize Docker layer caching in frontend/Dockerfile to reduce build times #5

@chigwell

Description

@chigwell

User Story
As a software developer,
I want to optimize Docker layer caching in the frontend/Dockerfile by separating npm install from source file copying
so that dependency installation is cached independently of source code changes, reducing build times during CI/CD.

Background
The current frontend/Dockerfile copies all source files (including public/ and src/) before running npm install. This invalidates the Docker cache for dependency installation whenever any source file changes, forcing a full reinstall of npm packages even when only application code is modified. This inefficiency increases build times and resource usage in development and deployment workflows. The specific file requiring modification is frontend/Dockerfile.

Acceptance Criteria

  • Modify frontend/Dockerfile to:
    • Copy only package.json before running npm install
    • Copy remaining source files (public/ and src/) after dependency installation
  • Ensure npm install executes only when package.json changes
  • Validation steps:
    • After implementation, modify a file in frontend/src/ and rebuild the Docker image. npm install should not rerun if package.json remains unchanged.
    • Confirm via build logs that the "CACHED" marker appears for the npm install layer during rebuilds with unchanged dependencies.
    • Verify build time reduction by comparing timestamps before/after the change when only source files are modified.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions