Skip to content

reorder the COPY in dockerfiles of backend for better layer caching#3945

Merged
arkid15r merged 3 commits intoOWASP:mainfrom
Davda-James:perf/docker_layer_caching
Feb 14, 2026
Merged

reorder the COPY in dockerfiles of backend for better layer caching#3945
arkid15r merged 3 commits intoOWASP:mainfrom
Davda-James:perf/docker_layer_caching

Conversation

@Davda-James
Copy link
Contributor

@Davda-James Davda-James commented Feb 14, 2026

Changes:
Minor improvements were made to the backend dockerfiles by reordering COPY statements. Previously, stable files like settings, static, and templates would rebuild whenever frequently changing files like apps were modified. The COPY instructions have now been reordered so that the most volatile files (apps and tests) are copied last.

Resolves #3944

I have scoped this for backend dockerfiles changes, if suggested by @ahmedxgouda will also review other dockerfiles for such improvements.

Files changed

docker/backend/Dockerfile 
docker/backend/Dockerfile.test
  • I followed the contributing workflow
  • I verified that my code works as intended and resolves the issue as described
  • I ran make check-test locally: all warnings addressed, tests passed
    The mypy test is failing but that is not because of my change its due to unescaped new lines in f string.
backend/tests/apps/mentorship/management/commands/mentorship_sync_module_issues_test.py:210: error: Unterminated string literal (detected at line 210)  [syntax]
Found 1 error in 1 file (errors prevented further checking)

If want I can change that in this PR.

  • I used AI for code, documentation, tests, or communication related to this PR

@github-actions github-actions bot added the docker Pull requests that update Docker code label Feb 14, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 14, 2026

Summary by CodeRabbit

  • Chores
    • Reordered Docker build file copy steps to improve layer caching and build efficiency.
    • Adjusted the sequence of asset and application copies to reduce rebuild frequency for unchanged layers and speed up image builds.

Walkthrough

Reorders COPY directives in docker/backend/Dockerfile: moves COPY apps to after COPY templates and COPY static, and adjusts the relative ordering of templates and static. No other build instructions or public APIs were changed.

Changes

Cohort / File(s) Summary
Dockerfile optimization
docker/backend/Dockerfile
Reordered COPY statements: placed COPY templates before COPY static, and moved COPY apps later in the sequence (after templates/static). Added a comment about cache considerations. No other instructions altered.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

backend, docker

Suggested reviewers

  • kasya
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: reordering COPY directives in backend Dockerfiles for improved layer caching.
Description check ✅ Passed The description clearly explains the rationale for reordering COPY statements to optimize Docker layer caching by placing volatile files last.
Linked Issues check ✅ Passed The PR successfully addresses issue #3944 by reordering COPY statements in backend Dockerfiles to copy stable files before volatile ones, improving layer caching.
Out of Scope Changes check ✅ Passed All changes are within scope, focusing on reordering COPY directives in backend Dockerfiles as specified in issue #3944.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


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.

cubic-dev-ai[bot]
cubic-dev-ai bot previously approved these changes Feb 14, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 14, 2026
Copy link
Collaborator

@ahmedxgouda ahmedxgouda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this. Please see the below comments.

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.34%. Comparing base (6071232) to head (d5f83c5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3945   +/-   ##
=======================================
  Coverage   96.34%   96.34%           
=======================================
  Files         512      512           
  Lines       15815    15815           
  Branches     2131     2174   +43     
=======================================
  Hits        15237    15237           
  Misses        431      431           
  Partials      147      147           
Flag Coverage Δ
backend 95.99% <ø> (ø)
frontend 97.42% <ø> (ø)

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


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6071232...d5f83c5. Read the comment docs.

🚀 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.

@ahmedxgouda ahmedxgouda self-assigned this Feb 14, 2026
@github-actions github-actions bot removed the docker Pull requests that update Docker code label Feb 14, 2026
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 14, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docker/backend/Dockerfile.test">

<violation number="1">
P1: **Caching regression**: `COPY apps apps` was moved from the last position to the second, which is the *opposite* of the intended optimization. In Docker layer caching, when a layer changes all subsequent layers are invalidated. The volatile `apps` directory should be copied **last** (not second), so that changes to application code don't invalidate the cache for stable layers like `settings`, `static`, and `templates`.

The correct order should copy stable files first and volatile files (`apps`, `tests/apps`) last — matching the pattern already used in the production `Dockerfile`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

ahmedxgouda
ahmedxgouda previously approved these changes Feb 14, 2026
Copy link
Collaborator

@ahmedxgouda ahmedxgouda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarqubecloud
Copy link

@arkid15r arkid15r enabled auto-merge February 14, 2026 20:12
@arkid15r arkid15r added this pull request to the merge queue Feb 14, 2026
Merged via the queue into OWASP:main with commit 3d52a6c Feb 14, 2026
36 checks passed
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.

Optimize layer caching in backend Dockerfile

3 participants