opnform-host-nginx/docker/Dockerfile.api

67 lines
1.7 KiB
Docker

# Stage 1: Composer dependencies
FROM composer:latest as composer
WORKDIR /app
COPY api/composer.* ./
ARG APP_ENV=production
RUN if [ "$APP_ENV" = "production" ]; then \
composer install --ignore-platform-req=php --no-dev --optimize-autoloader; \
else \
composer install --ignore-platform-req=php --optimize-autoloader; \
fi
# Stage 2: Final image
FROM php:8.3-fpm
# Install system dependencies and PHP extensions
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
libpq-dev \
&& docker-php-ext-install pdo_pgsql mbstring exif pcntl bcmath gd \
&& pecl install redis \
&& docker-php-ext-enable redis
# Install xdebug if not in production
ARG APP_ENV=production
RUN if [ "$APP_ENV" != "production" ]; then \
pecl install xdebug && \
docker-php-ext-enable xdebug; \
fi
# Configure PHP
COPY docker/php/php.ini /usr/local/etc/php/conf.d/app.ini
COPY docker/php/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf
WORKDIR /usr/share/nginx/html
# Copy application files
COPY api/artisan artisan
COPY api/bootstrap ./bootstrap
COPY api/config ./config
COPY api/app ./app
COPY api/database ./database
COPY api/public ./public
COPY api/routes ./routes
COPY api/tests ./tests
COPY api/resources ./resources
COPY api/storage ./storage
# Copy vendor directory from composer stage
COPY --from=composer /app/vendor ./vendor
# Set permissions
RUN chmod -R 775 storage \
&& chmod -R 775 bootstrap/cache \
&& chown -R www-data:www-data /usr/share/nginx/html
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"]