fix: add psql
This commit is contained in:
1 parent
4b43d8e70e
commit
098bd6528f
1 file changed
+55
-37
+55
-37
@@ -2,48 +2,57 @@
|
|||||||
# Stage 1: Build (Composer)
|
# Stage 1: Build (Composer)
|
||||||
# =========
|
# =========
|
||||||
FROM php:8.4-fpm-alpine AS build
|
FROM php:8.4-fpm-alpine AS build
|
||||||
# Build deps
|
|
||||||
RUN set -eux; \
|
|
||||||
apk add --no-cache git unzip libzip-dev oniguruma-dev icu-dev autoconf build-base
|
|
||||||
|
|
||||||
# PHP extensions for Laravel
|
# 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)
|
||||||
RUN docker-php-ext-configure zip; \
|
RUN docker-php-ext-configure zip; \
|
||||||
docker-php-ext-install -j"$(nproc)" pdo_mysql zip opcache intl
|
docker-php-ext-install -j"$(nproc)" \
|
||||||
|
pdo_mysql pdo_pgsql pgsql zip opcache intl
|
||||||
|
|
||||||
# Composer
|
# Composer
|
||||||
ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_HOME=/tmp/composer
|
ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_HOME=/tmp/composer
|
||||||
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
|
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
|
||||||
|
|
||||||
# Use a neutral build path; we'll copy to /var/www/html later
|
# App deps first for better layer caching
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Composer layers
|
|
||||||
COPY composer.json composer.lock ./
|
COPY composer.json composer.lock ./
|
||||||
RUN set -eux; \
|
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 app (NO artisan caching here!)
|
# Copy the rest of the source (no artisan optimize here; do it at runtime if desired)
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# =========
|
# =========
|
||||||
# Stage 2: Runtime (everything runs as 'nginx' user)
|
# Stage 2: Runtime (nginx + php-fpm)
|
||||||
# =========
|
# =========
|
||||||
FROM php:8.4-fpm-alpine
|
FROM php:8.4-fpm-alpine
|
||||||
|
|
||||||
# Runtime packages
|
# Base runtime packages
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apk add --no-cache nginx supervisor curl libzip icu-libs; \
|
apk add --no-cache \
|
||||||
mkdir -p /run/nginx /var/log/nginx /var/log/supervisor /etc/nginx/conf.d /var/www/html \
|
nginx supervisor curl \
|
||||||
/var/cache/nginx /var/lib/nginx/tmp
|
libzip icu-libs
|
||||||
|
|
||||||
# PHP runtime extensions
|
# Build PHP runtime extensions (need *-dev to compile, then remove them)
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apk add --no-cache libzip-dev icu-dev oniguruma-dev; \
|
apk add --no-cache \
|
||||||
|
libzip-dev icu-dev oniguruma-dev postgresql-dev; \
|
||||||
docker-php-ext-configure zip; \
|
docker-php-ext-configure zip; \
|
||||||
docker-php-ext-install -j"$(nproc)" pdo_mysql zip opcache intl; \
|
docker-php-ext-install -j"$(nproc)" \
|
||||||
apk del --no-progress --purge libzip-dev icu-dev oniguruma-dev || true
|
pdo_mysql pdo_pgsql pgsql zip opcache intl; \
|
||||||
|
# remove build deps; keep runtime libs (libpq comes via postgresql-dev)
|
||||||
|
apk del --no-progress --purge \
|
||||||
|
libzip-dev icu-dev oniguruma-dev postgresql-dev || true
|
||||||
|
|
||||||
# PHP production ini + opcache
|
# PHP production ini + opcache tuning
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
|
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
|
||||||
{ \
|
{ \
|
||||||
@@ -56,11 +65,30 @@ RUN set -eux; \
|
|||||||
echo "realpath_cache_ttl=600"; \
|
echo "realpath_cache_ttl=600"; \
|
||||||
} >> "$PHP_INI_DIR/conf.d/99-opcache.ini"
|
} >> "$PHP_INI_DIR/conf.d/99-opcache.ini"
|
||||||
|
|
||||||
# App into runtime image under final path; own by nginx
|
# FPM: pass env, listen on TCP, run workers as nginx
|
||||||
|
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; \
|
||||||
|
sed -ri 's|^user\s*=.*|user = nginx|g' /usr/local/etc/php-fpm.d/www.conf; \
|
||||||
|
sed -ri 's|^group\s*=.*|group = nginx|g' /usr/local/etc/php-fpm.d/www.conf; \
|
||||||
|
{ \
|
||||||
|
echo "ping.path = /ping"; \
|
||||||
|
echo "pm.status_path = /status"; \
|
||||||
|
echo "catch_workers_output = yes"; \
|
||||||
|
} >> /usr/local/etc/php-fpm.d/www.conf
|
||||||
|
|
||||||
|
# Create needed dirs
|
||||||
|
RUN set -eux; \
|
||||||
|
mkdir -p /run/nginx /var/log/nginx /var/log/supervisor \
|
||||||
|
/etc/nginx/conf.d /var/www/html \
|
||||||
|
/var/cache/nginx /var/lib/nginx/tmp
|
||||||
|
|
||||||
|
# App code
|
||||||
WORKDIR /var/www/html
|
WORKDIR /var/www/html
|
||||||
COPY --from=build --chown=nginx:nginx /app /var/www/html
|
COPY --from=build --chown=nginx:nginx /app /var/www/html
|
||||||
|
|
||||||
# Nginx + Supervisor configs + health + entrypoint
|
# 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/nginx.conf /etc/nginx/nginx.conf
|
||||||
COPY ./docker/site.conf /etc/nginx/conf.d/default.conf
|
COPY ./docker/site.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY ./docker/supervisord.conf /etc/supervisord.conf
|
COPY ./docker/supervisord.conf /etc/supervisord.conf
|
||||||
@@ -73,33 +101,23 @@ RUN set -eux; \
|
|||||||
ln -sf /dev/stdout /var/log/nginx/access.log; \
|
ln -sf /dev/stdout /var/log/nginx/access.log; \
|
||||||
ln -sf /dev/stderr /var/log/nginx/error.log
|
ln -sf /dev/stderr /var/log/nginx/error.log
|
||||||
|
|
||||||
# FPM: pass env, listen on TCP (non-root ok), run workers as nginx
|
|
||||||
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; \
|
|
||||||
sed -ri 's|^user\s*=.*|user = nginx|g' /usr/local/etc/php-fpm.d/www.conf; \
|
|
||||||
sed -ri 's|^group\s*=.*|group = nginx|g' /usr/local/etc/php-fpm.d/www.conf; \
|
|
||||||
{ \
|
|
||||||
echo "ping.path = /ping"; \
|
|
||||||
echo "pm.status_path = /status"; \
|
|
||||||
echo "catch_workers_output = yes"; \
|
|
||||||
} >> /usr/local/etc/php-fpm.d/www.conf
|
|
||||||
|
|
||||||
# Ensure Laravel writable dirs exist & owned by nginx
|
# Ensure Laravel writable dirs exist & owned by nginx
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
mkdir -p storage/framework/{cache,sessions,views} storage/logs bootstrap/cache; \
|
mkdir -p storage/framework/{cache,sessions,views} storage/logs bootstrap/cache; \
|
||||||
chown -R nginx:nginx storage bootstrap/cache /var/cache/nginx /var/lib/nginx /var/lib/nginx/tmp /run/nginx /var/log/nginx /var/log/supervisor; \
|
chown -R nginx:nginx storage bootstrap/cache \
|
||||||
|
/var/cache/nginx /var/lib/nginx /var/lib/nginx/tmp \
|
||||||
|
/run/nginx /var/log/nginx /var/log/supervisor; \
|
||||||
chmod -R ug+rwX storage bootstrap/cache
|
chmod -R ug+rwX storage bootstrap/cache
|
||||||
|
|
||||||
# ENV / port
|
# Environment + port (match your Nginx listen)
|
||||||
ENV APP_ENV=production APP_DEBUG=false APP_URL=http://localhost APP_PORT=8080
|
ENV APP_ENV=production APP_DEBUG=false APP_URL=http://localhost APP_PORT=8080
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# Healthcheck
|
# Healthcheck
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD ["/usr/local/bin/healthcheck.sh"]
|
HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD ["/usr/local/bin/healthcheck.sh"]
|
||||||
|
|
||||||
# Run everything as nginx
|
# Drop root
|
||||||
USER nginx:nginx
|
USER nginx:nginx
|
||||||
|
|
||||||
# Start via supervisor (which will first run entrypoint, then services)
|
# Start via supervisor (entrypoint can run artisan cache warmups, etc.)
|
||||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||||
Reference in new issue
Block a user