
# 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 \
    # PHP extensions needed by the OIDC helpers
    libzip-dev libpng-dev libicu-dev libpq-dev \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install zip \
    && docker-php-ext-install intl \
    # Clean up
    && rm -rf /var/lib/apt/lists/*

# -------------------------------------------------------------
# Install Composer (stand‑alone)
# -------------------------------------------------------------
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# 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/
# Set up composer
WORKDIR /var/www/html/
RUN composer require jumbojett/openid-connect-php
RUN composer install --no-dev --optimize-autoloader --no-interaction

# 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
EXPOSE 5000

# 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"]