diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ed6fb30 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +node_modules +.next +.git +.gitignore +npm-debug.log* +Dockerfile +.dockerignore +README.md +.env* +settings.json +.vscode +.idea +*.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..67221cb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# syntax=docker/dockerfile:1 + +# ============================================================ +# Multi-stage build para Next.js 16 (output: standalone). +# Bem mais rápido que Nixpacks: o stage de deps fica em cache e +# só reinstala quando package*.json muda. +# ============================================================ + +# ---- deps: instala dependências (camada cacheável) ---- +FROM node:22-alpine AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci + +# ---- builder: faz o next build ---- +FROM node:22-alpine AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +ENV NEXT_TELEMETRY_DISABLED=1 +RUN npm run build + +# ---- runner: imagem final enxuta ---- +FROM node:22-alpine AS runner +WORKDIR /app +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +ENV PORT=3000 +ENV HOSTNAME=0.0.0.0 + +RUN addgroup --system --gid 1001 nodejs \ + && adduser --system --uid 1001 nextjs \ + # /app precisa ser gravável pelo usuário nextjs: o app salva settings.json + # no diretório de trabalho em runtime. + && chown nextjs:nodejs /app + +# public/ e .next/static não vão no standalone por padrão — copiamos à mão. +COPY --from=builder --chown=nextjs:nodejs /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs +EXPOSE 3000 + +# server.js é gerado pelo output standalone do Next. +CMD ["node", "server.js"] diff --git a/next.config.ts b/next.config.ts index e9ffa30..a4adbe8 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,9 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + // Gera .next/standalone com só o necessário — imagem Docker bem menor e + // deploy mais rápido (não precisa instalar node_modules no runtime). + output: 'standalone', }; export default nextConfig;