FROM php:8.2-cli

WORKDIR /var/www

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    unzip \
    curl \
    libzip-dev \
    zip \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libonig-dev \
    libxml2-dev \
    nodejs \
    npm \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install pdo_mysql mbstring zip exif pcntl bcmath gd
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Copy project files
COPY . .

#  ADD THIS
RUN mkdir -p storage/app/chunks \
    && chmod -R 775 storage/app

RUN echo "upload_max_filesize=100M\npost_max_size=100M" > /usr/local/etc/php/conf.d/uploads.ini

# Set permissions
RUN chmod -R 775 storage bootstrap/cache
#RUN docker-php-ext-install gd
# Install PHP & Node dependencies
RUN composer install
RUN npm install && npm run build

# Expose Laravel port
EXPOSE 8000

# Start Laravel and run setup commands when container starts
#CMD php artisan key:generate --force \
# && php artisan storage:link || true \
# && php artisan migrate --seed --force \
# && php artisan serve --host=0.0.0.0 --port=8000
# Copy the docker-entrypoint.sh script
COPY docker-entrypoint.sh /usr/local/bin/

# Set permissions for the entrypoint script
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

# Set the entrypoint to the script
ENTRYPOINT ["docker-entrypoint.sh"]

#RUN echo "upload_max_filesize=100M\npost_max_size=100M" > /usr/local/etc/php/conf.d/uploads.ini

