Skip to content

chore: add local service bootstrap#5913

Merged
killagu merged 4 commits into
nextfrom
agent/egg-dev/fa7b6cfb
May 3, 2026
Merged

chore: add local service bootstrap#5913
killagu merged 4 commits into
nextfrom
agent/egg-dev/fa7b6cfb

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented May 2, 2026

Summary

  • add a repo-level Docker Compose stack for local MySQL/Redis services
  • add dev:services package scripts for start, stop, status, and reset
  • document service versions, DB initialization, port conflict behavior, environment overrides, and current hard-coded DAL/ORM/Redis test assumptions with utoo run commands

Verification

  • node --check scripts/dev-services.js
  • docker compose -f dev-services.compose.yml config
  • utoo --version
  • utoo run dev:services:status
  • utoo execute oxlint scripts/dev-services.js
  • utoo execute oxfmt --check README.md scripts/dev-services.js
  • git diff --check

Earlier service-stack verification on this PR also covered alternate-port startup, MySQL database initialization, Redis ping, running stack port mismatch protection, and reset cleanup.

Note: I did not rerun DAL/ORM tests against the default local ports after the utoo wording follow-up because 127.0.0.1:3306 was already occupied by an existing host service, and those tests mutate local MySQL databases.

Summary by CodeRabbit

  • New Features

    • Start/stop/status/reset local Dockerized MySQL and Redis via new npm commands; services bind to localhost on documented default ports, support image/port overrides via env vars, validate port availability, run health checks, auto-initialize test databases, and report readiness or actionable errors.
  • Documentation

    • Added "Local External Services" section with setup, usage, status/reset guidance, default ports, env var overrides, and note to reset when switching MySQL image families.

Copilot AI review requested due to automatic review settings May 2, 2026 16:46
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a Docker Compose project for local MySQL 8 and Redis 7, a Node.js CLI to start/stop/status/reset that project, npm script wrappers, and README documentation describing default localhost ports, fixture databases, and environment-variable overrides.

Changes

Local Development Services

