Files
seoulmate_bot_v1/services/bot/entrypoint.sh
2025-08-12 21:02:23 +09:00

27 lines
784 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [ -f "/app/.env" ]; then
set -a; source /app/.env; set +a
fi
echo "Waiting for DB..."
python - <<'PY'
import os, time, pymysql
url = os.environ["DATABASE_URL"]
u = url.split("://",1)[1].split("@",1)
auth, host_db = u[0], u[1]
host, port_db = host_db.split("/",1)[0], host_db.split("/",1)[1]
host, port = host.split(":")[0], int(host.split(":")[1] or 3306)
user, password = auth.split(":")[0], ":".join(auth.split(":")[1:])
db = port_db.split("?")[0]
for i in range(60):
try:
conn = pymysql.connect(host=host, port=port, user=user, password=password, database=db)
conn.close()
break
except Exception as e:
print("Waiting DB...", e)
time.sleep(2)
PY
alembic upgrade head
exec python -m app.main