Skip to content

add docker#121

Merged
TamCter merged 3 commits intodevelopfrom
docker
Apr 15, 2026
Merged

add docker#121
TamCter merged 3 commits intodevelopfrom
docker

Conversation

@TamCter
Copy link
Copy Markdown
Collaborator

@TamCter TamCter commented Apr 15, 2026

  1. Chạy nhanh cho Development (Hot-reload)
    Đây là cách nhanh nhất để bắt đầu code. Code ở máy thật sẽ đồng bộ vào container, sửa code là trình duyệt tự cập nhật.

bash

Bước 1: Đảm bảo đã có file src/.env.local (copy từ .env.example)

Bước 2: Khởi chạy dự án

docker compose up -d

Xem log để kiểm tra lỗi

docker compose logs -f app
2. Chạy thử bản Production (Build kĩ)
Dành cho việc kiểm tra app chạy như thế nào trong môi trường Docker thật sự trước khi deploy.

bash

Bước 1: Build image (truyền các biến môi trường Public vào build-arg)

Lưu ý: SERVICE_ROLE_KEY không truyền ở đây vì tính bảo mật

docker build --build-arg NEXT_PUBLIC_SUPABASE_URL="URL_CUA_BAN"
--build-arg NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY="KEY_CUA_BAN" `
-t task-master-pro:latest .

Bước 2: Chạy container

docker run -d --name task-master-pro
-p 3000:3000 -e SUPABASE_SERVICE_ROLE_KEY="KEY_BAO_MAT_CUA_BAN"
task-master-pro:latest
3. Các câu lệnh quản lý khác
Dừng dự án: docker compose down
Xóa toàn bộ để build lại từ đầu (không dùng cache):
bash
docker compose down
docker compose build --no-cache
docker compose up -d
Kiểm tra xem app đã "sống" chưa:
bash
curl http://localhost:3000/api/health

Summary by CodeRabbit

Ghi chú phát hành

  • Tính năng mới

    • Thêm điểm kiểm tra sức khỏe ứng dụng để giám sát.
  • Chores

    • Hỗ trợ Docker để triển khai containerized với cấu hình phát triển cục bộ.
    • Tối ưu hóa cấu hình Next.js cho môi trường container.

@TamCter TamCter requested a review from tribeti April 15, 2026 11:37
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 Docker support for the Next.js application by adding a multi-stage Dockerfile, a .dockerignore file, and a docker-compose configuration for development and production previews. Additionally, it enables standalone output in the Next.js configuration, adds a health check endpoint, and refactors the notification cron route to lazily initialize the Supabase client. Feedback suggests optimizing the Dockerfile structure with a shared base stage to ensure consistency and reduce redundancy, fixing file ownership for the public directory, and improving the development workflow by avoiding unnecessary build steps in Docker Compose. It also notes that the package version will not be correctly detected in the standalone production environment.

Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Comment thread docker-compose.yml Outdated
Comment thread src/app/api/health/route.ts Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Warning

Rate limit exceeded

@TamCter has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 26 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 21 minutes and 26 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b490e745-59b1-4c31-b557-e3ebc58e21c0

📥 Commits

Reviewing files that changed from the base of the PR and between 7f4aa84 and 805fa75.

📒 Files selected for processing (3)
  • docker-compose.yml
  • src/app/api/cron/notifications/route.ts
  • src/utils/supabase/admin.ts
📝 Walkthrough

Walkthrough

Thêm các tệp Docker (Dockerfile, docker-compose.yml, .dockerignore) để hỗ trợ containerization ứng dụng Next.js với xây dựng đa giai đoạn. Ngoài ra, tái cấu trúc khởi tạo Supabase admin client, thêm endpoint health check, và cấu hình Next.js standalone output.

Changes

Cohort / File(s) Summary
Docker Configuration
.dockerignore, Dockerfile, docker-compose.yml
Thiết lập containerization hoàn chỉnh: .dockerignore loại trừ các tệp không cần thiết; Dockerfile xác định xây dựng đa giai đoạn (base, development, builder, runner) cho Next.js; docker-compose.yml định cấu hình các dịch vụ app (development) và app-prod (production preview) với volume mount, biến môi trường, và healthcheck.
Next.js Configuration
src/next.config.ts
Bổ sung output: "standalone" để tối ưu hóa output cho containerization.
API Route Refactoring
src/app/api/cron/notifications/route.ts
Thay thế khởi tạo Supabase admin client ở mức module bằng helper function lazy getSupabaseAdmin() với xử lý lỗi rõ ràng cho credentials bị thiếu.
Health Check Endpoint
src/app/api/health/route.ts
Thêm endpoint GET /api/health trả về thông tin trạng thái, timestamp, uptime, phiên bản ứng dụng, và môi trường chạy.

Possibly related PRs

  • feat/notify assign #109: Cả hai PR sửa đổi tệp src/app/api/cron/notifications/route.ts — PR này tái cấu trúc khởi tạo Supabase client, trong khi PR liên quan thay đổi nội dung thông báo trên cùng đường mã.

Suggested reviewers

  • tribeti
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive Tiêu đề 'add docker' quá chung chung và thiếu chi tiết cụ thể về thay đổi chính. Mặc dù liên quan đến changeset, nó không mô tả đầy đủ phạm vi của những gì đã được thêm vào (Docker multi-stage build, docker-compose cho dev/prod, health check endpoint, v.v.). Cân nhắc thay tiêu đề thành chi tiết hơn như 'Add Docker support with multi-stage build and development/production compose setup' để rõ ràng hơn về nội dung thay đổi.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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.

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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docker-compose.yml`:
- Around line 29-30: The env_file entry currently points to src/.env.local which
will make docker compose up fail if that file is missing; update the
docker-compose.yml env_file entry to use the Compose v2.17+ mapping form and
mark the file optional (use the env_file mapping with source: src/.env.local and
optional: true) so Compose will not error when the file is absent, or
alternatively document/create a pre-run step that ensures src/.env.local exists
before running docker compose up; target the env_file block and the
src/.env.local reference when applying the change.
- Around line 32-37: The healthcheck currently uses the non-existent wget binary
and will always fail; replace the healthcheck test that references wget with a
Node-based check using the built-in fetch API (e.g. update the healthcheck test
to run a Node one-liner via node -e that fetches
http://localhost:3000/api/health and exits with code 0 on ok or non-zero on
failure). Target the healthcheck block (the test entry) in docker-compose.yml
and ensure the command runs with node from the image (node:20-alpine supports
fetch), preserving interval/timeout/retries/start_period values.