Layer / File(s) Summary
Compose Configuration
dev-services.compose.yml
New Docker Compose file ${EGG_DEV_SERVICES_PROJECT:-eggjs_dev_services} defining mysql and redis, configurable image and host-port env vars, healthchecks, and a named mysql-data volume.
CLI Boot / Config
scripts/dev-services.js
CLI bootstrap: resolves repo root and compose file, reads EGG_DEV_SERVICES_MYSQL_PORT, EGG_DEV_SERVICES_REDIS_PORT, EGG_DEV_SERVICES_WAIT_TIMEOUT, and defines fixed MySQL fixture database list.
Docker Helpers
scripts/dev-services.js
Adds dockerCompose() and runDocker() wrappers to run docker compose/docker commands with output capture and optional allow-failure behavior.
Preconditions / Port Checks
scripts/dev-services.js
Implements portIsFree, runningServices, docker compose port parsing, and assertPortAvailable to validate host-port availability and detect conflicting published endpoints.
Readiness & Init Logic
scripts/dev-services.js
Adds waitFor retry helper, initMysql which waits for mysqladmin ping and runs CREATE DATABASE IF NOT EXISTS for configured DBs, and waitRedis using redis-cli ping; failures include last command output.
Workflow Wiring
scripts/dev-services.js
Implements `start
CLI Integration
package.json
Adds npm scripts dev:services:start, dev:services:stop, dev:services:status, dev:services:reset calling node scripts/dev-services.js <action>.
Documentation
README.md
Adds “Local External Services” section documenting how to start/status/stop/reset services, lists created MySQL databases, default endpoints (127.0.0.1:3306, 127.0.0.1:6379), port-conflict behavior, and env var overrides (EGG_DEV_SERVICES_MYSQL_IMAGE, EGG_DEV_SERVICES_REDIS_IMAGE, EGG_DEV_SERVICES_MYSQL_PORT, EGG_DEV_SERVICES_REDIS_PORT) and notes about resetting when switching MySQL image families.

Sequence Diagram

sequenceDiagram
    actor Developer
    participant npm as "npm scripts"
    participant CLI as "dev-services.js"
    participant Docker as "Docker daemon"
    participant MySQL as "MySQL container"
    participant Redis as "Redis container"

    Developer->>npm: run dev:services:start
    npm->>CLI: node scripts/dev-services.js start
    CLI->>Docker: docker compose -f dev-services.compose.yml version
    CLI->>CLI: check port 3306 on 127.0.0.1
    CLI->>CLI: check port 6379 on 127.0.0.1
    CLI->>Docker: docker compose up -d
    Docker->>MySQL: create/start container
    Docker->>Redis: create/start container
    CLI->>MySQL: mysqladmin ping (retry)
    MySQL-->>CLI: ready
    CLI->>MySQL: CREATE DATABASE IF NOT EXISTS ...
    MySQL-->>CLI: databases created
    CLI->>Redis: redis-cli ping (retry)
    Redis-->>CLI: ready
    CLI->>Developer: print endpoints 127.0.0.1:3306, 127.0.0.1:6379
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nudged the compose file awake,
I hummed a ping to MySQL's gate,
Redis replied on seven-three-seven,
Volumes warmed and scripts did skate,
Local fixtures ready — hop to the gate.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: add local service bootstrap' accurately describes the primary change: introducing local Docker Compose services (MySQL and Redis) with supporting scripts and documentation for local development.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/egg-dev/fa7b6cfb

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.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 2, 2026

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5e4dd6d
Status: ✅  Deploy successful!
Preview URL: https://4a72cb23.egg-cci.pages.dev
Branch Preview URL: https://agent-egg-dev-fa7b6cfb.egg-cci.pages.dev

View logs

Copy link
Copy Markdown
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 a local development environment for external services (MySQL and Redis) using Docker Compose. It includes a management script (scripts/dev-services.js) to handle service lifecycle, port availability checks, and database initialization, along with new npm scripts in package.json. Documentation has been added to the README.md to guide users. Feedback focuses on improving security by explicitly binding service ports to 127.0.0.1 and enhancing error handling in the script's main catch block.

Comment thread dev-services.compose.yml Outdated
Comment thread dev-services.compose.yml Outdated
Comment thread scripts/dev-services.js Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.03%. Comparing base (88fa8e4) to head (5e4dd6d).
⚠️ Report is 3 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5913      +/-   ##
==========================================
- Coverage   85.03%   85.03%   -0.01%     
==========================================
  Files         665      667       +2     
  Lines       19108    19110       +2     
  Branches     3719     3719              
==========================================
+ Hits        16249    16250       +1     
- Misses       2466     2467       +1     
  Partials      393      393              

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

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 2, 2026

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5e4dd6d
Status: ✅  Deploy successful!
Preview URL: https://e02b1c0b.egg-v3.pages.dev
Branch Preview URL: https://agent-egg-dev-fa7b6cfb.egg-v3.pages.dev

View logs

@killagu killagu force-pushed the agent/egg-dev/fa7b6cfb branch from 5cf9004 to 2cac01e Compare May 2, 2026 16:49
Copy link
Copy Markdown
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 adds a repository-level way to bootstrap local MySQL and Redis services for development and test flows that depend on external infrastructure. It fits into the monorepo by providing a shared local-services entrypoint plus documentation for DAL/ORM/Redis-related workflows.

Changes:

  • Add a new scripts/dev-services.js CLI to start, stop, reset, and inspect a Docker Compose stack.
  • Add dev:services:* root package scripts that wrap the new helper.
  • Add a root dev-services.compose.yml and README guidance describing local service setup, ports, image overrides, and test assumptions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
scripts/dev-services.js Adds the Node.js helper that orchestrates Docker Compose, port checks, readiness checks, and MySQL DB initialization.
package.json Adds root scripts for starting/stopping/checking/resetting the local services stack.
dev-services.compose.yml Defines the local MySQL/Redis containers, ports, healthchecks, and persistent MySQL volume.
README.md Documents how to use the new local services workflow and which tests/fixtures depend on it.

Comment thread dev-services.compose.yml
Comment thread dev-services.compose.yml
Comment thread scripts/dev-services.js Outdated
@killagu killagu force-pushed the agent/egg-dev/fa7b6cfb branch from 2cac01e to 70d153e Compare May 2, 2026 16:53
Copilot AI review requested due to automatic review settings May 3, 2026 02:37
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/dev-services.js (1)

26-56: 💤 Low value

runDocker is a near-duplicate of dockerCompose used only once

The two helpers share identical bodies; the sole difference is that runDocker skips -f composeFile. runDocker is called exactly once (line 154) to detect Docker Compose availability. Consider either inlining the availability check (e.g. spawnSync('docker', ['compose', 'version'], …)) or folding the two helpers together with an option flag to reduce the duplication surface.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/dev-services.js` around lines 26 - 56, dockerCompose and runDocker
are near-duplicates; consolidate them by creating a single helper (e.g.,
dockerRun) that accepts an option to inject composeFile usage or takes the full
args array so both cases are covered (use dockerRun in place of dockerCompose
and runDocker). Update calls that currently call dockerCompose(...) to pass
['compose','-f', composeFile, ...] and replace the single runDocker call (the
compose availability check) with dockerRun(['compose','version'], {cwd: rootDir,
encoding:'utf8', stdio: ...}) or call dockerRun with an option like
{useComposeFile:false}. Ensure the new helper preserves the same error handling
and returns the spawnSync result, referencing spawnSync, composeFile, rootDir,
dockerCompose, and runDocker for locating and replacing the implementations and
call sites.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/dev-services.js`:
- Around line 108-109: Update the user-facing guidance string that currently
says "utoo run dev:services:reset" to the correct command "pnpm run
dev:services:reset" in the message assembled by the array ending with
].join('\n'); locate and edit the string literal in the message block (the
sentence starting "Re-run with the same EGG_DEV_SERVICES_* port override, or run
...") so it references "pnpm run" instead of "utoo run".

---

Nitpick comments:
In `@scripts/dev-services.js`:
- Around line 26-56: dockerCompose and runDocker are near-duplicates;
consolidate them by creating a single helper (e.g., dockerRun) that accepts an
option to inject composeFile usage or takes the full args array so both cases
are covered (use dockerRun in place of dockerCompose and runDocker). Update
calls that currently call dockerCompose(...) to pass ['compose','-f',
composeFile, ...] and replace the single runDocker call (the compose
availability check) with dockerRun(['compose','version'], {cwd: rootDir,
encoding:'utf8', stdio: ...}) or call dockerRun with an option like
{useComposeFile:false}. Ensure the new helper preserves the same error handling
and returns the spawnSync result, referencing spawnSync, composeFile, rootDir,
dockerCompose, and runDocker for locating and replacing the implementations and
call sites.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3c377324-c6f1-42aa-b04a-c978a57254cc

📥 Commits

Reviewing files that changed from the base of the PR and between 70d153e and b3db4df.

📒 Files selected for processing (2)
  • README.md
  • scripts/dev-services.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

Comment thread scripts/dev-services.js Outdated
Copy link
Copy Markdown
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

Comment thread scripts/dev-services.js
Comment thread scripts/dev-services.js Outdated
Comment thread scripts/dev-services.js Outdated
Comment thread scripts/dev-services.js Outdated
Comment thread README.md
Comment thread README.md
Comment thread README.md
Comment thread scripts/dev-services.js Outdated
Copilot AI review requested due to automatic review settings May 3, 2026 03:46
Copy link
Copy Markdown
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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@killagu killagu merged commit fd1bb0e into next May 3, 2026
29 of 30 checks passed
@killagu killagu deleted the agent/egg-dev/fa7b6cfb branch May 3, 2026 04:57
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