From 8ac90e4dd6db3d9f0df2aaf4dd2eff6af0bbd186 Mon Sep 17 00:00:00 2001 From: Agent Zero Date: Mon, 3 Aug 2026 01:22:44 +0200 Subject: [PATCH] deploy.py: .env nach update_service schreiben + _wait_service_healthy Bug fix --- scripts/deploy.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scripts/deploy.py b/scripts/deploy.py index b3d0b02..f2a0c5b 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -311,23 +311,12 @@ def deploy_worker(client: CoolifyClient, skip_build: bool = False) -> StepResult print(" Deploying worker service via Coolify API...") try: - # Step 1: Write .env file to server - print(" Writing .env file to server...") - import base64 - env_encoded = base64.b64encode(WORKER_ENV_CONTENT.encode()).decode() - env_code, env_output = ssh_run( - f'echo {env_encoded} | base64 -d > ' - f'/data/coolify/services/{WORKER_UUID}/.env && echo ENV_OK' - ) - if env_code != 0 or 'ENV_OK' not in env_output: - print(f" Warning: could not write .env ({env_output.strip()})") - - # Step 2: Update service compose with ${VARIABLE} syntax + # Step 1: Update service compose with ${VARIABLE} syntax print(" Updating worker service compose...") client.update_service(WORKER_UUID, WORKER_COMPOSE_YAML) time.sleep(2) - # Step 3: Set connect_to_docker_network=True + # Step 2: Set connect_to_docker_network=True print(" Ensuring coolify network connection...") import httpx resp = httpx.patch( @@ -339,6 +328,18 @@ def deploy_worker(client: CoolifyClient, skip_build: bool = False) -> StepResult if resp.status_code != 200: print(f" Warning: could not set connect_to_docker_network ({resp.status_code})") + # Step 3: Write .env file to server (AFTER update_service, because + # Coolify may regenerate .env during update/deploy) + print(" Writing .env file to server...") + import base64 + env_encoded = base64.b64encode(WORKER_ENV_CONTENT.encode()).decode() + env_code, env_output = ssh_run( + f'echo {env_encoded} | base64 -d > ' + f'/data/coolify/services/{WORKER_UUID}/.env && echo ENV_OK' + ) + if env_code != 0 or 'ENV_OK' not in env_output: + print(f" Warning: could not write .env ({env_output.strip()})") + # Step 4: Tag the latest API image as :latest print(" Tagging latest API image as :latest...") tag_code, tag_output = ssh_run( @@ -408,7 +409,8 @@ def _wait_service_healthy(client: CoolifyClient, service_uuid: str, timeout: int status = svc.get("status", "unknown") elapsed = int(time.time() - start) print(f" [{elapsed}s] Service status: {status}") - if "healthy" in status.lower(): + # Only accept exact 'running:healthy' or 'healthy' + if status == "running:healthy" or status == "healthy": return StepResult(True, f"Service healthy: {status}", time.time() - start, svc) if "failed" in status.lower() or "error" in status.lower(): return StepResult(False, f"Service failed: {status}", time.time() - start, svc)