Skip to content

feat(website): Optimize Docker infrastructure and reduce resource usage#640

Merged
yamadashy merged 10 commits intomainfrom
feat/docker-slim
Jun 7, 2025
Merged

feat(website): Optimize Docker infrastructure and reduce resource usage#640
yamadashy merged 10 commits intomainfrom
feat/docker-slim

Conversation

@yamadashy
Copy link
Owner

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

  • Verify Docker build succeeds with new multi-stage configuration
  • Test that website server starts correctly with Node.js 24
  • Confirm Cloud Run deployment works with reduced CPU/timeout settings
  • Validate zlib compression works properly for cached responses

🤖 Generated with Claude Code

yamadashy and others added 7 commits June 7, 2025 15:56
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>
Copilot AI review requested due to automatic review settings June 7, 2025 08:19
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 7, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The updates introduce asynchronous cache operations using Node.js zlib, remove the pako dependency, and update related function calls to await cache access. The Dockerfile is refactored for improved security and reproducibility, and deployment settings are adjusted for CPU and timeout. Both client and server package.json files now include a "name" field.

Changes

File(s) Change Summary
website/client/package.json, website/server/package.json Added "name" field to each package.json; removed "pako" and "@types/pako" from server dependencies.
website/server/Dockerfile Refactored to use Node.js 24-alpine, split build/deps/runtime stages, run as non-root, switched to node dist/index.js.
website/server/cloudbuild.yaml Reduced Cloud Run CPU from 4 to 2, and timeout from 35s to 31s.
website/server/src/utils/cache.ts Replaced pako with async zlib compression, made get and set methods async, removed generic from CacheEntry.
website/server/src/processZipFile.ts, src/remoteRepo.ts Updated cache access to await asynchronous get and set methods.

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)
Loading

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 7, 2025

Deploying repomix with  Cloudflare Pages  Cloudflare Pages

Latest commit: d58702e
Status: ✅  Deploy successful!
Preview URL: https://2711c59b.repomix.pages.dev
Branch Preview URL: https://feat-docker-slim.repomix.pages.dev

View logs

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.yaml have 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 pako library, previously used for compression/decompression in the server's cache utility, has been replaced with Node.js's native zlib module. 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 name field (repomix-website-client) to the root and package sections.
  • website/client/package.json
    • Added name field (repomix-website-client).
  • website/server/Dockerfile
    • Upgraded base Node.js image from node:23-alpine to node:24-alpine for all stages.
    • Changed npm i to npm ci in the builder stage for deterministic builds.
    • Introduced a new deps stage to install only production dependencies (npm ci --only=production) and clean the npm cache.
    • Moved git installation 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 --chown to the non-root user.
    • Removed the HEALTHCHECK instruction.
    • Changed the CMD to directly execute the built JavaScript file (node dist/index.js) instead of using npm start.
  • website/server/cloudbuild.yaml
    • Reduced --cpu setting for Cloud Run deployment from 4 to 2.
    • Reduced --timeout setting for Cloud Run deployment from 35s to 31s.
  • website/server/package-lock.json
    • Added name field (repomix-website-server) to the root and package sections.
    • Removed pako and @types/pako entries.
    • Updated repomix dependency version from 0.3.7 to 0.3.9.
  • website/server/package.json
    • Added name field (repomix-website-server).
    • Removed pako and @types/pako from dependencies and devDependencies.
  • website/server/src/utils/cache.ts
    • Replaced pako import with node:zlib.
    • Updated inflate logic to use zlib.inflateSync and convert the result to a UTF-8 string.
    • Updated deflate logic to use zlib.deflateSync and explicitly pass a Buffer created from the JSON string.
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

  1. 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
Copy link

codecov bot commented Jun 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.32%. Comparing base (b345676) to head (d58702e).
Report is 11 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

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

This comment was marked as outdated.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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-certificates in Dockerfile builder stage: The ca-certificates package 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 HEALTHCHECK in Dockerfile: The HEALTHCHECK instruction 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 name field in package.json and package-lock.json for both client and server projects has been updated from app to more descriptive names (repomix-website-client, repomix-website-server).
  • pako-to-zlib Migration: The pako dependency and its types have been removed, and the compression/decompression logic in cache.ts has been updated to use Node.js's built-in zlib module. This successfully removes an external dependency and is implemented correctly.
  • Repomix Version Update: The repomix dependency in the server's package-lock.json was updated from 0.3.7 to 0.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>
@yamadashy yamadashy requested a review from Copilot June 7, 2025 08:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 start to node dist/index.js may 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>
@yamadashy yamadashy merged commit b9c6bdb into main Jun 7, 2025
65 checks passed
@yamadashy yamadashy deleted the feat/docker-slim branch June 7, 2025 09:33
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.

2 participants