Skip to content

Conversation

@Tharsanan1
Copy link
Contributor

@Tharsanan1 Tharsanan1 commented Jan 27, 2026

This PR improves the Docker build performance by restructuring the COPY commands. It ensures that 'go mod download' only runs when the dependency definitions (go.mod/go.sum) change, rather than on every source code modification. This is achieved by copying only the mod files first and moving the full source code copy steps after the dependency download.

Summary by CodeRabbit

  • Chores
    • Optimized Docker build layer caching for dependencies in gateway-controller and policy-engine services, improving build efficiency by separating dependency resolution from source code changes.
    • Enhanced cross-compilation support to properly handle different processor architectures during containerized builds.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

Walkthrough

Both Dockerfiles reorganize layer caching strategy for Go dependencies by copying go.mod/go.sum files first for early dependency resolution, then copying full source code afterward. This isolates module cache invalidation to dependency changes. The gateway-controller Dockerfile additionally adds cross-compiler selection logic based on target architecture.

Changes

Cohort / File(s) Summary
Dependency-First Caching Strategy
gateway/gateway-controller/Dockerfile, gateway/policy-engine/Dockerfile
Restructures COPY commands to prioritize go.mod/go.sum before full module contents, enabling Docker to cache dependency resolution separately from source code changes. Moves RUN go mod download after copying modular files. Reorders subsequent COPY commands for source code to occur post-dependency resolution.
Cross-Compiler Selection
gateway/gateway-controller/Dockerfile
Adds conditional logic in build stage to set CC environment variable based on TARGETARCH (amd64 or arm64), ensuring correct cross-compiler is selected during CGO-enabled builds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hops through Docker layers with glee,
Dependencies cached first, you see!
Source comes after, the layers are wise,
No rebuild needed when code satisfies!
Cross-compiling flows with TARGETARCH grace,
Optimization wins this Docker race! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete against the template, missing required sections including Purpose, Goals, Approach, User stories, Documentation, Automation tests, Security checks, Samples, Related PRs, and Test environment. Complete the description by adding all required template sections with appropriate details for this Docker optimization change, or provide clear justification for any N/A sections.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Optimize Docker build caching' directly and specifically summarizes the main change in the PR, which restructures Dockerfiles to improve build caching efficiency.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


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.

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