fix: layout
This commit is contained in:
+46
-38
@@ -1,21 +1,22 @@
|
|||||||
# syntax=docker/dockerfile:1.6
|
# syntax=docker/dockerfile:1.6
|
||||||
|
|
||||||
|
ARG PHP_VERSION=8.3
|
||||||
|
ARG NODE_VERSION=20
|
||||||
|
|
||||||
############################
|
############################
|
||||||
# Stage 1: PHP (Composer) #
|
# Stage 1: PHP (Composer) #
|
||||||
############################
|
############################
|
||||||
FROM php:8.4-fpm-alpine AS phpbuild
|
FROM php:${PHP_VERSION}-fpm-alpine AS composer_build
|
||||||
|
|
||||||
# Build deps for PHP extensions + composer
|
# OS deps for building PHP extensions that Composer plugins may need
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apk add --no-cache \
|
apk add --no-cache git unzip icu-dev libzip-dev oniguruma-dev postgresql-dev autoconf build-base
|
||||||
git unzip \
|
|
||||||
libzip-dev oniguruma-dev icu-dev \
|
|
||||||
autoconf build-base postgresql-dev
|
|
||||||
|
|
||||||
# PHP extensions (PG + MySQL + zip/opcache/intl)
|
# PHP extensions required by Laravel (build here too if scripts need them)
|
||||||
RUN docker-php-ext-configure zip; \
|
RUN set -eux; \
|
||||||
|
docker-php-ext-configure zip; \
|
||||||
docker-php-ext-install -j"$(nproc)" \
|
docker-php-ext-install -j"$(nproc)" \
|
||||||
pdo_mysql pdo_pgsql pgsql zip opcache intl
|
pdo_mysql pdo_pgsql pgsql zip intl mbstring bcmath opcache
|
||||||
|
|
||||||
# Composer
|
# Composer
|
||||||
ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_HOME=/tmp/composer
|
ENV COMPOSER_ALLOW_SUPERUSER=1 COMPOSER_HOME=/tmp/composer
|
||||||
@@ -24,51 +25,58 @@ COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
# Install PHP deps first for better layer caching
|
# Install PHP deps first for better layer caching
|
||||||
COPY composer.json composer.lock ./
|
COPY composer.json composer.lock ./
|
||||||
RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader --no-scripts
|
# DO NOT skip scripts — Laravel needs them (package discovery, etc.)
|
||||||
|
RUN composer install \
|
||||||
|
--no-dev --no-interaction --prefer-dist \
|
||||||
|
--optimize-autoloader
|
||||||
|
|
||||||
# Copy full app source (now vendor/ exists for later stages)
|
# Bring in the rest of the app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
############################
|
############################
|
||||||
# Stage 2: Frontend (Vite) #
|
# Stage 2: Frontend (Vite) #
|
||||||
############################
|
############################
|
||||||
FROM node:20-alpine AS nodebuild
|
FROM node:${NODE_VERSION}-alpine AS node_build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Bring in the **already-composed** app (includes vendor/)
|
# Only the files Node needs (faster context & cache)
|
||||||
COPY --from=phpbuild /app /app
|
COPY package.json package-lock.json* pnpm-lock.yaml* yarn.lock* vite.config.* ./
|
||||||
|
COPY resources ./resources
|
||||||
|
COPY public ./public
|
||||||
|
# If your Vite config imports from `resources` only, this is enough.
|
||||||
|
# If you reference other paths at build time, copy them similarly.
|
||||||
|
|
||||||
# Native build tools in case any npm deps need them
|
# Native build deps (rarely needed, but safe)
|
||||||
RUN apk add --no-cache python3 make g++
|
RUN apk add --no-cache python3 make g++
|
||||||
|
|
||||||
# JS deps & build (Laravel default expects package.json at repo root)
|
# Install using the appropriate lockfile
|
||||||
RUN if [ -f package-lock.json ]; then npm ci; \
|
RUN set -eux; \
|
||||||
elif [ -f pnpm-lock.yaml ]; then corepack enable && pnpm i --frozen-lockfile; \
|
if [ -f pnpm-lock.yaml ]; then corepack enable && pnpm i --frozen-lockfile; \
|
||||||
elif [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
|
elif [ -f yarn.lock ]; then corepack enable && yarn install --frozen-lockfile; \
|
||||||
|
elif [ -f package-lock.json ]; then npm ci; \
|
||||||
else npm i; fi
|
else npm i; fi
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
# Standard Laravel: "build": "vite build"
|
# Standard Laravel vite build => outputs to public/build + manifest.json
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
# Stage 3: Runtime (nginx + php-fpm)#
|
# Stage 3: Runtime (nginx + php-fpm)#
|
||||||
#####################################
|
#####################################
|
||||||
FROM php:8.4-fpm-alpine
|
FROM php:${PHP_VERSION}-fpm-alpine
|
||||||
|
|
||||||
# Base runtime packages
|
# Base runtime packages
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apk add --no-cache \
|
apk add --no-cache nginx supervisor curl libzip icu-libs oniguruma libpq
|
||||||
nginx supervisor curl \
|
|
||||||
libzip icu-libs
|
|
||||||
|
|
||||||
# Build PHP runtime extensions and install libpq (needed by pdo_pgsql/pgsql)
|
# Build required PHP extensions in the final image (so they exist at runtime)
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apk add --no-cache libzip-dev icu-dev oniguruma-dev postgresql-dev; \
|
apk add --no-cache libzip-dev icu-dev oniguruma-dev postgresql-dev autoconf build-base; \
|
||||||
docker-php-ext-configure zip; \
|
docker-php-ext-configure zip; \
|
||||||
docker-php-ext-install -j"$(nproc)" pdo_mysql pdo_pgsql pgsql zip opcache intl; \
|
docker-php-ext-install -j"$(nproc)" \
|
||||||
apk add --no-cache libpq; \
|
pdo_mysql pdo_pgsql pgsql zip intl mbstring bcmath opcache; \
|
||||||
apk del --no-progress --purge libzip-dev icu-dev oniguruma-dev postgresql-dev || true
|
# Slim back down
|
||||||
|
apk del --no-progress --purge libzip-dev icu-dev oniguruma-dev postgresql-dev autoconf build-base || true
|
||||||
|
|
||||||
# php.ini production + opcache tuning
|
# php.ini production + opcache tuning
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
@@ -76,8 +84,8 @@ RUN set -eux; \
|
|||||||
{ \
|
{ \
|
||||||
echo "opcache.enable=1"; \
|
echo "opcache.enable=1"; \
|
||||||
echo "opcache.enable_cli=0"; \
|
echo "opcache.enable_cli=0"; \
|
||||||
echo "opcache.memory_consumption=128"; \
|
echo "opcache.memory_consumption=192"; \
|
||||||
echo "opcache.max_accelerated_files=20000"; \
|
echo "opcache.max_accelerated_files=40000"; \
|
||||||
echo "opcache.validate_timestamps=0"; \
|
echo "opcache.validate_timestamps=0"; \
|
||||||
echo "realpath_cache_size=4096K"; \
|
echo "realpath_cache_size=4096K"; \
|
||||||
echo "realpath_cache_ttl=600"; \
|
echo "realpath_cache_ttl=600"; \
|
||||||
@@ -91,7 +99,7 @@ RUN set -eux; \
|
|||||||
sed -ri 's|^group\s*=.*|group = 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
|
{ echo "ping.path = /ping"; echo "pm.status_path = /status"; echo "catch_workers_output = yes"; } >> /usr/local/etc/php-fpm.d/www.conf
|
||||||
|
|
||||||
# Directories
|
# Runtime dirs
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
mkdir -p /run/nginx /var/log/nginx /var/log/supervisor \
|
mkdir -p /run/nginx /var/log/nginx /var/log/supervisor \
|
||||||
/etc/nginx/conf.d /var/www/html \
|
/etc/nginx/conf.d /var/www/html \
|
||||||
@@ -99,13 +107,13 @@ RUN set -eux; \
|
|||||||
|
|
||||||
WORKDIR /var/www/html
|
WORKDIR /var/www/html
|
||||||
|
|
||||||
# App code from composer stage
|
# Copy application code (without node_modules) and vendor from composer stage
|
||||||
COPY --from=phpbuild --chown=nginx:nginx /app /var/www/html
|
COPY --from=composer_build --chown=nginx:nginx /app /var/www/html
|
||||||
|
|
||||||
# Built frontend assets from node stage (public/build/** including manifest.json)
|
# Copy built frontend assets (public/build with manifest.json)
|
||||||
COPY --from=nodebuild --chown=nginx:nginx /app/public/build /var/www/html/public/build
|
COPY --from=node_build --chown=nginx:nginx /app/public/build /var/www/html/public/build
|
||||||
|
|
||||||
# Nginx + Supervisor configs + health + entrypoint (must exist in your repo)
|
# Nginx + Supervisor configs + health + entrypoint (these must exist in 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
|
||||||
@@ -125,7 +133,7 @@ RUN set -eux; \
|
|||||||
/var/cache/nginx /var/lib/nginx /run/nginx /var/log/nginx /var/log/supervisor; \
|
/var/cache/nginx /var/lib/nginx /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 (ensure site.conf listens on 8080 or change EXPOSE to 80)
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user