fix: add more things
This commit is contained in:
+57
-14
@@ -1,15 +1,41 @@
|
|||||||
# =========
|
# =========
|
||||||
# Stage 1: Build (Composer)
|
# Stage 0: Frontend build (Vite)
|
||||||
|
# =========
|
||||||
|
FROM node:20-alpine AS nodebuild
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install JS deps first for caching
|
||||||
|
COPY package.json package-lock.json* pnpm-lock.yaml* yarn.lock* ./
|
||||||
|
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
|
||||||
|
|
||||||
|
# Copy the rest and build
|
||||||
|
COPY . .
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
# If your Vite build needs ASSET_URL or similar, set it here:
|
||||||
|
# ENV ASSET_URL=/
|
||||||
|
RUN \
|
||||||
|
if [ -f package.json ]; then \
|
||||||
|
if npm run | grep -q " build"; then npm run build; \
|
||||||
|
else echo "No build script in package.json"; fi; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# =========
|
||||||
|
# Stage 1: Composer / PHP deps
|
||||||
# =========
|
# =========
|
||||||
FROM php:8.4-fpm-alpine AS build
|
FROM php:8.4-fpm-alpine AS build
|
||||||
|
|
||||||
|
# Build dependencies for PHP extensions and composer operations
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
git unzip \
|
git unzip \
|
||||||
libzip-dev oniguruma-dev icu-dev \
|
libzip-dev oniguruma-dev icu-dev \
|
||||||
autoconf build-base postgresql-dev
|
autoconf build-base postgresql-dev
|
||||||
|
|
||||||
# PHP extensions for Laravel (include pg + mysql)
|
# PHP extensions (include PostgreSQL)
|
||||||
RUN docker-php-ext-configure zip; \
|
RUN 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 opcache intl
|
||||||
@@ -18,11 +44,15 @@ RUN docker-php-ext-configure zip; \
|
|||||||
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
|
||||||
|
|
||||||
|
# Install PHP deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
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 app source (do not run artisan optimize here; we’ll clear/warmup at runtime if needed)
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# =========
|
# =========
|
||||||
@@ -43,13 +73,13 @@ RUN set -eux; \
|
|||||||
docker-php-ext-configure zip; \
|
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 opcache intl; \
|
||||||
# Install the runtime lib for PostgreSQL (REQUIRED for pdo_pgsql/pgsql)
|
# PostgreSQL client runtime lib so pdo_pgsql/pgsql can load
|
||||||
apk add --no-cache libpq; \
|
apk add --no-cache libpq; \
|
||||||
# Now remove build deps
|
# Remove build deps
|
||||||
apk del --no-progress --purge \
|
apk del --no-progress --purge \
|
||||||
libzip-dev icu-dev oniguruma-dev postgresql-dev || true
|
libzip-dev icu-dev oniguruma-dev postgresql-dev || true
|
||||||
|
|
||||||
# PHP production ini + opcache
|
# php.ini production + 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"; \
|
||||||
{ \
|
{ \
|
||||||
@@ -62,7 +92,7 @@ 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"
|
||||||
|
|
||||||
# FPM config
|
# Configure PHP-FPM: pass env, listen on TCP, run as nginx
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
sed -ri 's|^;?clear_env\s*=.*|clear_env = no|g' /usr/local/etc/php-fpm.d/www.conf; \
|
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|^listen = .*|listen = 127.0.0.1:9000|g' /usr/local/etc/php-fpm.d/www.conf; \
|
||||||
@@ -74,7 +104,7 @@ RUN set -eux; \
|
|||||||
echo "catch_workers_output = yes"; \
|
echo "catch_workers_output = yes"; \
|
||||||
} >> /usr/local/etc/php-fpm.d/www.conf
|
} >> /usr/local/etc/php-fpm.d/www.conf
|
||||||
|
|
||||||
# Create dirs
|
# Create required directories
|
||||||
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 \
|
||||||
@@ -84,12 +114,16 @@ RUN set -eux; \
|
|||||||
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
|
||||||
|
|
||||||
|
# Copy built frontend assets from node stage
|
||||||
|
COPY --from=nodebuild --chown=nginx:nginx /app/public/build /var/www/html/public/build
|
||||||
|
|
||||||
# Nginx + Supervisor configs + health + entrypoint
|
# Nginx + Supervisor configs + health + entrypoint
|
||||||
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
|
# Ensure these files exist in your repo under ./docker
|
||||||
COPY ./docker/site.conf /etc/nginx/conf.d/default.conf
|
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
|
||||||
COPY ./docker/supervisord.conf /etc/supervisord.conf
|
COPY ./docker/site.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY ./docker/healthcheck.sh /usr/local/bin/healthcheck.sh
|
COPY ./docker/supervisord.conf /etc/supervisord.conf
|
||||||
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY ./docker/healthcheck.sh /usr/local/bin/healthcheck.sh
|
||||||
|
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
RUN chmod +x /usr/local/bin/healthcheck.sh /usr/local/bin/entrypoint.sh
|
RUN chmod +x /usr/local/bin/healthcheck.sh /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
# Log to STDOUT/ERR
|
# Log to STDOUT/ERR
|
||||||
@@ -97,7 +131,7 @@ 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
|
||||||
|
|
||||||
# Laravel writable dirs
|
# Laravel writable dirs & permissions
|
||||||
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 \
|
chown -R nginx:nginx storage bootstrap/cache \
|
||||||
@@ -105,10 +139,19 @@ RUN set -eux; \
|
|||||||
/run/nginx /var/log/nginx /var/log/supervisor; \
|
/run/nginx /var/log/nginx /var/log/supervisor; \
|
||||||
chmod -R ug+rwX storage bootstrap/cache
|
chmod -R ug+rwX storage bootstrap/cache
|
||||||
|
|
||||||
|
# Optional: clear caches on container start via entrypoint (your entrypoint can do this)
|
||||||
|
# e.g., in /usr/local/bin/entrypoint.sh you might have:
|
||||||
|
# php artisan config:clear || true && php artisan cache:clear || true
|
||||||
|
|
||||||
|
# Env + port
|
||||||
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 --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 as nginx user
|
||||||
USER nginx:nginx
|
USER nginx:nginx
|
||||||
|
|
||||||
|
# Launch supervisor (which can start php-fpm + nginx; your supervisord.conf should do that)
|
||||||
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
|
||||||
|
|||||||
Reference in New Issue
Block a user