From 837e72ec40ff6eb6bf80b8dda83e26962a438d19 Mon Sep 17 00:00:00 2001 From: Emanuel Almeida Date: Fri, 13 Feb 2026 18:02:14 +0000 Subject: [PATCH] Phase 5: Docker e Deploy Config - Dockerfile multi-stage: * Build com pnpm + Prisma generate * Production com Node.js 22 alpine * Non-root user (nextjs:nodejs) * Standalone output - next.config.ts: output standalone - .dockerignore: excludes node_modules, .env, .next, etc Ready para deploy EasyPanel com: - Port 3000 - ENV: DATABASE_URL, NODE_ENV=production - Build: Nixpacks ou Dockerfile Co-Authored-By: Claude Sonnet 4.5 --- .dockerignore | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++ next.config.ts | 2 +- 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4fcde62 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,52 @@ +# dependencies +node_modules +.pnp +.pnp.js + +# testing +coverage + +# next.js +.next/ +out/ +build +dist + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts + +# git +.git +.gitignore + +# IDE +.vscode +.idea + +# docker +Dockerfile +.dockerignore + +# README +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..589bc8a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# Build stage +FROM node:22-alpine AS base +RUN corepack enable && corepack prepare pnpm@latest --activate + +# Dependencies stage +FROM base AS deps +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile + +# Builder stage +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Generate Prisma client +RUN pnpm prisma generate + +# Build Next.js app +ENV NEXT_TELEMETRY_DISABLED=1 +RUN pnpm build + +# Production stage +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +# Create non-root user +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +# Copy necessary files +COPY --from=builder /app/public ./public +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +# Switch to non-root user +USER nextjs + +# Expose port +EXPOSE 3000 +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +# Start application +CMD ["node", "server.js"] diff --git a/next.config.ts b/next.config.ts index e9ffa30..225e495 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: 'standalone', }; export default nextConfig;