Files
nhgooi.nl/docker-entrypoint.sh
T
eric.busandClaude Opus 5.5 2ddcb1b6b0 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>
2026-11-20 13:33:07 +01:00

45 lines
1.3 KiB
Bash

#!/bin/bash
set -e
cd /var/www/app
# Set HOME for npm cache (www-data user needs writable cache directory)
export HOME=/tmp
echo "Setting up dependencies..."
# Create vendor directories and fix permissions
echo "Fixing permissions..."
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
# 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
echo "Installing npm packages..."
npm ci --omit=dev
node scripts/setup-vendor.js
fi
# Fix permissions
echo "Fixing permissions..."
chown -R www-data:www-data \
bootstrap/cache \
public/assets/vendor
chmod -R ug+rwX bootstrap/cache
echo "✓ Setup complete, starting Apache..."
exec apache2-foreground