opnform-host-nginx/docker/Dockerfile.api

91 lines
2.5 KiB
Docker

FROM php:8.3-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y \
libzip-dev \
libpng-dev \
postgresql-client \
libpq-dev \
unzip \
gcc \
make \
autoconf \
libc-dev \
pkg-config \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER=1
# Install PHP extensions
ENV CFLAGS="-O1 -D_GNU_SOURCE" \
CXXFLAGS="-O1 -D_GNU_SOURCE"
# Install basic extensions first
RUN set -eux; \
docker-php-ext-install -j$(nproc) pdo zip && \
php -m | grep -E 'pdo|zip'
# Install GD
RUN set -eux; \
docker-php-ext-install -j$(nproc) gd && \
php -m | grep -E 'gd'
# Install PostgreSQL related extensions
RUN set -eux; \
docker-php-ext-configure pgsql && \
docker-php-ext-install -j$(nproc) pgsql pdo_pgsql && \
php -m | grep -E 'pgsql|pdo_pgsql'
# Install bcmath with optimization flags for stability
RUN set -eux; \
docker-php-ext-install -j1 bcmath && \
php -m | grep -E 'bcmath'
# Install Redis extension
RUN set -eux; \
pecl install -f --configureoptions 'enable-redis-igbinary="no" enable-redis-lzf="no" enable-redis-zstd="no" enable-redis-msgpack="no" enable-redis-lz4="no"' redis && \
docker-php-ext-enable redis && \
php -m | grep -E 'redis'
WORKDIR /usr/share/nginx/html/
# Create storage directories
RUN mkdir -p storage/framework/sessions \
storage/framework/views \
storage/framework/cache \
storage/logs \
storage/app/public \
bootstrap/cache \
&& chown -R www-data:www-data storage bootstrap/cache \
&& chmod -R 775 storage bootstrap/cache
# Copy composer files and helpers.php first
COPY api/composer.json api/composer.lock ./
COPY api/app/helpers.php ./app/helpers.php
# Default to production settings unless overridden during build
ARG APP_ENV=production
ARG COMPOSER_FLAGS=--no-dev --optimize-autoloader --no-interaction
# Install dependencies without running scripts
RUN composer install ${COMPOSER_FLAGS} --no-scripts --ignore-platform-req=php
# Copy the rest of the application
COPY api/ .
# Run composer scripts and clear cache
RUN composer dump-autoload -o \
&& php artisan package:discover --ansi \
&& composer clear-cache \
&& chmod -R 775 storage \
&& chown -R www-data:www-data storage
# Setup entrypoint
COPY docker/php-fpm-entrypoint /usr/local/bin/opnform-entrypoint
RUN chmod a+x /usr/local/bin/*
ENTRYPOINT ["/usr/local/bin/opnform-entrypoint"]
CMD ["php-fpm"]