# Multi-stage build for Oltalama application # Stage 1: Build frontend FROM node:20-alpine AS frontend-builder WORKDIR /app/frontend # Copy frontend package files COPY frontend/package*.json ./ # Install frontend dependencies RUN npm ci # Copy frontend source COPY frontend/ ./ # Build frontend (output will be in dist/) RUN npm run build # Stage 2: Backend + Runtime FROM node:20-alpine WORKDIR /app # Install system dependencies for sqlite3 RUN apk add --no-cache python3 make g++ sqlite # Copy backend package files COPY backend/package*.json ./ # Install backend dependencies RUN npm ci --only=production # Copy backend source COPY backend/ ./ # Copy frontend build from previous stage to backend public directory COPY --from=frontend-builder /app/frontend/dist ./src/public/dist # Create database directory RUN mkdir -p database # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" # Start script that runs migrations and seeds before starting the server COPY docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh ENTRYPOINT ["docker-entrypoint.sh"] CMD ["node", "src/app.js"]