# Multi-stage build: build library artifacts from source, then prepare a minimal runtime image
FROM node:20-slim AS builder
WORKDIR /app
# Install dependencies
COPY package.json ./
RUN npm install --legacy-peer-deps
# Copy the rest of the source
COPY . .
# Build the library artifacts
RUN npm run lib
RUN npm run lib:esm
# Final runtime image
FROM node:20-slim
WORKDIR /app
# Copy built artifacts from builder
COPY --from=builder /app/lib /app/lib
COPY --from=builder /app/esm /app/esm
# Copy entrypoint script
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
CMD ["sh", "-lc", "/usr/local/bin/entrypoint.sh"]