docker: run composer install at build time instead of in the entrypoint

- Install dependencies in a cached layer (composer.json/lock only), then
  dump the optimized autoloader after copying the app
- Entrypoint only runs composer install if vendor/ is missing (e.g. when
  the app directory is mounted as a volume)
- Force LF for *.sh so the entrypoint works when built from a Windows checkout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
eric.busandClaude Opus 5.5 committed 2026-11-20 13:33:07 +01:00
1 parent a11dca62a4
commit 2ddcb1b6b0
3 files changed
+23 -11

No files matched your search

+12 -4
View File
@@ -46,12 +46,17 @@ RUN echo '<Directory /var/www/app/public>\n\
</Directory>' > /etc/apache2/conf-available/laravel.conf \
&& a2enconf laravel
# Copy app files (composer/npm setup happens at runtime via entrypoint)
# Install PHP dependencies first (cached layer, only rebuilt when composer files change).
# Scripts and autoloader are skipped here because the app code isn't copied yet.
COPY composer.json composer.lock ./
COPY package.json package-lock.json* ./
COPY scripts/ ./scripts/ 2>/dev/null
RUN composer install \
--no-dev \
--prefer-dist \
--no-interaction \
--no-scripts \
--no-autoloader
# Note: for Laravel, the COPY . . needs to be before the composer install
# Copy app files (npm setup happens at runtime via entrypoint)
COPY . .
# Create storage directories
@@ -64,6 +69,9 @@ RUN mkdir -p \
bootstrap/cache \
public/assets/vendor
# Generate the optimized autoloader and run composer scripts (package:discover)
RUN composer dump-autoload --no-dev --optimize --no-interaction
# Copy and set up entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh