# Runs only on the Raspberry Pi storage node — see docs/PROJECT_PLAN.md §50.
# node:22-alpine has official arm64 builds, which matters here.
FROM node:22-alpine AS build

WORKDIR /app
COPY package*.json ./
RUN npm ci

COPY tsconfig.json tsconfig.build.json ./
COPY src ./src
RUN npm run build

# --- Runtime stage: no dev deps, no TypeScript toolchain -----------------
FROM node:22-alpine

WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev

COPY --from=build /app/dist ./dist

# Overridden by HOST/PORT env vars — see docker-compose.pi.yml. Defaults
# here are loopback-safe; binding wider is an explicit operator choice.
ENV HOST=127.0.0.1
ENV PORT=9200
EXPOSE 9200

CMD ["node", "dist/server.js"]
