FROM node:20-alpine

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Copy environment files for production
COPY .env.production ./

# Install dependencies
RUN npm ci --only=production

# Copy source code
COPY src ./src
COPY app.js .
COPY healthcheck.js .

# Create uploads directory
RUN mkdir -p uploads/images uploads/signatures

# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001

# Change ownership of the app directory
RUN chown -R nodejs:nodejs /app
USER nodejs

# Expose port
EXPOSE 3000

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD node healthcheck.js

# Start the application
CMD ["node", "app.js"] 