FROM node:22-bookworm-slim AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --ignore-scripts --no-audit --no-fund
COPY frontend ./frontend
COPY shared ./shared
COPY public ./public
COPY index.html vite.config.ts tsconfig.json tailwind.config.js postcss.config.js ./
RUN npm run typecheck && npm run build

FROM node:22-bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY server ./server
COPY LICENSE.txt NOTICES.md ./
ENV HOST=0.0.0.0 PORT=8118
USER node
EXPOSE 8118
CMD ["node", "server/index.mjs"]
