# Use the official PHP image
FROM php:8.3.6-fpm

# Install dependencies
RUN apt-get update && apt-get install -y \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libzip-dev \
    unzip \
    supervisor \
    openssl \
    git \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install gd zip pdo pdo_mysql

# Set the working directory
WORKDIR /var/www

# Copy the application code
COPY . .

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Install PHP dependencies
RUN composer install --no-interaction --optimize-autoloader

# Copy the SSL certificates
COPY ./certs/selfsigned.crt /etc/ssl/certs/selfsigned.crt
COPY ./certs/selfsigned.key /etc/ssl/private/selfsigned.key

# Copy the Supervisor configuration file
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Expose the HTTPS port
EXPOSE 8011

# Command to run Supervisor
CMD ["/usr/bin/supervisord"]
