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
18 changes: 5 additions & 13 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,30 @@ FROM node:20-alpine AS builder

WORKDIR /app

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

# Instalar dependencias
RUN npm ci

# Copiar código fuente
COPY . .

# Build
RUN npm run build

# Test stage (para CI/CD)
FROM builder AS test
CMD ["npm", "test"]

# Production stage
FROM node:20-alpine
FROM node:20-alpine AS production

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
Expand Down
49 changes: 49 additions & 0 deletions backend/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
services:
nestjs-test:
build:
context: ./backend
dockerfile: Dockerfile
target: test # 🔥 Usa el stage "test"
environment:
DB_HOST: postgres
DB_PORT: "5432"
DB_NAME: "${DB_NAME}"
DB_USER: "${DB_USER}"
DB_PASSWORD: "${DB_PASSWORD}"
REDIS_HOST: redis
REDIS_PORT: "6379"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- my_network

postgres:
image: postgres:14-alpine
environment:
POSTGRES_USER: "${DB_USER}"
POSTGRES_PASSWORD: "${DB_PASSWORD}"
POSTGRES_DB: "${DB_NAME}"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
interval: 5s
timeout: 3s
retries: 3
networks:
- my_network

redis:
image: redis:7-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 3
networks:
- my_network

networks:
my_network:
driver: bridge
Loading