
# Base image
FROM php:8.1-apache

# Install system packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    # Python
    python3 python3-venv python3-pip \
    # Process supervisor
    supervisor \
    # Others
    net-tools curl less nano \
    # Clean up
    && rm -rf /var/lib/apt/lists/*

# Apache on 8069
COPY apache_ports.conf /etc/apache2/ports.conf
COPY apache_vhost.conf /etc/apache2/sites-available/000-default.conf
COPY web/ /var/www/html/

# API on 5000
RUN mkdir -p /opt/Fitness
RUN python3 -m venv /opt/Fitness/venv
COPY api/requirements.txt /opt/Fitness/
RUN /opt/Fitness/venv/bin/pip3 install --no-cache-dir -r /opt/Fitness/requirements.txt
# Copy the actual app code after installing deps
COPY api/ /opt/Fitness/

# Add supervisord configuration
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Expose ports
EXPOSE 8069

# healthcheck looks for apache
HEALTHCHECK CMD netstat -ltn | grep -c ":8069" > /dev/null; if [ 0 != $? ]; then exit 1; fi;

# Start supervisord
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]