# Use an official PHP runtime as a parent image
FROM php:8.1-fpm

# Set the working directory to /var/www/html
WORKDIR /var/www/html

# Install any needed extensions
RUN docker-php-ext-install pdo pdo_mysql

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

RUN curl -sL https://deb.nodesource.com/setup_18.x
RUN apt-get install -y nodejs npm

# Install Composer globally
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install Supervisor for process control
RUN apt-get update && apt-get install -y supervisor && \
    mkdir -p /var/log/supervisor
# Copy the application code into the container
COPY . /var/www

# Set working directory
WORKDIR /var/www

USER $user

# Run Composer install and other necesary commands
RUN composer install --ignore-platform-reqs
RUN chmod -R 777 /var
RUN cd /var/www \
    php artisan key:generate \
    php artisan storage:link \
    npm install \
    npm run build
