FROM node:26-bookworm-slim
# Debian base (not Alpine) — @typescript/native-preview ships glibc-linked
# binaries with no musl variant. Alpine would fail to load tsgo.
RUN apt-get update && apt-get install -y --no-install-recommends openssl ca-certificates wget \
  && rm -rf /var/lib/apt/lists/*
WORKDIR /app

# Copy entire monorepo structure for workspace resolution
COPY package.json ./package.json
COPY .npmrc ./.npmrc
COPY packages/ ./packages/
COPY apps/claw-client-logs-service/ ./apps/claw-client-logs-service/

# Install workspace deps FIRST so all @types/* are hoisted at root AND all
# @claw/* workspace packages get symlinked into /app/node_modules. Also pulls
# @typescript/native-preview-linux-x64 (glibc binary) via the typescript alias.
WORKDIR /app
RUN npm install --ignore-scripts

# Compile shared packages with workspace-hoisted types available
RUN cd packages/shared-types && npx tsgo
RUN cd packages/shared-constants && npx tsgo
RUN cd packages/shared-rabbitmq && npx tsgo
RUN cd packages/shared-auth && npx tsgo
RUN cd packages/shared-utilities && npx tsgo

WORKDIR /app/apps/claw-client-logs-service
RUN chmod +x docker-entrypoint.dev.sh

EXPOSE 4010
CMD ["./docker-entrypoint.dev.sh"]
