feat: Domain-based app names + admin user seeding
- deploy.py: APP_NAME derived from APP_DOMAIN (e.g. crm.media-on.de → crm) - deploy.py: seed_admin_user() runs seed_admin.py after deploy - fast-deploy.sh: Same domain-based name derivation - No hardcoded leocrm-api/leocrm-worker defaults
This commit is contained in:
+36
-4
@@ -61,8 +61,15 @@ APP_UUID = os.environ.get("COOLIFY_APP_UUID", "")
|
||||
WORKER_UUID = os.environ.get("COOLIFY_WORKER_UUID", "")
|
||||
|
||||
# Names for API lookup when UUIDs are not provided
|
||||
APP_NAME = os.environ.get("APP_NAME", "leocrm-api")
|
||||
WORKER_NAME = os.environ.get("WORKER_NAME", "leocrm-worker")
|
||||
# Derive from APP_DOMAIN if not set (e.g. https://crm.media-on.de → crm)
|
||||
_domain_default = ""
|
||||
if os.environ.get("APP_DOMAIN"):
|
||||
try:
|
||||
_domain_default = os.environ["APP_DOMAIN"].split("//")[1].split(".")[0]
|
||||
except (IndexError, ValueError):
|
||||
pass
|
||||
APP_NAME = os.environ.get("APP_NAME", _domain_default or "app")
|
||||
WORKER_NAME = os.environ.get("WORKER_NAME", f"{APP_NAME}-worker")
|
||||
|
||||
# Domain (required)
|
||||
APP_DOMAIN = os.environ.get("APP_DOMAIN", "")
|
||||
@@ -723,6 +730,25 @@ def validate_config() -> list[str]:
|
||||
# ─── Main Deploy Pipeline ──────────────────────────────────────────────
|
||||
|
||||
|
||||
def seed_admin_user(app_uuid: str) -> StepResult:
|
||||
"""Seed admin user after fresh deployment via SSH into the app container."""
|
||||
admin_email = os.environ.get("ADMIN_EMAIL", "admin@media-on.de")
|
||||
admin_password = os.environ.get("ADMIN_PASSWORD", "Admin123!")
|
||||
if not admin_password:
|
||||
return StepResult(True, "Skipped — ADMIN_PASSWORD not set")
|
||||
print(f"\n[Seed] Seeding admin user ({admin_email})...")
|
||||
cmd = f"docker ps --filter name={app_uuid} --format '{{{{.Names}}}}' | grep crm-app | head -1"
|
||||
rc, container = ssh_run(cmd, timeout=30)
|
||||
if rc != 0 or not container.strip():
|
||||
return StepResult(False, f"Could not find crm-app container for {app_uuid}")
|
||||
container = container.strip()
|
||||
seed_cmd = f"docker exec {container} python3 /app/scripts/seed_admin.py"
|
||||
rc, out = ssh_run(seed_cmd, timeout=60)
|
||||
if rc != 0:
|
||||
return StepResult(False, f"Admin seed failed: {out.strip()}")
|
||||
return StepResult(True, f"Admin user seeded: {admin_email}")
|
||||
|
||||
|
||||
def deploy_full(skip_build: bool = False) -> int:
|
||||
"""Full deploy: API + Worker + Verification."""
|
||||
print(f"\n{'='*60}")
|
||||
@@ -770,8 +796,14 @@ def deploy_full(skip_build: bool = False) -> int:
|
||||
print("\n[2/3] Worker deploy skipped (no worker UUID resolved)")
|
||||
steps.append(("Worker deploy", StepResult(True, "Skipped — no worker configured")))
|
||||
|
||||
# Step 3: Verification
|
||||
print("\n[3/3] Running verification...")
|
||||
# Step 3: Seed admin user (if ADMIN_PASSWORD set)
|
||||
print("\n[3/4] Seeding admin user...")
|
||||
r = seed_admin_user(app_uuid)
|
||||
steps.append(("Admin seed", r))
|
||||
_print_result(r)
|
||||
|
||||
# Step 4: Verification
|
||||
print("\n[4/4] Running verification...")
|
||||
verify_results = run_verification(client, worker_uuid=worker_uuid)
|
||||
steps.extend(verify_results)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user