In `@Dockerfile`:
- Around line 43-46: The stage comment above the runner image is misnumbered as
"Stage 3"; update the comment to reflect the actual stage sequence (base →
development → builder → runner) by changing "Stage 3: runner — minimal
production image" to "Stage 4: runner — minimal production image" (the block
containing FROM base AS runner identifies the runner stage).

In `@src/app/api/cron/notifications/route.ts`:
- Around line 5-12: Replace the duplicated helper getSupabaseAdmin() with the
existing createAdminClient() utility: remove getSupabaseAdmin() from this route
and call createAdminClient() instead, ensuring the Supabase client is
initialized with the same auth options (autoRefreshToken: false, persistSession:
false) that the original utility provides; if you worry about Next.js static
analysis at build time, update createAdminClient() to validate env vars at
runtime and throw a clear error when NEXT_PUBLIC_SUPABASE_URL or
SUPABASE_SERVICE_ROLE_KEY are missing so callers can safely call
createAdminClient() inside the handler.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 511cc991-dcba-4ac3-9f7d-288310273877

📥 Commits

Reviewing files that changed from the base of the PR and between fda45b8 and 7f4aa84.

📒 Files selected for processing (6)
  • .dockerignore
  • Dockerfile
  • docker-compose.yml
  • src/app/api/cron/notifications/route.ts
  • src/app/api/health/route.ts
  • src/next.config.ts

Comment thread docker-compose.yml
Comment thread docker-compose.yml
Comment thread Dockerfile
Comment thread src/app/api/cron/notifications/route.ts Outdated
@TamCter TamCter merged commit 576c504 into develop Apr 15, 2026
5 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.

2 participants