FROM node:20-alpine

WORKDIR /app

# Install dependencies
RUN apk add --no-cache curl unzip

# Copy package files
COPY package*.json ./

# Copy setup script (needed for postinstall)
COPY setup-h5p.js ./

# Install npm packages (postinstall will run setup-h5p.js)
RUN npm install --production

# Copy application code
COPY . .

# Create directories for H5P content
RUN mkdir -p h5p-content h5p-libraries h5p-temp h5p-core

# Expose port
EXPOSE 8080

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8080/health || exit 1

# Start server (using simplified version for now)
CMD ["node", "server-simple.js"]
