customer-riverside/docker/php/entrypoint.sh

85 lines
3.2 KiB
Bash
Raw Normal View History

2026-04-19 20:33:56 -08:00
#!/bin/sh
DB_HOST="${DB_HOST:-postgres}"
DB_USER="${DB_USER:-drupal}"
DB_NAME="${DB_NAME:-drupal}"
echo "[entrypoint] Waiting for PostgreSQL at ${DB_HOST}..."
until pg_isready -h "$DB_HOST" -U "$DB_USER" -d "$DB_NAME" -q; do
sleep 1
done
echo "[entrypoint] PostgreSQL is ready."
cd /var/www/html
DRUSH="vendor/bin/drush --root=/var/www/html/web"
HAS_TABLES=$($DRUSH sql:query \
2026-05-14 19:39:30 -08:00
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='public' AND table_name='users';" \
2026-04-19 20:33:56 -08:00
2>/dev/null || echo "0")
IS_SETUP=$($DRUSH sql:query \
"SELECT COUNT(*) FROM config WHERE name='core.extension' AND data LIKE '%riverside_pt%';" \
2>/dev/null || echo "0")
if [ "$HAS_TABLES" != "1" ]; then
2026-04-19 20:33:56 -08:00
echo "[entrypoint] Fresh database, installing Drupal..."
2026-05-12 16:28:47 -08:00
$DRUSH site:install standard \
2026-04-19 20:33:56 -08:00
--site-name="${SITE_NAME:-Portfolio}" \
--account-name=admin \
--account-pass="${ADMIN_PASS:-admin}" \
-y || { echo "[entrypoint] FATAL: site:install failed."; exit 1; }
2026-04-19 20:33:56 -08:00
echo "[entrypoint] Drupal installed."
fi
2026-04-19 20:33:56 -08:00
if [ "$IS_SETUP" != "1" ]; then
echo "[entrypoint] Running setup (first boot or recovery from failed setup)..."
2026-05-12 16:28:47 -08:00
$DRUSH en -y views views_ui field_ui text options link datetime && \
echo "[entrypoint] Core modules enabled." || echo "[entrypoint] WARNING: core modules failed."
$DRUSH en -y webform webform_ui && \
echo "[entrypoint] Webform enabled." || echo "[entrypoint] WARNING: webform failed."
$DRUSH en -y symfony_mailer && \
echo "[entrypoint] Mailer enabled." || echo "[entrypoint] WARNING: symfony_mailer failed."
$DRUSH en -y riverside_pt && \
echo "[entrypoint] riverside_pt enabled." || echo "[entrypoint] WARNING: riverside_pt failed."
2026-05-01 03:18:57 -08:00
$DRUSH config:set system.site page.front /home -y && \
echo "[entrypoint] Front page set." || echo "[entrypoint] WARNING: front page config failed."
2026-05-16 08:52:21 -08:00
$DRUSH theme:enable starterkit_theme claro_compact -y && \
$DRUSH config:set system.theme default starterkit_theme -y && \
$DRUSH config:set system.theme admin claro_compact -y && \
echo "[entrypoint] Themes set." || echo "[entrypoint] WARNING: theme enable failed."
2026-05-01 03:18:57 -08:00
2026-04-19 20:33:56 -08:00
if ls /var/www/html/config/sync/*.yml >/dev/null 2>&1; then
echo "[entrypoint] Importing configuration from sync dir..."
2026-05-14 19:39:30 -08:00
$DRUSH config:import --partial -y || echo "[entrypoint] WARNING: config import failed."
2026-04-19 20:33:56 -08:00
fi
echo "[entrypoint] Setup complete."
else
echo "[entrypoint] Setup already complete, importing configuration..."
2026-05-14 19:39:30 -08:00
$DRUSH config:import -y >/dev/null 2>&1 && \
echo "[entrypoint] Config imported." || \
echo "[entrypoint] No config to import, continuing."
fi
2026-05-01 03:42:53 -08:00
2026-05-16 10:45:33 -08:00
npm run build --prefix /var/www/html >/dev/null 2>&1 && echo "[entrypoint] Tailwind built." || echo "[entrypoint] WARNING: Tailwind build failed."
2026-05-14 20:23:54 -08:00
$DRUSH cache:rebuild >/dev/null 2>&1 && echo "[entrypoint] Cache rebuilt."
2026-05-24 18:23:05 -08:00
if [ "${DEBUG:-false}" = "true" ]; then
NGINX_CSS_CACHE='expires off; add_header Cache-Control "no-store";'
else
NGINX_CSS_CACHE='expires max;'
fi
export NGINX_CSS_CACHE
envsubst '${NGINX_CSS_CACHE}' \
< /etc/nginx/conf.d/default.conf.template \
> /etc/nginx/conf.d/default.conf
echo "[entrypoint] nginx cache mode: ${DEBUG:-false} = debug."
2026-04-19 20:33:56 -08:00
echo "[entrypoint] Starting services..."
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf