# Base stage
FROM node:18-alpine AS base
# Environment variables for pnpm
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN apk update && apk add --no-cache libc6-compat
RUN corepack enable
# Pruning stage
FROM base AS pruner
WORKDIR /app
COPY . .
# Install Turbo globally
RUN pnpm add -g turbo
RUN turbo prune scan-service --docker
# Development dependencies stage
FROM base AS dev-deps
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install
# Production dependencies stage
FROM base AS prod-deps
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install
# Build stage
FROM base AS builder
WORKDIR /app
COPY --from=dev-deps /app/ .
COPY --from=pruner /app/out/full/ .
COPY turbo.json* ./
RUN pnpm turbo run build --filter=scan-service...
# Runner stage
FROM base AS runner
WORKDIR /app
COPY --from=prod-deps /app/ .
COPY --from=builder /app/apps/scan-service/dist/ ./apps/scan-service/dist/
# Expose port 3000
EXPOSE 3000
# Command to run the application
CMD ["pnpm", "start"]