# Menggunakan image PHP 8.2 FPM resmi
FROM php:8.2-fpm

# Mengatur working directory
WORKDIR /var/www

# Menginstal dependensi sistem dan ekstensi PHP yang dibutuhkan Laravel
RUN apt-get update && apt-get install -y \
    build-essential \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl \
    libzip-dev \
    nginx

# Membersihkan cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Menginstal ekstensi PHP
RUN docker-php-ext-install pdo_mysql zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd

# Menginstal Composer secara langsung dari image resmi
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Menyalin seluruh kode proyek ke dalam kontainer
COPY . /var/www

# Memberikan izin akses (permissions) ke folder storage dan cache
RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache

# Menyalin konfigurasi Nginx (akan kita buat di langkah berikutnya)
COPY nginx.conf /etc/nginx/nginx.conf

# Mengekspos port 80
EXPOSE 80

# Menjalankan script PHP-FPM dan Nginx secara bersamaan
CMD service nginx start && php-fpm
