-
Notifications
You must be signed in to change notification settings - Fork 5
feat(docker): dockerize app with dev compose and docs #82
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
Conversation
- add multi-stage Dockerfile using Next.js standalone output (node:20-alpine) - add docker-compose.dev.yml for hot-reload development (bind mounts, npm run dev) - add docker-compose.yml for runtime usage - add .dockerignore to shrink build context - docs(README): add Docker usage instructions - fix(header): remove unused Badge import to pass ESLint - chore(compose): drop obsolete `version` field from compose files - build: set default NEXTAUTH_SECRET during image build to avoid NextAuth error
WalkthroughAdds Docker support and docs: a multi-stage Next.js Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as Developer
participant DCdev as docker-compose.dev.yml
participant DCprod as docker-compose.yml
participant Docker as Docker Engine
participant Image as Image (githubmon:prod)
participant Container as Container (runner)
Dev->>DCdev: docker compose -f docker-compose.dev.yml up
DCdev->>Docker: start dev container (node:20-alpine, volumes, npm run dev)
Dev->>Container: interact via localhost:3000 (hot-reload)
Dev->>DCprod: docker compose up -d
DCprod->>Docker: build using `Dockerfile` (target=runner)
Docker->>Docker: stages: base -> deps (npm ci) -> build (npm run build) -> runner
Docker-->>Image: produce image githubmon:prod
DCprod->>Docker: run container with env (NODE_ENV, NEXTAUTH_*, GITHUB_*)
Docker-->>Container: start container (port 3000, HOSTNAME=0.0.0.0)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (11)
.dockerignore (1)
1-13: Solid baseline; add a few common ignores.Consider ignoring editor/system files and coverage to trim build context further.
node_modules .next out .git .gitignore Dockerfile* docker-compose*.yml npm-debug.log* yarn-debug.log* yarn-error.log* .pnpm-store .env* **/*.tsbuildinfo +*.log +.DS_Store +.idea/ +.vscode/ +coverage/ +dist/ +tmp/Dockerfile (5)
5-7: PNPM vars not used; drop to reduce noise.You enable corepack and set PNPM_HOME but use npm throughout. Remove these to keep intent clear.
-ENV PNPM_HOME="/pnpm" -ENV PATH="$PNPM_HOME:$PATH" -RUN corepack enable +# corepack/PNPM not required since we use npm ci
21-24: Avoid duplicate apk installs; keep it in one stage.You install libc6-compat in both deps and build. One install in deps is enough if you copy node_modules; drop it here unless build tooling needs it independently.
-RUN apk add --no-cache libc6-compat
35-37: Preserve ownership for non-root runtime.Files copied as root may cause permission surprises later. Copy with ownership or chown once.
-COPY --from=build /app/.next/standalone ./ -COPY --from=build /app/.next/static ./.next/static -COPY --from=build /app/public ./public +COPY --chown=nextjs:nextjs --from=build /app/.next/standalone ./ +COPY --chown=nextjs:nextjs --from=build /app/.next/static ./.next/static +COPY --chown=nextjs:nextjs --from=build /app/public ./public
39-44: Add a healthcheck for better orchestration behavior.Helps Compose/K8s manage restarts and readiness.
EXPOSE 3000 USER nextjs - -CMD ["node", "server.js"] +HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD wget -qO- http://127.0.0.1:3000/ || exit 1 +CMD ["node", "server.js"]
27-29: Optional: set HOME for non-root user.Prevents some tools from complaining and ensures consistent cache paths.
FROM node:20-alpine AS runner ENV NODE_ENV=production WORKDIR /app +ENV HOME=/home/nextjsdocker-compose.dev.yml (3)
5-5:npm cievery start is slow; cache when possible.If startup time is an issue, separate install into a one-off task or leverage a named volume for node_modules to persist across container recreations.
- command: sh -c "npm ci && npm run dev" + command: sh -c "npm run dev" + volumes: + - node_modules:/app/node_modules +volumes: + node_modules:
11-15: Add polling envs for reliable hot reload on Docker Desktop.Improves file watching on macOS/Windows.
- HOSTNAME=0.0.0.0 + - CHOKIDAR_USEPOLLING=true + - WATCHPACK_POLLING=true
12-15: Optional: run as non-root in dev.Avoids accidental root-owned files if additional mounts are added later.
volumes: - ./:/app - /app/node_modules - /app/.next + user: "${UID:-1000}:${GID:-1000}"README.md (1)
142-169: Clarify env handling and dev gotchas.Small additions improve DX and security expectations.
- Note that the placeholder NEXTAUTH_SECRET is only used at build time and not present in the runtime image; production must supply its own secret.
- Mention
.envauto-loading by Docker Compose and showenv_file: .envalternative.- Add hint for macOS/Windows to set CHOKIDAR_USEPOLLING/WATCHPACK_POLLING when using dev compose.
- Add a brief note about the image running as non-root in production.
Example snippet:
Compose reads variables from a `.env` file in the project root by default. Alternatively: services: web: env_file: .env On macOS/Windows, for hot reload in containers, set: CHOKIDAR_USEPOLLING=true WATCHPACK_POLLING=truedocker-compose.yml (1)
10-19: Considerenv_fileand a healthcheck.Keeps compose clean and improves service management.
environment: - - NODE_ENV=production - - NEXT_TELEMETRY_DISABLED=1 - - HOSTNAME=0.0.0.0 - # Map your envs; you can also use an env_file - - NEXTAUTH_URL=${NEXTAUTH_URL} - - NEXTAUTH_SECRET=${NEXTAUTH_SECRET} - - GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID} - - GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET} + - NODE_ENV=production + - NEXT_TELEMETRY_DISABLED=1 + - HOSTNAME=0.0.0.0 + env_file: + - .env + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/ || exit 1"] + interval: 30s + timeout: 3s + retries: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (6)
.dockerignore(1 hunks)Dockerfile(1 hunks)README.md(1 hunks)docker-compose.dev.yml(1 hunks)docker-compose.yml(1 hunks)src/components/layout/Header.tsx(0 hunks)
💤 Files with no reviewable changes (1)
- src/components/layout/Header.tsx
🔇 Additional comments (2)
Dockerfile (2)
20-24: Verify that NEXTAUTH_SECRET placeholder isn’t embedded in the build
Ensure the placeholderdev_docker_build_secretdoesn’t end up in the server bundle. Locally runnpm run buildand thengrep -R "dev_docker_build_secret" .nextto confirm there are no matches.
4-4: Node.js 20 EOL confirmed; Node.js 22 LTS available
Node.js 20 (Iron) reaches end-of-life on April 30, 2026; Node.js 22 (Jod) is the current Active LTS (EOL April 30, 2027). Consider upgrading to Node 22 if compatible.
versionfield from compose#27
@omarkurt @ArjinAlbay
Summary by CodeRabbit
New Features
Documentation
Chores
Refactor