# ATAPOLY CBT — App image (Node + built frontend served from backend/public)
FROM node:18-alpine

WORKDIR /app

# Install only production deps (faster, smaller image)
COPY package*.json ./
RUN npm install --omit=dev

# Copy backend source (frontend build is already in backend/public from deploy.sh)
COPY . .

# App listens on 3001
EXPOSE 3001

# Wait for DB, run migrations, then start server
CMD ["sh", "-c", "node db/init.js && node db/migrate.js && node index.js"]
