Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
FROM node:latest
# Build stage
FROM node:20-alpine AS builder

WORKDIR /app

# Copiar archivos de dependencias
COPY package*.json ./

RUN yarn install
# Instalar dependencias
RUN npm ci

# Copiar código fuente
COPY . .

RUN yarn build
# Build
RUN npm run build

# Production stage
FROM node:20-alpine

WORKDIR /app

# Crear usuario no-root
RUN addgroup -g 1001 -S nodejs && \
adduser -S nestjs -u 1001

# Copiar package.json
COPY package*.json ./

# Instalar SOLO dependencias de producción
RUN npm ci --only=production && \
npm cache clean --force

# Copiar build desde stage anterior
COPY --from=builder /app/dist ./dist

# Cambiar a usuario no-root
USER nestjs

EXPOSE 3000

CMD ["yarn", "start:prod"]
CMD ["node", "dist/main"]
45 changes: 33 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ services:
build:
context: ./backend
dockerfile: Dockerfile
restart: unless-stopped
ports:
- "3001:3000"
environment:
Expand All @@ -25,52 +26,72 @@ services:
condition: service_healthy
networks:
- my_network
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"]
interval: 30s
timeout: 3s
retries: 3
start_period: 40s

nextjs:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: nextjs_app
restart: unless-stopped
ports:
- "3000:3000"
environment:
BASE_API_URL: "http://nestjs:3000"
NEXT_PUBLIC_API_URL: "http://localhost:3001"
depends_on:
- nestjs
nestjs:
condition: service_healthy
networks:
- my_network
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 40s

postgres:
image: postgres:14.3
ports:
- "5432:5432"
image: postgres:14-alpine # 🔥 50% más pequeña
restart: unless-stopped
# Solo exponer si necesitas acceso directo desde tu máquina
# ports:
# - "5432:5432"
environment:
POSTGRES_USER: "${DB_USER}"
POSTGRES_PASSWORD: "${DB_PASSWORD}"
POSTGRES_DB: "${DB_NAME}"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"]
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
interval: 10s
timeout: 5s
retries: 5
timeout: 3s
retries: 3
start_period: 10s
networks:
- my_network

redis:
image: redis:7-alpine
ports:
- "6379:6379"
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
restart: unless-stopped
# Solo exponer si necesitas acceso directo desde tu máquina
# ports:
# - "6379:6379"
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru --save ""
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
timeout: 3s
retries: 3
start_period: 5s
networks:
- my_network

Expand Down
36 changes: 32 additions & 4 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
FROM node:latest
# Dependencies stage
FROM node:20-alpine AS deps

WORKDIR /app

COPY package*.json ./
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

RUN yarn install
# Builder stage
FROM node:20-alpine AS builder

WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules
COPY . .

ENV NEXT_TELEMETRY_DISABLED=1

RUN yarn build

# Production stage
FROM node:20-alpine AS runner

WORKDIR /app

ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup -g 1001 -S nodejs && \
adduser -S nextjs -u 1001

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

USER nextjs

EXPOSE 3000

CMD ["yarn", "start"]
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"

CMD ["node", "server.js"]
1 change: 1 addition & 0 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const withPWA = withPWAInit({

/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
typescript: {
ignoreBuildErrors: true,
},
Expand Down
Loading