Fix deploy.py: Use /deploy endpoint for Worker Service + connect_to_docker_network
This commit is contained in:
+34
-21
@@ -260,25 +260,38 @@ def deploy_api(client: CoolifyClient, skip_build: bool = False) -> StepResult:
|
|||||||
|
|
||||||
|
|
||||||
def deploy_worker(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
|
The worker is a Coolify Service that uses the same Docker image as the
|
||||||
API application (stvabl4vaqru7jclx4ittzr3:latest). After the API is
|
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
|
Uses POST /deploy with the service UUID — this is the correct way to
|
||||||
service's compose definition (which has all the correct environment
|
deploy a Coolify Service (not restart, which only restarts an existing
|
||||||
variables, volumes, and network settings configured via the Coolify UI).
|
container, and not start, which fails if the container was removed).
|
||||||
|
|
||||||
After restart, we ensure:
|
We also ensure:
|
||||||
1. The :latest tag points to the most recent build (Coolify tags with
|
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)
|
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...")
|
print(" Deploying worker service via Coolify API...")
|
||||||
|
|
||||||
try:
|
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)
|
# Step 1: Tag the latest API image as :latest (Coolify uses commit-hash tags)
|
||||||
print(" Tagging latest API image as :latest...")
|
print(" Tagging latest API image as :latest...")
|
||||||
tag_code, tag_output = ssh_run(
|
tag_code, tag_output = ssh_run(
|
||||||
@@ -289,19 +302,19 @@ def deploy_worker(client: CoolifyClient, skip_build: bool = False) -> StepResult
|
|||||||
if tag_code != 0:
|
if tag_code != 0:
|
||||||
print(f" Warning: could not tag :latest ({tag_output.strip()})")
|
print(f" Warning: could not tag :latest ({tag_output.strip()})")
|
||||||
|
|
||||||
# Step 2: Restart the service to pick up the latest image
|
# Step 2: Deploy the service via POST /deploy (creates new container)
|
||||||
print(" Restarting worker service...")
|
print(" Deploying worker service...")
|
||||||
client.restart_service(WORKER_UUID)
|
result = client.deploy_application(WORKER_UUID)
|
||||||
time.sleep(5)
|
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
|
# Step 3: Wait for service to be healthy
|
||||||
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
|
|
||||||
return _wait_service_healthy(client, WORKER_UUID, timeout=120)
|
return _wait_service_healthy(client, WORKER_UUID, timeout=120)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user