FROM node:22-alpine
WORKDIR /app

COPY dist ./dist

COPY package.json ./
RUN node -e " \
  const p = JSON.parse(require('fs').readFileSync('./package.json', 'utf8')); \
  p.dependencies = Object.fromEntries( \
    Object.entries(p.dependencies || {}).filter(([k]) => !k.startsWith('@lilith/')) \
  ); \
  delete p.devDependencies; \
  require('fs').writeFileSync('./package.json', JSON.stringify(p, null, 2)); \
" && npm install --production --ignore-scripts

COPY .vendor-lilith/ ./node_modules/

EXPOSE 4003
USER node
CMD ["node", "dist/main.js"]
