# Multi-stage Dockerfile for production deployment
FROM node:18-alpine AS base

# Production stage

# Backend stage
FROM base AS backend
WORKDIR /app/backend
COPY backend/package*.json ./
RUN npm install --omit=dev

# Frontend build stage
FROM base AS frontend-build
WORKDIR /app/frontend
COPY frontend/package.json ./package.json
COPY frontend/tsconfig.json ./tsconfig.json
COPY frontend/tailwind.config.js ./tailwind.config.js
COPY frontend/postcss.config.js ./postcss.config.js
RUN npm install
COPY frontend/public ./public
COPY frontend/src ./src
COPY frontend/fonts ./fonts
RUN npm run build

# Production stage
FROM base AS production
WORKDIR /app

# Copy backend
COPY backend ./backend
COPY --from=backend /app/backend/node_modules ./backend/node_modules

# Copy logos and fonts folders for frontend
COPY frontend/logos ./frontend/logos
COPY frontend/fonts ./frontend/fonts

# Copy built frontend
COPY --from=frontend-build /app/frontend/build ./frontend/build

# Copy docker-compose configuration
COPY docker-compose.yml ./

# Copy ESV Bible data from repository
COPY ESV /app/ESV

# Copy NKJV Bible data from repository
COPY NKJV /app/NKJV

# Copy NLT Bible data from repository
COPY NLT /app/NLT

# Copy CSB Bible data from repository
COPY CSB /app/CSB

# Expose port
EXPOSE 3000

# Start backend server
WORKDIR /app/backend
CMD ["npm", "start"]
