FROM node:20-slim

WORKDIR /app

# Install native build tools needed for better-sqlite3
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3 make g++ \
    && rm -rf /var/lib/apt/lists/*

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

COPY index.js ./

# Download script — runs once at startup if DB is missing
COPY start.sh ./
RUN chmod +x start.sh

EXPOSE 3000

ENTRYPOINT ["./start.sh"]
