feat: add entrypoint
This commit is contained in:
1 parent
28ed738e33
commit
8492f2cc33
6 files changed
+131
-85
No files matched your search
+42
-55
@@ -1,50 +1,44 @@
|
||||
# ---------- 1) Build Composer deps ----------
|
||||
# ---------- 1) Build Composer deps (no scripts; avoids artisan during build) ----------
|
||||
FROM composer:2 AS vendor
|
||||
ARG COMPOSER_NO_DEV=1
|
||||
WORKDIR /app
|
||||
COPY composer.json composer.lock ./
|
||||
# Disable scripts to avoid "artisan not found"
|
||||
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 --no-scripts; \
|
||||
fi
|
||||
|
||||
|
||||
# ---------- 2) Copy app source (optional separate build stage) ----------
|
||||
# ---------- 2) Bring in app sources ----------
|
||||
FROM alpine:3.20 AS app_src
|
||||
WORKDIR /app
|
||||
COPY . ./
|
||||
|
||||
|
||||
# ---------- 3) Final image: Nginx + PHP-FPM ----------
|
||||
# ---------- 3) Final image: Nginx + PHP-FPM + PGSQL ----------
|
||||
FROM php:8.4-fpm-alpine
|
||||
|
||||
# System dependencies & build tools
|
||||
# System deps (build + runtime)
|
||||
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 nginx supervisor curl \
|
||||
oniguruma \
|
||||
\
|
||||
# PHP extensions
|
||||
&& 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 \
|
||||
\
|
||||
# Cleanup
|
||||
&& apk del .build-deps \
|
||||
&& rm -rf /var/cache/apk/* /tmp/*
|
||||
|
||||
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 \
|
||||
# PHP extensions
|
||||
&& 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 \
|
||||
# Cleanup
|
||||
&& apk del .build-deps \
|
||||
&& rm -rf /var/cache/apk/* /tmp/*
|
||||
|
||||
# Configure PHP-FPM to use UNIX socket for Nginx
|
||||
# PHP runtime tuning
|
||||
RUN set -eux; \
|
||||
sed -ri 's|^;?listen = .*$|listen = /run/php-fpm.sock|' /usr/local/etc/php-fpm.d/zz-docker.conf; \
|
||||
{ \
|
||||
echo "memory_limit=512M"; \
|
||||
echo "upload_max_filesize=64M"; \
|
||||
@@ -60,34 +54,27 @@
|
||||
echo "opcache.max_accelerated_files=20000"; \
|
||||
} > /usr/local/etc/php/conf.d/laravel.ini
|
||||
|
||||
# Prepare directories
|
||||
RUN mkdir -p /run/nginx /run/php /var/log/supervisor /var/www/html /etc/nginx/conf.d
|
||||
# Prepare dirs
|
||||
RUN mkdir -p /run/php /run/nginx /var/log/supervisor /var/www/html /etc/nginx/http.d
|
||||
|
||||
# Copy app & vendor
|
||||
# Copy app and vendor
|
||||
COPY --from=app_src /app /var/www/html
|
||||
COPY --from=vendor /app/vendor /var/www/html/vendor
|
||||
|
||||
# Copy configs
|
||||
COPY deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY deploy/supervisord.conf /etc/supervisord.conf
|
||||
|
||||
WORKDIR /var/www/html
|
||||
|
||||
# (Optional) Run artisan discovery after copy — nonfatal
|
||||
RUN php artisan package:discover --ansi || true
|
||||
|
||||
# Fix permissions for Laravel
|
||||
RUN set -eux; \
|
||||
mkdir -p storage bootstrap/cache; \
|
||||
chown -R www-data:www-data storage bootstrap/cache; \
|
||||
find storage -type d -exec chmod 775 {} \; ; \
|
||||
find storage -type f -exec chmod 664 {} \; ; \
|
||||
chmod -R 775 bootstrap/cache
|
||||
|
||||
EXPOSE 80
|
||||
HEALTHCHECK --interval=30s --timeout=5s --retries=5 \
|
||||
CMD curl -fsS http://localhost/healthz || exit 1
|
||||
|
||||
# Supervisor runs both services
|
||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||
|
||||
# Copy configs
|
||||
COPY deploy/nginx/default.conf /etc/nginx/http.d/default.conf
|
||||
COPY deploy/supervisord.conf /etc/supervisord.conf
|
||||
COPY deploy/php-fpm/zz-socket.conf /usr/local/etc/php-fpm.d/zz-socket.conf
|
||||
COPY deploy/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Ensure executable
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Healthcheck and ports (unchanged)
|
||||
EXPOSE 80
|
||||
HEALTHCHECK --interval=30s --timeout=5s --retries=5 \
|
||||
CMD curl -fsS http://localhost/healthz || exit 1
|
||||
|
||||
# Use the entrypoint to run artisan warmups, then exec supervisord
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||
Reference in new issue
Block a user