Skip to content

Conversation

@HazarBakir
Copy link
Contributor

@HazarBakir HazarBakir commented Oct 1, 2025

  • 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
  • build: set default NEXTAUTH_SECRET during image build to avoid NextAuth error

#27
@omarkurt @ArjinAlbay

Summary by CodeRabbit

  • New Features

    • Dockerized app with a multi-stage production image, non-root runtime, and port 3000.
    • Development hot-reload setup via docker-compose.
  • Documentation

    • Added Docker usage guide with dev/prod commands and required environment variables.
  • Chores

    • Added .dockerignore to reduce build context.
    • Added docker-compose configs for dev and production.
    • Added MIT LICENSE file.
  • Refactor

    • Removed an unused import to reduce footprint.

- 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
@coderabbitai
Copy link

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adds Docker support and docs: a multi-stage Next.js Dockerfile, docker-compose.yml, docker-compose.dev.yml, a .dockerignore, README Docker usage, plus a minor UI cleanup (removed unused Badge import) and added LICENSE. No runtime application logic changed.

Changes

Cohort / File(s) Summary
Dockerfiles & compose
Dockerfile, docker-compose.yml, docker-compose.dev.yml, .dockerignore
Adds a multi-stage Dockerfile (base → deps → build → runner) for a Next.js app, production and development docker-compose configs, and a .dockerignore excluding common build/local artifacts. Runtime uses a non-root user, exposes port 3000, and runs the standalone server.
Documentation
README.md
Adds a Docker section with Development (hot reload) and Production usage instructions, commands, and required environment variables.
License
LICENSE
Adds MIT license file.
UI cleanup
src/components/layout/Header.tsx
Removes unused Badge import; no behavioral 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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • docs: update README #8 — README modifications overlap (this PR adds a Docker section while that PR rewrote README).

Poem

I pack my carrots in a layered crate,
Build, copy, run — my burrow's first-rate.
Volumes mounted, ports set free,
A stray Badge gone, the tree feels breezy.
Hop into containers — prod and dev, hooray! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly highlights the primary change of adding Docker support to the application along with development compose configuration and documentation, directly reflecting the key additions in the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb9a0d5 and e4b67c0.

📒 Files selected for processing (1)
  • LICENSE (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • LICENSE

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

@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: 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/nextjs
docker-compose.dev.yml (3)

5-5: npm ci every 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 .env auto-loading by Docker Compose and show env_file: .env alternative.
  • 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=true
docker-compose.yml (1)

10-19: Consider env_file and 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

📥 Commits

Reviewing files that changed from the base of the PR and between c505f6c and 5960aec.

⛔ Files ignored due to path filters (1)
  • package-lock.json is 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 placeholder dev_docker_build_secret doesn’t end up in the server bundle. Locally run npm run build and then

grep -R "dev_docker_build_secret" .next

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

@ArjinAlbay ArjinAlbay merged commit 3dceb1c into HappyHackingSpace:main Oct 19, 2025
1 check 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