Skip to content

Commit 3dceb1c

Browse files
authored
Merge pull request #82 from HazarBakir/main
feat(docker): dockerize app with dev compose and docs
2 parents c505f6c + e4b67c0 commit 3dceb1c

File tree

8 files changed

+150
-128
lines changed

8 files changed

+150
-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"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 HappyHackingSpace
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,40 @@ 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+
# Start dev container (no image build needed)
147+
docker compose -f docker-compose.dev.yml up
148+
# Then open http://localhost:3000
149+
```
150+
- Create `.env.local` in the project root with at least:
151+
```bash
152+
NEXTAUTH_SECRET=your_secure_secret
153+
NEXTAUTH_URL=http://localhost:3000
154+
GITHUB_CLIENT_ID=your_client_id
155+
GITHUB_CLIENT_SECRET=your_client_secret
156+
```
157+
- Code changes on your host are reflected inside the container.
158+
- Uses bind mounts and `npm run dev`.
159+
160+
### Production
161+
```bash
162+
# Build image and start
163+
docker compose up --build -d
164+
# Tail logs
165+
docker compose logs -f
166+
# Stop
167+
docker compose down
168+
```
169+
Set required environment variables (can be .env file in project root):
170+
```bash
171+
NEXTAUTH_URL=http://localhost:3000
172+
NEXTAUTH_SECRET=replace_with_secure_random
173+
GITHUB_CLIENT_ID=your_client_id
174+
GITHUB_CLIENT_SECRET=your_client_secret
175+
```
176+
Note: a default `NEXTAUTH_SECRET` is set only during the image build to allow Next.js to compile. You must provide real secrets at runtime via `.env` or your deployment platform.

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)