FROM node:18-bullseye-slim AS builder
WORKDIR /app
# Install dependencies needed for building native addons
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
python3 \
build-essential \
git \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Use a PNPM version compatible with the repository's lockfile
RUN npm i -g pnpm@9
# Copy lockfiles and manifests first to leverage Docker cache
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
# Copy the repository contents
COPY . .
# Install dependencies for the core package and build the project
RUN pnpm install
RUN pnpm run build
# Production: serve built assets with nginx
FROM nginx:1.23-alpine AS prod
# Copy the built UI assets from the builder stage
COPY --from=builder /app/packages/ctool-core/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]