From 1d78ea599a05c3fc74918e3797029c2d64b5c923 Mon Sep 17 00:00:00 2001 From: Emmanuel Rojas Date: Tue, 6 Oct 2026 02:03:43 -0500 Subject: [PATCH] docker --- .dockerignore | 9 +++++++++ Dockerfile | 40 ++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 26 ++++++++++++++++++++++++++ next-env.d.ts | 4 ++-- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6ffed73 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +node_modules +.next +.git +.env*.local +.env.local +.DS_Store +npm-debug.log* +.claude +*.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f2da5fc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# syntax=docker/dockerfile:1 + +# ---- deps: instala dependencias (capa cacheable) ---- +FROM node:22-alpine AS deps +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm ci + +# ---- build: compila Next.js en modo standalone ---- +FROM node:22-alpine AS build +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Variables NEXT_PUBLIC_* se incrustan en el bundle del cliente en build-time, +# por eso llegan como build-arg (desde docker-compose) y no solo como env de +# runtime del contenedor final. +ARG NEXT_PUBLIC_API_URL +ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN npm run build + +# ---- runtime: imagen final mínima (next.config.ts tiene output: "standalone") ---- +FROM node:22-alpine AS runtime +WORKDIR /app +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 +ENV PORT=3000 +ENV HOSTNAME=0.0.0.0 + +RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001 +USER nextjs + +COPY --from=build --chown=nextjs:nodejs /app/public ./public +COPY --from=build --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=build --chown=nextjs:nodejs /app/.next/static ./.next/static + +EXPOSE 3000 +ENTRYPOINT ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..64a3285 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +# Levanta solo el frontend (Next.js). El backend (Internal-API) tiene su +# propio docker-compose.yml en ese repositorio. +# +# NEXT_PUBLIC_API_URL se necesita en BUILD time (Next.js lo incrusta en el +# bundle del cliente), así que viene de `build.args`, no solo de `environment`. +# Docker Compose solo autocarga un archivo llamado ".env" en este mismo +# directorio para resolver los ${...} de este archivo — como aquí usamos +# ".env.production", hay que decírselo explícitamente al levantar: +# +# docker compose --env-file .env.production up -d --build +# +# (o copia/renombra .env.production a .env si prefieres el comportamiento +# por defecto de `docker compose up`). + +services: + web: + build: + context: . + dockerfile: Dockerfile + args: + NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:?Define NEXT_PUBLIC_API_URL (en .env.production) con la URL pública del backend} + env_file: + - .env.production + ports: + - "${FRONTEND_PORT:-3000}:3000" + restart: unless-stopped diff --git a/next-env.d.ts b/next-env.d.ts index a419cbe..ce4e94a 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,7 +1,7 @@ /// /// -import "./.next/dev/types/routes.d.ts"; -import "./.next/dev/types/root-params.d.ts"; +import "./.next/types/routes.d.ts"; +import "./.next/types/root-params.d.ts"; // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.