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:
1 parent
a11dca62a4
commit
2ddcb1b6b0
3 files changed
+23
-11
No files matched your search
@@ -3,3 +3,4 @@
|
||||
*.scss linguist-vendored
|
||||
*.js linguist-vendored
|
||||
CHANGELOG.md export-ignore
|
||||
*.sh text eol=lf
|
||||
+12
-4
@@ -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
|
||||
|
||||
+10
-7
@@ -14,13 +14,16 @@ mkdir -p bootstrap/cache storage/framework storage/logs public/assets/vendor
|
||||
chown -R www-data:www-data bootstrap/cache storage/framework storage/logs public/assets/vendor
|
||||
chmod -R ug+rwX bootstrap/cache storage/framework storage/logs public/assets/vendor
|
||||
|
||||
# Install PHP dependencies
|
||||
echo "Installing PHP packages..."
|
||||
composer install \
|
||||
--no-dev \
|
||||
--prefer-dist \
|
||||
--no-interaction \
|
||||
--optimize-autoloader
|
||||
# PHP dependencies are installed in the image. Only install them here as a
|
||||
# fallback, e.g. when the app directory is mounted as a volume without vendor/.
|
||||
if [ ! -f vendor/autoload.php ]; then
|
||||
echo "vendor/ missing, installing PHP packages..."
|
||||
composer install \
|
||||
--no-dev \
|
||||
--prefer-dist \
|
||||
--no-interaction \
|
||||
--optimize-autoloader
|
||||
fi
|
||||
|
||||
# Install npm dependencies if package.json has dependencies
|
||||
if grep -q "\"dependencies\"" package.json; then
|
||||
|
||||
Reference in new issue
Block a user