# Build context: services/astro. Deployment remains gated by licence and secrets.
FROM node:22-bookworm-slim AS build
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends python3 make g++ && rm -rf /var/lib/apt/lists/*
COPY package.json package-lock.json ./
RUN npm ci --omit=dev

FROM node:22-bookworm-slim
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends gosu && rm -rf /var/lib/apt/lists/*
COPY --from=build /app/node_modules ./node_modules
COPY package.json ./
COPY src ./src
COPY entrypoint.sh ./entrypoint.sh
RUN chmod 755 /app/entrypoint.sh
ENV NODE_ENV=production ASTRO_ENGINE_HOST=0.0.0.0 ASTRO_ENGINE_DATA_DIR=/data/astro PORT=8787
ENV ASTRO_ENGINE_CONCURRENCY=1 ASTRO_ENGINE_MAX_PENDING=200
EXPOSE 8787
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT+'/healthz',{headers:{'x-engine-key':process.env.ASTRO_ENGINE_API_KEY},signal:AbortSignal.timeout(4000)}).then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
ENTRYPOINT ["/app/entrypoint.sh"]
