# OweMe: one image with the server (Node standard library only, no
# node_modules) and the built web client. Build context: the repo root.

FROM docker.io/library/node:24.21.0-alpine AS build
WORKDIR /src
COPY package.json package-lock.json ./
COPY packages/core/package.json packages/core/
COPY apps/web/package.json apps/web/
# --ignore-scripts: no install hooks from dependencies run during the build.
RUN npm ci --no-audit --no-fund --ignore-scripts
COPY packages/core packages/core
COPY apps/web apps/web
RUN npm run build -w apps/web

FROM docker.io/library/node:24.21.0-alpine
WORKDIR /app
ENV NODE_ENV=production \
    HOST=0.0.0.0 \
    PORT=8080 \
    DATA_DIR=/data \
    STATIC_DIR=/app/web \
    TRUST_PROXY=1
COPY apps/server/src ./server
COPY --from=build /src/apps/web/dist ./web
RUN mkdir -p /data && chown node:node /data
USER node
VOLUME /data
EXPOSE 8080
CMD ["node", "--disable-warning=ExperimentalWarning", "server/main.ts"]
