# Use official Python Alpine base image
FROM python:3.11-alpine

# Maintainer information
LABEL maintainer="Balotario Licencia A-I"
LABEL description="Interactive web application to study driving license test questions"
LABEL version="1.0.0"

# Set working directory
WORKDIR /app

# Update system packages for security (CVEs)
RUN apk update && apk upgrade --no-cache && \
    rm -rf /var/cache/apk/*

# Copy dependency files
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Create non-root user for security
RUN adduser -D -s /bin/sh app && \
    chown -R app:app /app
USER app

# Expose port
EXPOSE 5000

# Environment variables
ENV FLASK_APP=app.py
ENV FLASK_ENV=production
ENV PYTHONPATH=/app

# Docker health check command
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:5000/ || exit 1

# Default command
CMD ["python", "run.py"]
