FROM php:8.4-fpm-alpine

WORKDIR /var/www

# Install system dependencies
RUN apk add --no-cache \
    git \
    curl \
    libpng-dev \
    oniguruma-dev \
    libxml2-dev \
    zip \
    unzip \
    libzip-dev \
    icu-dev

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip intl

# Clear cache
RUN rm -rf /var/cache/apk/*

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

# Copy application files and fix permissions
COPY . /var/www
RUN chown -R www-data:www-data /var/www && \
    find /var/www -type d -exec chmod 755 {} + && \
    find /var/www -type f -exec chmod 644 {} + && \
    rm -rf /var/www/.circleci /var/www/.github

USER www-data

EXPOSE 8000

CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8000"]