2025-10-22 22:58:32 +02:00
|
|
|
# syntax=docker/dockerfile:1.6
|
|
|
|
|
|
|
|
|
|
############################
|
2025-10-22 23:00:32 +02:00
|
|
|
# Stage 1: PHP (Composer) #
|
2025-10-22 22:58:32 +02:00
|
|
|
############################
|
2025-10-22 23:00:32 +02:00
|
|
|
FROM php:8.4-fpm-alpine AS phpbuild
|
2025-10-21 18:37:25 +02:00
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Build deps for PHP extensions + composer
|
2025-10-22 22:34:44 +02:00
|
|
|
RUN set -eux; \
|
|
|
|
|
apk add --no-cache \
|
|
|
|
|
git unzip \
|
|
|
|
|
libzip-dev oniguruma-dev icu-dev \
|
|
|
|
|
autoconf build-base postgresql-dev
|
|
|
|
|
|
2025-10-22 22:58:32 +02:00
|
|
|
# PHP extensions (PG + MySQL + zip/opcache/intl)
|
2025-10-21 18:37:25 +02:00
|
|
|
RUN docker-php-ext-configure zip; \
|
2025-10-22 22:34:44 +02:00
|
|
|
docker-php-ext-install -j"$(nproc)" \
|
|
|
|
|
pdo_mysql pdo_pgsql pgsql zip opcache intl
|
2025-10-21 18:37:25 +02:00
|
|
|
|
|
|
|
|
# Composer
|
|
|
|
|
ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_HOME=/tmp/composer
|
|
|
|
|
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
2025-10-22 23:00:32 +02:00
|
|
|
# Install PHP deps first for better layer caching
|
2025-10-21 18:37:25 +02:00
|
|
|
COPY composer.json composer.lock ./
|
2025-10-22 22:58:32 +02:00
|
|
|
RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --no-scripts
|
2025-10-22 23:00:32 +02:00
|
|
|
|
|
|
|
|
# Copy full app source (now vendor/ exists for later stages)
|
2025-10-21 18:37:25 +02:00
|
|
|
COPY . .
|
|
|
|
|
|
2025-10-22 22:58:32 +02:00
|
|
|
############################
|
2025-10-22 23:00:32 +02:00
|
|
|
# Stage 2: Frontend (Vite) #
|
2025-10-22 22:58:32 +02:00
|
|
|
############################
|
2025-10-22 23:00:32 +02:00
|
|
|
FROM node:20-alpine AS nodebuild
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Bring in the **already-composed** app (includes vendor/)
|
|
|
|
|
COPY --from=phpbuild /app /app
|
|
|
|
|
|
|
|
|
|
# Native build tools in case any npm deps need them
|
|
|
|
|
RUN apk add --no-cache python3 make g++
|
|
|
|
|
|
|
|
|
|
# JS deps & build (Laravel default expects package.json at repo root)
|
|
|
|
|
RUN if [ -f package-lock.json ]; then npm ci; \
|
|
|
|
|
elif [ -f pnpm-lock.yaml ]; then corepack enable && pnpm i --frozen-lockfile; \
|
|
|
|
|
elif [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
|
|
|
|
|
else npm i; fi
|
|
|
|
|
|
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
|
# Standard Laravel: "build": "vite build"
|
|
|
|
|
RUN npm run build
|
|
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
|
# Stage 3: Runtime (nginx + php-fpm)#
|
|
|
|
|
#####################################
|
2025-10-21 18:37:25 +02:00
|
|
|
FROM php:8.4-fpm-alpine
|
|
|
|
|
|
2025-10-22 22:34:44 +02:00
|
|
|
# Base runtime packages
|
2025-10-21 18:37:25 +02:00
|
|
|
RUN set -eux; \
|
2025-10-22 22:34:44 +02:00
|
|
|
apk add --no-cache \
|
|
|
|
|
nginx supervisor curl \
|
|
|
|
|
libzip icu-libs
|
2025-10-21 18:37:25 +02:00
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Build PHP runtime extensions and install libpq (needed by pdo_pgsql/pgsql)
|
2025-10-21 18:37:25 +02:00
|
|
|
RUN set -eux; \
|
2025-10-22 22:58:32 +02:00
|
|
|
apk add --no-cache libzip-dev icu-dev oniguruma-dev postgresql-dev; \
|
2025-10-21 18:37:25 +02:00
|
|
|
docker-php-ext-configure zip; \
|
2025-10-22 22:58:32 +02:00
|
|
|
docker-php-ext-install -j"$(nproc)" pdo_mysql pdo_pgsql pgsql zip opcache intl; \
|
2025-10-22 22:42:52 +02:00
|
|
|
apk add --no-cache libpq; \
|
2025-10-22 22:58:32 +02:00
|
|
|
apk del --no-progress --purge libzip-dev icu-dev oniguruma-dev postgresql-dev || true
|
2025-10-21 18:37:25 +02:00
|
|
|
|
2025-10-22 22:53:46 +02:00
|
|
|
# php.ini production + opcache tuning
|
2025-10-21 18:37:25 +02:00
|
|
|
RUN set -eux; \
|
|
|
|
|
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"; \
|
|
|
|
|
{ \
|
|
|
|
|
echo "opcache.enable=1"; \
|
|
|
|
|
echo "opcache.enable_cli=0"; \
|
|
|
|
|
echo "opcache.memory_consumption=128"; \
|
|
|
|
|
echo "opcache.max_accelerated_files=20000"; \
|
|
|
|
|
echo "opcache.validate_timestamps=0"; \
|
|
|
|
|
echo "realpath_cache_size=4096K"; \
|
|
|
|
|
echo "realpath_cache_ttl=600"; \
|
|
|
|
|
} >> "$PHP_INI_DIR/conf.d/99-opcache.ini"
|
|
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Configure PHP-FPM: pass env, listen TCP, run as nginx
|
2025-10-21 18:37:25 +02:00
|
|
|
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; \
|
2025-10-22 23:00:32 +02:00
|
|
|
{ echo "ping.path = /ping"; echo "pm.status_path = /status"; echo "catch_workers_output = yes"; } >> /usr/local/etc/php-fpm.d/www.conf
|
2025-10-21 18:37:25 +02:00
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Directories
|
2025-10-22 22:34:44 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
WORKDIR /var/www/html
|
2025-10-22 22:58:32 +02:00
|
|
|
|
|
|
|
|
# App code from composer stage
|
2025-10-22 23:00:32 +02:00
|
|
|
COPY --from=phpbuild --chown=nginx:nginx /app /var/www/html
|
2025-10-22 22:34:44 +02:00
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Built frontend assets from node stage (public/build/** including manifest.json)
|
2025-10-22 22:53:46 +02:00
|
|
|
COPY --from=nodebuild --chown=nginx:nginx /app/public/build /var/www/html/public/build
|
|
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Nginx + Supervisor configs + health + entrypoint (must exist in your repo)
|
2025-10-22 22:53:46 +02:00
|
|
|
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
|
2025-10-22 22:34:44 +02:00
|
|
|
RUN chmod +x /usr/local/bin/healthcheck.sh /usr/local/bin/entrypoint.sh
|
|
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Log to STDOUT/ERR
|
2025-10-22 22:34:44 +02:00
|
|
|
RUN set -eux; \
|
|
|
|
|
ln -sf /dev/stdout /var/log/nginx/access.log; \
|
|
|
|
|
ln -sf /dev/stderr /var/log/nginx/error.log
|
|
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Laravel writable dirs & permissions
|
2025-10-21 18:37:25 +02:00
|
|
|
RUN set -eux; \
|
|
|
|
|
mkdir -p storage/framework/{cache,sessions,views} storage/logs bootstrap/cache; \
|
2025-10-22 22:34:44 +02:00
|
|
|
chown -R nginx:nginx storage bootstrap/cache \
|
2025-10-22 22:58:32 +02:00
|
|
|
/var/cache/nginx /var/lib/nginx /run/nginx /var/log/nginx /var/log/supervisor; \
|
2025-10-21 18:37:25 +02:00
|
|
|
chmod -R ug+rwX storage bootstrap/cache
|
|
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Env + port
|
2025-10-21 18:37:25 +02:00
|
|
|
ENV APP_ENV=production APP_DEBUG=false APP_URL=http://localhost APP_PORT=8080
|
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD ["/usr/local/bin/healthcheck.sh"]
|
|
|
|
|
|
2025-10-22 23:00:32 +02:00
|
|
|
# Drop root
|
2025-10-21 18:37:25 +02:00
|
|
|
USER nginx:nginx
|
2025-10-22 23:00:32 +02:00
|
|
|
|
|
|
|
|
# Start services
|
2025-10-21 18:37:25 +02:00
|
|
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|