diff --git a/Dockerfile b/Dockerfile index 4e9d2dd..4017953 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,13 @@ # ========= FROM php:8.4-fpm-alpine AS build -# Build deps (add postgresql-dev so we can compile pg extensions if needed here) RUN set -eux; \ apk add --no-cache \ git unzip \ libzip-dev oniguruma-dev icu-dev \ autoconf build-base postgresql-dev -# PHP extensions for Laravel (include pg + mysql to keep image flexible) +# PHP extensions for Laravel (include pg + mysql) RUN docker-php-ext-configure zip; \ docker-php-ext-install -j"$(nproc)" \ pdo_mysql pdo_pgsql pgsql zip opcache intl @@ -19,15 +18,11 @@ RUN docker-php-ext-configure zip; \ ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_HOME=/tmp/composer COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer -# App deps first for better layer caching WORKDIR /app COPY composer.json composer.lock ./ RUN set -eux; \ - composer install \ - --no-dev --no-interaction --prefer-dist \ - --optimize-autoloader --no-scripts + composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --no-scripts -# Copy the rest of the source (no artisan optimize here; do it at runtime if desired) COPY . . # ========= @@ -41,18 +36,20 @@ RUN set -eux; \ nginx supervisor curl \ libzip icu-libs -# Build PHP runtime extensions (need *-dev to compile, then remove them) +# Build PHP runtime extensions (need *-dev to compile) RUN set -eux; \ apk add --no-cache \ libzip-dev icu-dev oniguruma-dev postgresql-dev; \ docker-php-ext-configure zip; \ docker-php-ext-install -j"$(nproc)" \ pdo_mysql pdo_pgsql pgsql zip opcache intl; \ - # remove build deps; keep runtime libs (libpq comes via postgresql-dev) + # Install the runtime lib for PostgreSQL (REQUIRED for pdo_pgsql/pgsql) + apk add --no-cache libpq; \ + # Now remove build deps apk del --no-progress --purge \ libzip-dev icu-dev oniguruma-dev postgresql-dev || true -# PHP production ini + opcache tuning +# PHP production ini + opcache RUN set -eux; \ mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \ { \ @@ -65,7 +62,7 @@ RUN set -eux; \ echo "realpath_cache_ttl=600"; \ } >> "$PHP_INI_DIR/conf.d/99-opcache.ini" -# FPM: pass env, listen on TCP, run workers as nginx +# FPM config RUN set -eux; \ sed -ri 's|^;?clear_env\s*=.*|clear_env = no|g' /usr/local/etc/php-fpm.d/www.conf; \ sed -ri 's|^listen = .*|listen = 127.0.0.1:9000|g' /usr/local/etc/php-fpm.d/www.conf; \ @@ -77,7 +74,7 @@ RUN set -eux; \ echo "catch_workers_output = yes"; \ } >> /usr/local/etc/php-fpm.d/www.conf -# Create needed dirs +# Create dirs RUN set -eux; \ mkdir -p /run/nginx /var/log/nginx /var/log/supervisor \ /etc/nginx/conf.d /var/www/html \ @@ -88,12 +85,11 @@ WORKDIR /var/www/html COPY --from=build --chown=nginx:nginx /app /var/www/html # Nginx + Supervisor configs + health + entrypoint -# (Make sure these files exist in ./docker of your repo) -COPY ./docker/nginx.conf /etc/nginx/nginx.conf -COPY ./docker/site.conf /etc/nginx/conf.d/default.conf -COPY ./docker/supervisord.conf /etc/supervisord.conf -COPY ./docker/healthcheck.sh /usr/local/bin/healthcheck.sh -COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh +COPY ./docker/nginx.conf /etc/nginx/nginx.conf +COPY ./docker/site.conf /etc/nginx/conf.d/default.conf +COPY ./docker/supervisord.conf /etc/supervisord.conf +COPY ./docker/healthcheck.sh /usr/local/bin/healthcheck.sh +COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/healthcheck.sh /usr/local/bin/entrypoint.sh # Log to STDOUT/ERR @@ -101,7 +97,7 @@ RUN set -eux; \ ln -sf /dev/stdout /var/log/nginx/access.log; \ ln -sf /dev/stderr /var/log/nginx/error.log -# Ensure Laravel writable dirs exist & owned by nginx +# Laravel writable dirs RUN set -eux; \ mkdir -p storage/framework/{cache,sessions,views} storage/logs bootstrap/cache; \ chown -R nginx:nginx storage bootstrap/cache \ @@ -109,15 +105,10 @@ RUN set -eux; \ /run/nginx /var/log/nginx /var/log/supervisor; \ chmod -R ug+rwX storage bootstrap/cache -# Environment + port (match your Nginx listen) ENV APP_ENV=production APP_DEBUG=false APP_URL=http://localhost APP_PORT=8080 EXPOSE 8080 -# Healthcheck HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD ["/usr/local/bin/healthcheck.sh"] -# Drop root USER nginx:nginx - -# Start via supervisor (entrypoint can run artisan cache warmups, etc.) CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]