fix: redesign
This commit is contained in:
+53
-59
@@ -1,70 +1,64 @@
|
||||
# -------- 1) Composer deps (no scripts; avoids artisan during build) --------
|
||||
# -------- Stage 1: Builder (Composer Dependencies) --------
|
||||
FROM composer:2 AS vendor
|
||||
ARG COMPOSER_NO_DEV=1
|
||||
|
||||
WORKDIR /app
|
||||
COPY composer.json composer.lock ./
|
||||
RUN if [ "$COMPOSER_NO_DEV" = "1" ]; then \
|
||||
composer install --no-dev --prefer-dist --no-progress --no-interaction --classmap-authoritative --no-scripts; \
|
||||
else \
|
||||
composer install --prefer-dist --no-progress --no-interaction --classmap-authoritative --no-scripts; \
|
||||
fi
|
||||
|
||||
# -------- 2) App source --------
|
||||
FROM alpine:3.22 AS app_src
|
||||
WORKDIR /app
|
||||
COPY composer.json composer.lock ./
|
||||
|
||||
RUN composer install --no-dev --optimize-autoloader --no-scripts --no-progress
|
||||
|
||||
# -------- Stage 2: Runtime (Alpine + PHP-FPM + Nginx + Supervisor) --------
|
||||
FROM alpine:3.22
|
||||
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# Install system and PHP packages, inkl. SQLite & PostgreSQL
|
||||
RUN apk add --no-cache \
|
||||
nginx supervisor gettext bash curl \
|
||||
php82 php82-fpm php82-opcache php82-mbstring php82-xml php82-curl php82-zip \
|
||||
php82-ctype php82-session php82-pdo php82-pdo_mysql php82-tokenizer php82-dom \
|
||||
php82-fileinfo php82-gd php82-intl php82-simplexml php82-phar php82-bcmath \
|
||||
php82-pdo_sqlite php82-sqlite3 php82-pgsql php82-pdo_pgsql \
|
||||
nodejs npm
|
||||
|
||||
# Provide php alias
|
||||
RUN ln -sf /usr/bin/php82 /usr/bin/php
|
||||
|
||||
# Create user, dirs, and sockets
|
||||
RUN addgroup -S web && adduser -S web -G web \
|
||||
&& mkdir -p /run/nginx /run/php /var/www/html /var/log/supervisor
|
||||
|
||||
# Configure PHP-FPM socket
|
||||
RUN sed -i 's|^listen = 127\\.0\\.0\\.1:9000|listen = /run/php/php-fpm.sock|' /etc/php82/php-fpm.d/www.conf \
|
||||
&& sed -i 's|^;listen.owner = nobody|listen.owner = nginx|' /etc/php82/php-fpm.d/www.conf \
|
||||
&& sed -i 's|^;listen.group = nobody|listen.group = nginx|' /etc/php82/php-fpm.d/www.conf \
|
||||
&& sed -i 's|^;listen.mode = 0660|listen.mode = 0660|' /etc/php82/php-fpm.d/www.conf \
|
||||
&& sed -i 's|^user = nobody|user = nginx|' /etc/php82/php-fpm.d/www.conf \
|
||||
&& sed -i 's|^group = nobody|group = nginx|' /etc/php82/php-fpm.d/www.conf
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
||||
COPY --from=vendor /app/vendor ./vendor
|
||||
COPY . ./
|
||||
|
||||
# -------- 3) Final: Nginx + PHP-FPM + PGSQL drivers --------
|
||||
FROM php:8.4-fpm-alpine
|
||||
COPY deploy/nginx/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY deploy/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
COPY deploy/nginx/nginx.default.conf.template /etc/nginx/templates/default.conf.template
|
||||
COPY deploy/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Build + runtime deps (incl. oniguruma for mbstring, GD runtime libs)
|
||||
RUN set -eux; \
|
||||
apk add --no-cache --virtual .build-deps \
|
||||
$PHPIZE_DEPS icu-dev libzip-dev postgresql-dev \
|
||||
freetype-dev libjpeg-turbo-dev libpng-dev \
|
||||
oniguruma-dev pkgconf \
|
||||
&& apk add --no-cache \
|
||||
icu-libs libzip libpq tzdata bash git curl \
|
||||
nginx supervisor \
|
||||
oniguruma freetype libjpeg-turbo libpng \
|
||||
&& docker-php-ext-configure intl \
|
||||
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
|
||||
&& docker-php-ext-install -j"$(nproc)" intl opcache zip bcmath mbstring gd pdo pdo_pgsql pgsql \
|
||||
&& apk del .build-deps \
|
||||
&& rm -rf /var/cache/apk/* /tmp/*
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# PHP runtime tuning
|
||||
RUN set -eux; \
|
||||
{ \
|
||||
echo "memory_limit=512M"; \
|
||||
echo "upload_max_filesize=64M"; \
|
||||
echo "post_max_size=64M"; \
|
||||
echo "max_execution_time=60"; \
|
||||
} > /usr/local/etc/php/conf.d/laravel.ini
|
||||
# Permissions for Laravel writable directories
|
||||
RUN mkdir -p storage bootstrap/cache \
|
||||
&& chown -R nginx:nginx storage bootstrap/cache \
|
||||
&& chmod -R ug+rwX storage bootstrap/cache
|
||||
|
||||
# Set timezone
|
||||
RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime
|
||||
# Build frontend assets
|
||||
RUN npm ci && npm run build
|
||||
|
||||
# Copy application source
|
||||
WORKDIR /app
|
||||
COPY --from=app_src /app /app
|
||||
COPY --from=vendor /app/vendor /app/vendor
|
||||
# Optimize Laravel configuration
|
||||
RUN php artisan config:cache && php artisan route:cache && php artisan view:cache && php artisan event:cache
|
||||
|
||||
# Set permissions for Laravel storage and cache
|
||||
RUN set -eux; \
|
||||
chown -R www-data:www-data /app/storage /app/bootstrap/cache /app/public; \
|
||||
chmod -R 775 /app/storage /app/bootstrap/cache /app/public
|
||||
|
||||
# Configure Nginx
|
||||
RUN mkdir -p /run/nginx
|
||||
RUN mkdir -p /var/log/supervisor
|
||||
COPY ./deploy/nginx/default.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Configure Supervisor
|
||||
COPY ./deploy/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
# Expose ports
|
||||
EXPOSE 80
|
||||
|
||||
# Start Supervisor
|
||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
|
||||
Reference in New Issue
Block a user