FROM php:8.4-cli-alpine

# Install system dependencies and build libraries
RUN apk add --no-cache \
    curl \
    libpng-dev \
    libxml2-dev \
    zip \
    unzip \
    git \
    nodejs \
    npm \
    autoconf \
    g++ \
    make \
    linux-headers

# Install core PHP extensions
RUN docker-php-ext-install pdo_mysql bcmath gd xml

# Install high-performance Swoole (Octane) & Redis extensions from PECL
RUN pecl install swoole redis && \
    docker-php-ext-enable swoole redis

# Inject standard composer binary
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www/html

# Copy application files
COPY . .

# Run production composer setup
RUN composer install --no-dev --optimize-autoloader

# Build static PWA assets
RUN npm install && npm run build

# Expose Swoole Octane port (8000) and Reverb WebSocket port (8080)
EXPOSE 8000 8080

# Default command to boot the high-performance Laravel Octane engine using Swoole
CMD ["php", "artisan", "octane:start", "--server=swoole", "--host=0.0.0.0", "--port=8000"]
