You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
3.2 KiB

#!/bin/sh
set -e
if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
# Host bind-mount: /app is often owned by another uid; git 2.35+ and Composer (VCS) warn or fail.
if command -v git >/dev/null 2>&1; then
git config --global --add safe.directory /app 2>/dev/null || true
fi
# Install the project the first time PHP is started
# After the installation, the following block can be deleted
if [ ! -f composer.json ]; then
rm -Rf tmp/
composer create-project "symfony/skeleton $SYMFONY_VERSION" tmp --stability="$STABILITY" --prefer-dist --no-progress --no-interaction --no-install
cd tmp
cp -Rp . ..
cd -
rm -Rf tmp/
composer require "php:>=$PHP_VERSION" runtime/frankenphp-symfony
composer config --json extra.symfony.docker 'true'
if [ -f .env ] && grep -q ^DATABASE_URL= .env; then
echo 'To finish the installation please press Ctrl+C to stop Docker Compose and run: docker compose up --build -d --wait'
sleep infinity
fi
fi
if [ ! -f vendor/autoload.php ]; then
set +e
composer install --prefer-dist --no-progress --no-interaction
CI_ERR=$?
set -e
if [ "$CI_ERR" -ne 0 ]; then
echo "composer install failed (exit $CI_ERR). If composer.json changed without composer.lock, syncing lock (symfony/process)…"
composer update symfony/process -W --prefer-dist --no-progress --no-interaction --ignore-platform-reqs
composer install --prefer-dist --no-progress --no-interaction
fi
fi
# DATABASE_URL from Compose / k8s env, or from a local .env file (dev bind-mount).
# Project `var/` is often gitignored; create dirs before setfacl so log/cache handlers can always run.
mkdir -p var/log var/cache
if [ -n "${DATABASE_URL:-}" ] || { [ -f .env ] && grep -q ^DATABASE_URL= .env; }; then
echo 'Waiting for database to be ready...'
ATTEMPTS_LEFT_TO_REACH_DATABASE=60
until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || DATABASE_ERROR=$(php bin/console dbal:run-sql -q "SELECT 1" 2>&1); do
if [ $? -eq 255 ]; then
# If the Doctrine command exits with 255, an unrecoverable error occurred
ATTEMPTS_LEFT_TO_REACH_DATABASE=0
break
fi
sleep 1
ATTEMPTS_LEFT_TO_REACH_DATABASE=$((ATTEMPTS_LEFT_TO_REACH_DATABASE - 1))
echo "Still waiting for database to be ready... Or maybe the database is not reachable. $ATTEMPTS_LEFT_TO_REACH_DATABASE attempts left."
done
if [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ]; then
echo 'The database is not up or not reachable:'
echo "$DATABASE_ERROR"
exit 1
else
echo 'The database is now ready and reachable'
fi
if [ "$( find ./migrations -iname '*.php' -print -quit )" ]; then
php bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing
fi
# Optional: warm magazine index + metadata cache on container start (does not run articles:get).
# Prefer ./scripts/docker-prewarm.sh or `make prewarm` for full DB + relay backfill from the host.
if [ "${PREWARM_ON_START:-0}" = "1" ]; then
echo "PREWARM_ON_START=1: running app:prewarm..."
php bin/console app:prewarm || true
fi
fi
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
fi
exec docker-php-entrypoint "$@"