FROM node:22-alpine AS build-stage
WORKDIR /app

# Copy dependency files
COPY package.json ./

# Install dependencies
RUN yarn install --frozen-lockfile

# Copy source and build
COPY . .
RUN yarn build

# ---- Production Stage ----
FROM node:22-alpine AS production-stage
WORKDIR /app

# Copy only necessary files
COPY --from=build-stage /app /app

# Set environment
ENV NODE_ENV=production
EXPOSE 3000

# Run with yarn
CMD ["yarn", "start"]