#!/bin/sh set -e # ============================================================================== # EZSCALE app container entrypoint # Used by `app`, `horizon`, and `scheduler` services. Idempotent. # ============================================================================== cd /var/www/html # Wait for MariaDB. depends_on: condition: service_healthy already gates this, # but the belt-and-braces loop is cheap and survives healthcheck regressions. if [ -n "${DB_HOST:-}" ]; then echo "[entrypoint] waiting for ${DB_HOST}:${DB_PORT:-3306}..." until php -r "new PDO('mysql:host=${DB_HOST};port=${DB_PORT:-3306}', '${DB_USERNAME}', '${DB_PASSWORD}');" 2>/dev/null; do sleep 1 done echo "[entrypoint] mariadb is up." fi # Bootstrap .env on first boot. We bind-mount the website/ source, so .env may # already exist from a previous bare-metal `composer run dev` workflow. if [ ! -f .env ]; then if [ -f /var/www/html/.env.docker ]; then echo "[entrypoint] copying .env.docker -> .env" cp /var/www/html/.env.docker .env elif [ -f .env.example ]; then echo "[entrypoint] copying .env.example -> .env (fallback)" cp .env.example .env fi fi # Vendor dir bootstrapping — first-clone convenience. Skipped if already present. if [ ! -d vendor ] || [ ! -f vendor/autoload.php ]; then echo "[entrypoint] vendor/ missing; running composer install" composer install --no-interaction --prefer-dist --no-progress fi # Generate APP_KEY if blank. `key:generate` writes to .env in place. if ! grep -qE '^APP_KEY=base64:' .env; then echo "[entrypoint] generating APP_KEY" php artisan key:generate --force --no-interaction fi # Run migrations only when this container is the `app` (php-fpm) role. # Horizon and scheduler share this image but skip migrations to avoid races. case "$1" in php-fpm|php-fpm*) echo "[entrypoint] running migrations" php artisan migrate --force --no-interaction || true php artisan storage:link || true ;; esac exec "$@"