-
Notifications
You must be signed in to change notification settings - Fork 0
chore(docker): configure docker build and deployment #24
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| .next | ||
| .git | ||
| .gitignore | ||
| .eslintignore | ||
| .prettierignore | ||
| node_modules | ||
| npm-debug.log | ||
| yarn-debug.log | ||
| yarn-error.log | ||
| .env | ||
| .env.example | ||
| .env.local | ||
| .env.*.local | ||
| .DS_Store | ||
| .vscode | ||
| .idea | ||
| *.md | ||
| !README.md | ||
| .turbo | ||
| .cache | ||
| dist | ||
| build | ||
| coverage | ||
| .husky |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Stage 1: Builder | ||
| FROM node:24-alpine AS builder | ||
| RUN apk add --no-cache libc6-compat curl | ||
| WORKDIR /app | ||
|
|
||
| COPY package.json package-lock.json ./ | ||
| RUN npm ci --ignore-scripts --no-fund --no-audit | ||
|
|
||
| COPY . . | ||
|
|
||
| # Check that output: 'standalone' is enabled (not commented) | ||
| RUN grep -E "^\s*output:" next.config.ts | grep -q "standalone" || (echo "ERROR: next.config.ts must have output: 'standalone' enabled" && exit 1) | ||
|
|
||
| # Ensure public directory exists (required for COPY in runtime stage) | ||
| RUN mkdir -p public | ||
|
|
||
| ENV NODE_ENV=production | ||
| RUN npm run build && \ | ||
| curl -sf https://gobinaries.com/tj/node-prune | sh && \ | ||
| node-prune .next/standalone/node_modules | ||
|
|
||
|
|
||
| # Stage 2: Runtime (distroless) | ||
| FROM gcr.io/distroless/nodejs24-debian12:nonroot | ||
| WORKDIR /app | ||
|
|
||
| ENV NODE_ENV=production \ | ||
| PORT=3000 \ | ||
| HOSTNAME=0.0.0.0 | ||
|
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding runtime configuration like |
||
|
|
||
| # Copy optimized build output | ||
| COPY --from=builder --chown=nonroot:nonroot /app/.next/standalone ./ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| COPY --from=builder --chown=nonroot:nonroot /app/.next/static ./.next/static | ||
| COPY --from=builder --chown=nonroot:nonroot /app/public ./public | ||
|
|
||
| USER nonroot | ||
| EXPOSE 3000 | ||
|
|
||
| CMD ["server.js"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| app: | ||
| container_name: next-template | ||
| build: . | ||
| init: true | ||
|
|
||
| ports: | ||
| - '3000:3000' | ||
|
|
||
| environment: | ||
| NODE_ENV: production | ||
| HOSTNAME: 0.0.0.0 | ||
| PORT: 3000 | ||
| # Uncomment to enable persistent file storage | ||
| # volumes: | ||
| # - ./data:/app/data | ||
|
|
||
| restart: unless-stopped |
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.
Piping
curltoshfrom a URL is a security risk as it executes remote code without verification. For improved security and reproducibility, it's better to download a specific, versioned release ofnode-prunefrom its official GitHub repository.