FROM composer:2 AS composer_bin

FROM php:8.2-apache

WORKDIR /var/www/tempmailer-vendor.local/public_html
COPY . .

RUN useradd -ms /bin/bash ubuntu

# Update apt-get and install dependencies
RUN apt-get update \
    && apt-get install -y libzip-dev \
    && docker-php-ext-install zip

# Install composer
COPY --from=composer_bin /usr/bin/composer /usr/local/bin/composer

# Set up apache
RUN mkdir /var/www/tempmailer-vendor.local/logs && chmod -R 777 /var/www/tempmailer-vendor.local/logs
RUN touch /var/www/tempmailer-vendor.local/logs/access.log && touch /var/www/tempmailer-vendor.local/logs/access.log
RUN touch /var/www/tempmailer-vendor.local/logs/error.log && touch /var/www/tempmailer-vendor.local/logs/error.log

RUN cp apache2-config/tempmailer-vendor.conf /etc/apache2/sites-available/tempmailer-vendor.conf
RUN a2ensite tempmailer-vendor.conf
RUN a2enmod rewrite

RUN chown -R ubuntu:root /var/www/tempmailer-vendor.local

USER ubuntu
RUN cp .env.example .env && composer install