FROM node:20-alpine AS base

WORKDIR /app

RUN apk add --no-cache python3 make g++ su-exec \
  && npm install --global npm@latest

COPY package*.json tsconfig.json ./

RUN npm install

COPY src ./src

RUN npm run build

RUN addgroup -S appuser && adduser -S -G appuser appuser \
  && mkdir -p /app/data \
  && chown -R appuser:appuser /app

COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

EXPOSE 8000

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["node", "dist/index.js"]
