ARG PHP_VERSION
FROM dunglas/frankenphp:php${PHP_VERSION}-alpine

# add additional extensions here:
RUN install-php-extensions \
    pdo_mysql \
    mysqli \
    gd \
    imagick \
    intl \
    zip \
    bcmath \
    soap \
    sqlite3 \
    mbstring \
    curl \
    xml \
    dom \
    fileinfo \
    opcache \
    ctype \
    iconv \
    openssl \
    tokenizer \
    simplexml \
    xsl \
    exif \
    sodium \
	redis \
    apcu

# Install Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs
	
# Fix permissions for storage & cache (FrankenPHP runs as UID 65534 = nobody)
RUN if [ -d /app/storage ]; then chown -R 65534:65534 /app/storage /app/bootstrap/cache; fi

ARG MODE
# production mode: direct run container on server
RUN if [ "$MODE" = "prod" ]; then \
	# Enable PHP production settings
	mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
fi
