build: Dockerfile multi-stage + Next standalone (deploy mais rápido)
Substitui o build via Nixpacks (lento, sem cache de deps) por um Dockerfile multi-stage com output: 'standalone'. O stage de deps fica em cache e só reinstala quando package*.json muda; imagem final enxuta roda node server.js. Trocar o build pack do Coolify para Dockerfile. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
87fdacfb3d
commit
f2d3f34bbf
3 changed files with 63 additions and 1 deletions
13
.dockerignore
Normal file
13
.dockerignore
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
node_modules
|
||||||
|
.next
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
npm-debug.log*
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
README.md
|
||||||
|
.env*
|
||||||
|
settings.json
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
*.log
|
||||||
47
Dockerfile
Normal file
47
Dockerfile
Normal file
|
|
@ -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"]
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
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;
|
export default nextConfig;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue