Skip to content

Commit 5960aec

Browse files
committed
feat(docker): dockerize app with dev compose and docs
- 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
1 parent c505f6c commit 5960aec

File tree

7 files changed

+122
-128
lines changed

7 files changed

+122
-128
lines changed

.dockerignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
node_modules
2+
.next
3+
out
4+
.git
5+
.gitignore
6+
Dockerfile*
7+
docker-compose*.yml
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
.pnpm-store
12+
.env*
13+
**/*.tsbuildinfo

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# syntax=docker/dockerfile:1.7
2+
3+
# ---------- Base ----------
4+
FROM node:20-alpine AS base
5+
ENV PNPM_HOME="/pnpm"
6+
ENV PATH="$PNPM_HOME:$PATH"
7+
RUN corepack enable
8+
WORKDIR /app
9+
10+
# ---------- Deps (install with frozen lockfile) ----------
11+
FROM base AS deps
12+
RUN apk add --no-cache libc6-compat
13+
COPY package.json package-lock.json ./
14+
RUN npm ci
15+
16+
# ---------- Build ----------
17+
FROM base AS build
18+
ENV NEXT_TELEMETRY_DISABLED=1
19+
# Provide a safe default so NextAuth doesn't fail during build
20+
ENV NEXTAUTH_SECRET=dev_docker_build_secret
21+
RUN apk add --no-cache libc6-compat
22+
COPY --from=deps /app/node_modules ./node_modules
23+
COPY . .
24+
RUN npm run build
25+
26+
# ---------- Runtime ----------
27+
FROM node:20-alpine AS runner
28+
ENV NODE_ENV=production
29+
WORKDIR /app
30+
31+
# Non-root user
32+
RUN addgroup -S nextjs && adduser -S nextjs -G nextjs
33+
34+
# Copy standalone server
35+
COPY --from=build /app/.next/standalone ./
36+
COPY --from=build /app/.next/static ./.next/static
37+
COPY --from=build /app/public ./public
38+
39+
ENV PORT=3000
40+
ENV HOSTNAME=0.0.0.0
41+
EXPOSE 3000
42+
USER nextjs
43+
44+
CMD ["node", "server.js"]

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,33 @@ Contributions are welcome! Please open an issue or submit a pull request.
137137

138138
## License
139139

140-
MIT
140+
MIT
141+
142+
## Docker
143+
144+
### Development (hot reload)
145+
```bash
146+
# Build and start
147+
docker compose -f docker-compose.dev.yml up --build
148+
# Then open http://localhost:3000
149+
```
150+
- Code changes on your host are reflected inside the container.
151+
- Uses bind mounts and `npm run dev`.
152+
153+
### Production
154+
```bash
155+
# Build image and start
156+
docker compose up --build -d
157+
# Tail logs
158+
docker compose logs -f
159+
# Stop
160+
docker compose down
161+
```
162+
Set required environment variables (can be .env file in project root):
163+
```bash
164+
NEXTAUTH_URL=http://localhost:3000
165+
NEXTAUTH_SECRET=replace_with_secure_random
166+
GITHUB_CLIENT_ID=your_client_id
167+
GITHUB_CLIENT_SECRET=your_client_secret
168+
```
169+
The production image uses Next.js standalone output for a small runtime.

docker-compose.dev.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
services:
2+
web:
3+
image: node:20-alpine
4+
working_dir: /app
5+
command: sh -c "npm ci && npm run dev"
6+
ports:
7+
- "3000:3000"
8+
environment:
9+
- NODE_ENV=development
10+
- NEXT_TELEMETRY_DISABLED=1
11+
- HOSTNAME=0.0.0.0
12+
volumes:
13+
- ./:/app
14+
- /app/node_modules
15+
- /app/.next
16+
restart: unless-stopped

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
web:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
target: runner
7+
image: githubmon:prod
8+
ports:
9+
- "3000:3000"
10+
environment:
11+
- NODE_ENV=production
12+
- NEXT_TELEMETRY_DISABLED=1
13+
- HOSTNAME=0.0.0.0
14+
# Map your envs; you can also use an env_file
15+
- NEXTAUTH_URL=${NEXTAUTH_URL}
16+
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
17+
- GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
18+
- GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
19+
restart: unless-stopped

package-lock.json

Lines changed: 0 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/layout/Header.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client'
22

33
import { useRouter } from 'next/navigation'
4-
import { Badge } from '@/components/ui/badge'
54
import { RateLimitWarning } from '@/components/common/RateLimitWarning'
65
import { ThemeToggle } from '@/components/theme/ThemeToggle'
76
import { useSearchStore } from '@/stores'

0 commit comments

Comments
 (0)