# ABOUTME: Multi-stage Docker build for Express API
# ABOUTME: Creates minimal production image with compiled TypeScript

# Build stage
FROM public.ecr.aws/docker/library/node:20-alpine AS builder

WORKDIR /app

RUN corepack enable

COPY package.json ./
RUN {{installCommand}}

COPY tsconfig.json ./
COPY *.ts ./
RUN {{runScriptPrefix}} build

# Production stage
FROM public.ecr.aws/docker/library/node:20-alpine

WORKDIR /app

RUN corepack enable

# Copy package files and install production dependencies only
COPY package.json ./
RUN {{installProdCommand}}

# Copy compiled JavaScript from builder
COPY --from=builder /app/dist ./dist

# Run as non-root user for security
USER node

EXPOSE 8080

CMD ["node", "dist/index.js"]
