-
Notifications
You must be signed in to change notification settings - Fork 0
add docker #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
add docker #121
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # .dockerignore — loại trừ các file không cần copy vào Docker image | ||
| # Đặt ở root của project (cùng cấp với Dockerfile) | ||
|
|
||
| # Git | ||
| .git | ||
| .gitignore | ||
| .github | ||
|
|
||
| # Dependencies (sẽ được install lại trong container) | ||
| src/node_modules | ||
|
|
||
| # Build output (sẽ được build lại trong container) | ||
| src/.next | ||
| src/coverage | ||
|
|
||
| # Dev/test artifacts | ||
| src/.swc | ||
| src/tsconfig.tsbuildinfo | ||
|
|
||
| # Environment files (inject qua CI/CD secrets, không bake vào image) | ||
| src/.env.local | ||
| src/.env*.local | ||
|
|
||
| # Logs | ||
| *.log | ||
| npm-debug.log* | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # IDE | ||
| .vscode | ||
| .idea | ||
| *.suo | ||
| *.user | ||
|
|
||
| # Docker files (không cần copy vào image) | ||
| Dockerfile | ||
| docker-compose*.yml | ||
| .dockerignore | ||
|
|
||
| # Docs | ||
| README.md | ||
| LICENSE | ||
| acc.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # ============================================================ | ||
| # Stage 1: base — base image with essential libraries | ||
| # ============================================================ | ||
| FROM node:20-alpine AS base | ||
| RUN apk add --no-cache libc6-compat | ||
| WORKDIR /app | ||
|
|
||
| # Application version (passed at build time) | ||
| ARG NEXT_PUBLIC_APP_VERSION | ||
| ENV NEXT_PUBLIC_APP_VERSION=$NEXT_PUBLIC_APP_VERSION | ||
|
|
||
| # ============================================================ | ||
| # Stage 2: development — prep for dev environment | ||
| # ============================================================ | ||
| FROM base AS development | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy ALL deps (including devDeps) | ||
| COPY src/package.json src/package-lock.json ./ | ||
| RUN npm ci --ignore-scripts | ||
|
|
||
| # Copy source code | ||
| COPY src/ . | ||
|
|
||
| # Disable Next.js telemetry | ||
| ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| # ============================================================ | ||
| # Stage 3: builder — compile the Next.js app | ||
| # ============================================================ | ||
| FROM development AS builder | ||
|
|
||
| # Build-time env vars (public ones only — never leak secrets here) | ||
| ARG NEXT_PUBLIC_SUPABASE_URL | ||
| ARG NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY | ||
|
|
||
| ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL | ||
| ENV NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=$NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY | ||
|
|
||
| RUN npm run build | ||
|
|
||
| # ============================================================ | ||
| # Stage 3: runner — minimal production image | ||
| # ============================================================ | ||
| FROM base AS runner | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| ENV NODE_ENV=production | ||
| ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
|
||
| # Create non-root user for security | ||
| RUN addgroup --system --gid 1001 nodejs && \ | ||
| adduser --system --uid 1001 nextjs | ||
|
|
||
| # Copy built assets from builder | ||
| COPY --from=builder --chown=nextjs:nodejs /app/public ./public | ||
| COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | ||
| COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | ||
|
|
||
| USER nextjs | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| ENV PORT=3000 | ||
| ENV HOSTNAME="0.0.0.0" | ||
|
|
||
| # Use Next.js standalone server | ||
| CMD ["node", "server.js"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # docker-compose.yml — dùng cho LOCAL DEVELOPMENT | ||
| # Không dùng file này ở production | ||
|
|
||
| name: task-master-pro | ||
|
|
||
| services: | ||
| app: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| target: development # build xong là chạy ngay (npm install), không cần build sản phẩm | ||
| args: | ||
| NEXT_PUBLIC_SUPABASE_URL: ${NEXT_PUBLIC_SUPABASE_URL} | ||
| NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY: ${NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY} | ||
| NEXT_PUBLIC_APP_VERSION: ${APP_VERSION:-0.1.0} | ||
| command: npm run dev | ||
| ports: | ||
| - "3000:3000" | ||
| volumes: | ||
| - ./src:/app # hot-reload: mount source vào container | ||
| - /app/node_modules # giữ nguyên node_modules của container | ||
| - /app/.next # giữ nguyên .next cache | ||
| environment: | ||
| - NODE_ENV=development | ||
| - NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL} | ||
| - NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=${NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY} | ||
| - NEXT_PUBLIC_APP_VERSION=${APP_VERSION:-0.1.0} | ||
| - SUPABASE_SERVICE_ROLE_KEY=${SUPABASE_SERVICE_ROLE_KEY} | ||
| env_file: | ||
| - src/.env.local | ||
|
TamCter marked this conversation as resolved.
|
||
| restart: unless-stopped | ||
| healthcheck: | ||
| test: ["CMD", "node", "-e", "fetch('http://localhost:3000/api/health').then(r => r.ok ? process.exit(0) : process.exit(1)).catch(() => process.exit(1))"] | ||
| interval: 30s | ||
| timeout: 10s | ||
| retries: 3 | ||
| start_period: 40s | ||
|
TamCter marked this conversation as resolved.
|
||
|
|
||
| # ── Production preview (dùng `docker compose --profile prod up`) ── | ||
| app-prod: | ||
| profiles: ["prod"] | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| args: | ||
| NEXT_PUBLIC_SUPABASE_URL: ${NEXT_PUBLIC_SUPABASE_URL} | ||
| NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY: ${NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY} | ||
| NEXT_PUBLIC_APP_VERSION: ${APP_VERSION:-0.1.0} | ||
| ports: | ||
| - "3000:3000" | ||
| environment: | ||
| - NEXT_PUBLIC_APP_VERSION=${APP_VERSION:-0.1.0} | ||
| - SUPABASE_SERVICE_ROLE_KEY=${SUPABASE_SERVICE_ROLE_KEY} | ||
| env_file: | ||
| - src/.env.local | ||
| restart: unless-stopped | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { NextResponse } from "next/server"; | ||
|
|
||
| /** | ||
| * GET /api/health | ||
| * Health-check endpoint dùng cho Docker healthcheck & monitoring | ||
| */ | ||
| export async function GET() { | ||
| return NextResponse.json( | ||
| { | ||
| status: "ok", | ||
| timestamp: new Date().toISOString(), | ||
| uptime: process.uptime(), | ||
| version: process.env.NEXT_PUBLIC_APP_VERSION ?? "unknown", | ||
| environment: process.env.NODE_ENV, | ||
| }, | ||
| { status: 200 } | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.