65 - Speed up the production image build
All checks were successful
CI / ci (push) Successful in 55s
CI / build (push) Successful in 1m7s
CI / ci (pull_request) Successful in 26s
CI / build (pull_request) Successful in 1m14s

This commit is contained in:
myrmidex 2026-08-16 13:12:25 +02:00
parent e5c257d94d
commit 8d124e42cd
2 changed files with 19 additions and 12 deletions

View file

@ -39,6 +39,11 @@ jobs:
with:
context: .
file: docker/production/Dockerfile
# arm64 is deliberate: nothing of ours deploys to it, but the image is
# published for self-hosters and dropping it would exclude ARM boxes.
# It is emulated via QEMU, so keep the Dockerfile free of compilation.
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=forge.lvl0.xyz/lvl0/incr:buildcache
cache-to: type=registry,ref=forge.lvl0.xyz/lvl0/incr:buildcache,mode=max

View file

@ -20,39 +20,41 @@ RUN npm run build
# PHP runtime stage
FROM php:8.3-fpm-alpine
# Install system dependencies
# mysql-client backs the database readiness loop in start-app.sh.
RUN apk add --no-cache \
git \
curl \
libpng-dev \
libxml2-dev \
zip \
unzip \
oniguruma-dev \
mysql-client \
nginx \
supervisor
# Install PHP extensions
RUN docker-php-ext-install \
# Prebuilt binaries rather than docker-php-ext-install: compiling these under
# QEMU for the arm64 image dominated the build time.
COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions \
pdo_mysql \
mbstring \
exif \
pcntl \
bcmath \
gd
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www/html
# Copy application code first
# Dependencies before the source, so a code change does not reinstall vendor.
# --no-scripts because package discovery needs the full application.
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader --no-interaction --no-scripts
COPY . .
# Install PHP dependencies after copying all files
RUN composer install --no-dev --optimize-autoloader --no-interaction
# dump-autoload triggers post-autoload-dump, which runs package:discover.
RUN composer dump-autoload --optimize --no-interaction
# Copy built frontend assets from builder stage
COPY --from=frontend-builder /app/public/build/ ./public/build/