FROM node:24-alpine

WORKDIR /usr/src/app

# Install SQLite for database operations (needed for testing/debugging)
RUN apk add --no-cache sqlite

# Copy package.json and package-lock.json (if available)
COPY backend/package*.json ./

# Install dependencies
RUN npm install --production

# Copy the source code
COPY backend/src ./src

# Copy production environment configuration
COPY docker/prod/backend/config/.env ./.env

# Create data directories for file storage
RUN mkdir -p src/data/images src/data/previews src/data/groups

# Expose port 5000
EXPOSE 5000

# Start the application
CMD ["node", "src/index.js"]