60 lines
1.8 KiB
Bash
60 lines
1.8 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
cd /var/www/html
|
|
|
|
# Install PHP dependencies on first boot (the app is bind-mounted from ./src)
|
|
if [ ! -f vendor/autoload.php ]; then
|
|
echo "vendor/ missing - running composer install..."
|
|
composer install --no-interaction --prefer-dist --no-progress
|
|
fi
|
|
|
|
# Provide Swagger UI assets to the bind-mounted public directory
|
|
if [ -d /opt/swagger-ui ] && [ ! -f public/vendor/swagger-ui/swagger-ui-bundle.js ]; then
|
|
echo "Installing Swagger UI assets..."
|
|
mkdir -p public/vendor/swagger-ui
|
|
cp /opt/swagger-ui/* public/vendor/swagger-ui/
|
|
fi
|
|
|
|
# Directory for admin-uploaded theme assets (logo)
|
|
mkdir -p public/uploads/theme
|
|
|
|
# Compile Tailwind CSS
|
|
if [ -f resources/css/app.css ]; then
|
|
echo "Building Tailwind CSS..."
|
|
tailwindcss -i resources/css/app.css -o public/css/app.css --minify
|
|
fi
|
|
|
|
# Wait for the database to accept connections
|
|
echo "Waiting for database at ${DB_HOST}:${DB_PORT}..."
|
|
until php -r '
|
|
try {
|
|
new PDO(
|
|
"mysql:host=" . getenv("DB_HOST") . ";port=" . getenv("DB_PORT"),
|
|
getenv("DB_USERNAME"),
|
|
getenv("DB_PASSWORD"),
|
|
[PDO::ATTR_TIMEOUT => 3]
|
|
);
|
|
} catch (Throwable $e) {
|
|
exit(1);
|
|
}
|
|
' 2>/dev/null; do
|
|
echo " ...database not ready, retrying"
|
|
sleep 2
|
|
done
|
|
echo "Database is up."
|
|
|
|
php artisan migrate --force
|
|
php artisan db:seed --force
|
|
|
|
# Cache config/routes/views (re-built on every container start, so restarts
|
|
# always pick up changes; run `php artisan optimize:clear` while iterating).
|
|
php artisan optimize
|
|
|
|
# Make runtime directories writable by the web server.
|
|
# chown can be a no-op or fail on Windows bind mounts - never fatal.
|
|
chown -R www-data:www-data storage bootstrap/cache 2>/dev/null || true
|
|
chmod -R ugo+rwX storage bootstrap/cache 2>/dev/null || true
|
|
|
|
exec "$@"
|