diff --git a/scripts/deploy.py b/scripts/deploy.py index 24c8ebd..77af471 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -260,25 +260,38 @@ def deploy_api(client: CoolifyClient, skip_build: bool = False) -> StepResult: def deploy_worker(client: CoolifyClient, skip_build: bool = False) -> StepResult: - """Restart the worker service via Coolify API. + """Deploy the worker service via Coolify API. The worker is a Coolify Service that uses the same Docker image as the API application (stvabl4vaqru7jclx4ittzr3:latest). After the API is - rebuilt, the worker just needs a restart to pick up the new image. + rebuilt, the worker needs a deploy to pick up the new image. - We do NOT call update_service because that would overwrite the Coolify - service's compose definition (which has all the correct environment - variables, volumes, and network settings configured via the Coolify UI). + Uses POST /deploy with the service UUID — this is the correct way to + deploy a Coolify Service (not restart, which only restarts an existing + container, and not start, which fails if the container was removed). - After restart, we ensure: - 1. The :latest tag points to the most recent build (Coolify tags with + We also ensure: + 1. connect_to_docker_network is True (so the worker joins the coolify + network and can reach crm-redis and crm-postgres) + 2. The :latest tag points to the most recent build (Coolify tags with commit hashes, not :latest) - 2. The worker container is connected to the coolify network (needed to - reach crm-redis and crm-postgres) """ print(" Deploying worker service via Coolify API...") try: + # Step 0: Ensure connect_to_docker_network is True + print(" Ensuring coolify network connection...") + # Set connect_to_docker_network via API (does not overwrite compose) + import httpx + resp = httpx.patch( + f"{client.base_url}/api/v1/services/{WORKER_UUID}", + headers=client.headers, + json={"connect_to_docker_network": True}, + timeout=30, + ) + if resp.status_code != 200: + print(f" Warning: could not set connect_to_docker_network ({resp.status_code})") + # Step 1: Tag the latest API image as :latest (Coolify uses commit-hash tags) print(" Tagging latest API image as :latest...") tag_code, tag_output = ssh_run( @@ -289,19 +302,19 @@ def deploy_worker(client: CoolifyClient, skip_build: bool = False) -> StepResult if tag_code != 0: print(f" Warning: could not tag :latest ({tag_output.strip()})") - # Step 2: Restart the service to pick up the latest image - print(" Restarting worker service...") - client.restart_service(WORKER_UUID) - time.sleep(5) + # Step 2: Deploy the service via POST /deploy (creates new container) + print(" Deploying worker service...") + result = client.deploy_application(WORKER_UUID) + deploy_uuid = _extract_deploy_uuid(result) + if deploy_uuid: + print(f" Worker deploy queued: {deploy_uuid[:12]}") + dep_result = _wait_deployment(client, deploy_uuid, timeout=120) + if not dep_result.success: + return dep_result + else: + print(" No deployment UUID returned, waiting for healthy...") - # Step 3: Ensure worker is connected to coolify network - print(" Ensuring coolify network connection...") - net_code, net_output = ssh_run( - 'docker network connect coolify worker-asxqaq3566to108xordck0ff 2>/dev/null; ' - 'echo done' - ) - - # Step 4: Wait for service to be healthy + # Step 3: Wait for service to be healthy return _wait_service_healthy(client, WORKER_UUID, timeout=120) except Exception as e: