# --- build stage ---
FROM node:24-slim AS build
WORKDIR /app
# build tools for better-sqlite3 if a prebuilt binary isn't available
RUN apt-get update && apt-get install -y --no-install-recommends python3 make g++ \
	&& rm -rf /var/lib/apt/lists/*
COPY package.json package-lock.json* ./
RUN npm install
COPY . .
RUN npm run build && npm prune --omit=dev

# --- runtime stage ---
FROM node:24-slim
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV DB_PATH=/data/toknmtr.db
COPY --from=build /app/build ./build
COPY --from=build /app/node_modules ./node_modules
COPY package.json ./
VOLUME /data
EXPOSE 3000
CMD ["node", "build"]
