feat(website): Optimize Docker infrastructure and reduce resource usage#640
feat(website): Optimize Docker infrastructure and reduce resource usage#640
Conversation
Implement multi-stage build with production-only dependencies to improve Cloud Run startup performance. Reduce image size by 11% while maintaining all functionality including git support for remote repository processing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Replace pako.deflate/inflate with zlib.deflateSync/inflateSync in cache.ts - Remove pako and @types/pako dependencies from package.json - Utilize Node.js built-in zlib module for better performance and reduced dependencies 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Optimize resource allocation in cloudbuild.yaml for cost efficiency - Maintain adequate performance with reduced CPU allocation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Update repomix dependency from 0.3.7 to 0.3.9 - Includes latest features and bug fixes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…conflicts - Add "name": "repomix-website-server" to server/package.json - Add "name": "repomix-website-client" to client/package.json - Prevents npm from using /app directory name in package-lock.json during Docker builds - Ensures consistent package names across development environments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe updates introduce asynchronous cache operations using Node.js zlib, remove the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant RequestCache
Note over RequestCache: Uses zlib for compression
Caller->>RequestCache: await get(key)
alt Cache hit
RequestCache->>zlib: Decompress entry
zlib-->>RequestCache: Decompressed data
RequestCache-->>Caller: Parsed result
else Cache miss
RequestCache-->>Caller: undefined
end
Caller->>RequestCache: await set(key, value)
RequestCache->>zlib: Compress value
zlib-->>RequestCache: Compressed buffer
RequestCache-->>Caller: (after storing)
Possibly related PRs
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Deploying repomix with
|
| Latest commit: |
d58702e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2711c59b.repomix.pages.dev |
| Branch Preview URL: | https://feat-docker-slim.repomix.pages.dev |
There was a problem hiding this comment.
Hello @yamadashy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello! Gemini here, providing a summary of this pull request to help everyone quickly understand the changes and context.
This PR, authored by yamadashy, focuses on optimizing the Docker infrastructure for the website's server component and reducing its resource usage. The main goals are to implement multi-stage Docker builds for efficiency, clean up dependencies, upgrade Node.js to version 24, tune CPU and timeout settings for Cloud Run deployment, and migrate from the pako library to Node.js's built-in zlib module for compression, aiming to reduce the overall footprint and potentially improve performance.
Highlights
- Docker Optimization: The Dockerfile for the server has been significantly refactored to use multi-stage builds. This includes a dedicated stage for installing production dependencies only, resulting in a smaller final image size. The base Node.js version is upgraded from 23 to 24.
- Resource Reduction: Cloud Run deployment settings in
cloudbuild.yamlhave been adjusted to use fewer CPU resources (reduced from 4 to 2) and a slightly shorter timeout (reduced from 35s to 31s). - Dependency Migration: The
pakolibrary, previously used for compression/decompression in the server's cache utility, has been replaced with Node.js's nativezlibmodule. This removes an external dependency and leverages a built-in capability. - Security Improvement: The Dockerfile now includes steps to create and switch to a non-root user (
nodejs) for running the application, improving security by reducing potential attack surface.
Changelog
Click here to see the changelog
- website/client/package-lock.json
- Added
namefield (repomix-website-client) to the root and package sections.
- Added
- website/client/package.json
- Added
namefield (repomix-website-client).
- Added
- website/server/Dockerfile
- Upgraded base Node.js image from
node:23-alpinetonode:24-alpinefor all stages. - Changed
npm itonpm ciin the builder stage for deterministic builds. - Introduced a new
depsstage to install only production dependencies (npm ci --only=production) and clean the npm cache. - Moved
gitinstallation from the builder stage to the final runtime image. - Added steps to create and switch to a non-root user (
nodejs) for running the application. - Copied built application (
dist) and production dependencies (node_modules) from their respective stages using--chownto the non-root user. - Removed the
HEALTHCHECKinstruction. - Changed the
CMDto directly execute the built JavaScript file (node dist/index.js) instead of usingnpm start.
- Upgraded base Node.js image from
- website/server/cloudbuild.yaml
- Reduced
--cpusetting for Cloud Run deployment from4to2. - Reduced
--timeoutsetting for Cloud Run deployment from35sto31s.
- Reduced
- website/server/package-lock.json
- Added
namefield (repomix-website-server) to the root and package sections. - Removed
pakoand@types/pakoentries. - Updated
repomixdependency version from0.3.7to0.3.9.
- Added
- website/server/package.json
- Added
namefield (repomix-website-server). - Removed
pakoand@types/pakofrom dependencies and devDependencies.
- Added
- website/server/src/utils/cache.ts
- Replaced
pakoimport withnode:zlib. - Updated
inflatelogic to usezlib.inflateSyncand convert the result to a UTF-8 string. - Updated
deflatelogic to usezlib.deflateSyncand explicitly pass a Buffer created from the JSON string.
- Replaced
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #640 +/- ##
=======================================
Coverage 90.32% 90.32%
=======================================
Files 96 96
Lines 4962 4962
Branches 1042 1042
=======================================
Hits 4482 4482
Misses 480 480 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces several valuable optimizations to the Docker infrastructure and resource usage, aligning well with the stated goals. The multi-stage build in the Dockerfile is a great improvement for reducing the final image size. Upgrading to Node.js 24 is also a positive step. The migration from pako to Node.js's built-in zlib module is well-implemented and removes an external dependency. The reduction in Cloud Run CPU and timeout settings is a good effort towards resource optimization, assuming testing confirms these settings are sufficient under expected load.
Overall, the changes are well-structured and address the objectives. However, there is one significant concern regarding the removal of the health check in the Dockerfile, which is crucial for reliable deployments in orchestrated environments.
Summary of Findings
- Dockerfile Multi-stage build and Node.js 24 upgrade: The Dockerfile has been refactored to use a multi-stage build, separating build dependencies from runtime dependencies, which is a good practice for reducing final image size. The base image has also been updated to Node.js 24, as intended.
- Removal of
ca-certificatesin Dockerfile builder stage: Theca-certificatespackage was removed from the builder stage. While Alpine images usually include necessary certificates, it's a minor point to be aware of if any build steps encounter certificate issues. - Removal of
HEALTHCHECKin Dockerfile: TheHEALTHCHECKinstruction was removed from the final Docker image. This is a significant change as health checks are important for deployment reliability in orchestrated environments. This issue has been commented on directly. - Cloud Run CPU and Timeout Tuning: The Cloud Build configuration reduces the allocated CPU from 4 to 2 and the timeout from 35s to 31s. This aims to reduce resource usage. The test plan includes verifying deployment with these settings, which is good.
- Package Name Updates: The
namefield inpackage.jsonandpackage-lock.jsonfor both client and server projects has been updated fromappto more descriptive names (repomix-website-client,repomix-website-server). - pako-to-zlib Migration: The
pakodependency and its types have been removed, and the compression/decompression logic incache.tshas been updated to use Node.js's built-inzlibmodule. This successfully removes an external dependency and is implemented correctly. - Repomix Version Update: The
repomixdependency in the server'spackage-lock.jsonwas updated from0.3.7to0.3.9.
Merge Readiness
This pull request introduces valuable optimizations and dependency updates. The multi-stage Docker build and the zlib migration are positive changes. However, the removal of the HEALTHCHECK instruction in the Dockerfile is a high-severity issue that impacts deployment reliability. I recommend addressing this issue before merging. Please note that I am unable to approve this pull request; other reviewers should review and approve this code before merging.
…ent loop blocking Replace synchronous zlib.inflateSync/deflateSync with async alternatives to prevent blocking the event loop under high load. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
…erface 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
deaeebf to
900bd49
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the website server’s build infrastructure, reduces resource usage, and migrates in-memory caching to use Node’s built-in zlib.
- Replace pako with promisified zlib for async compression in
RequestCache - Upgrade Docker images to Node.js 24 with a three-stage build and non-root runtime user
- Tune Cloud Run CPU and timeout settings
Reviewed Changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/utils/cache.ts | Swap pako for zlib/promisify, convert cache get/set to async |
| server/src/remoteRepo.ts | Await updated async cache API |
| server/src/processZipFile.ts | Await updated async cache API |
| server/package.json | Remove pako dependency, set name |
| server/cloudbuild.yaml | Decrease CPU allocation and request timeout |
| server/Dockerfile | Introduce multi-stage build, upgrade to Node 24, add non-root user |
| client/package.json | Add name field to client package.json |
Files not reviewed (2)
- website/client/package-lock.json: Language not supported
- website/server/package-lock.json: Language not supported
Comments suppressed due to low confidence (3)
website/server/src/utils/cache.ts:24
- Changing get() from sync to async is a breaking API change. Document this change or bump the package version accordingly to avoid unexpected consumer issues.
async get(key: string): Promise<T | undefined> {
website/server/Dockerfile:61
- Switching from
npm starttonode dist/index.jsmay skip environment setup or scripts defined in package.json. Confirm the runtime behavior matches expectations.
CMD ["node", "dist/index.js"]
website/server/cloudbuild.yaml:41
- [nitpick] Dropping from 4 to 2 CPUs could cause builds or startup to slow or time out. Monitor memory/CPU footprints and adjust if builds begin to fail.
- - '2'
Alpine images often omit CA certificates needed for HTTPS git operations. Add ca-certificates to ensure remote cloning/pulls succeed at runtime. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
• Optimize Docker infrastructure with multi-stage builds, dependency cleanup, and Node.js 24 upgrade
• Reduce resource usage through CPU/timeout tuning and pako-to-zlib migration
Test plan
🤖 Generated with Claude Code