deploy.py: .env nach update_service schreiben + _wait_service_healthy Bug fix
This commit is contained in:
+16
-14
@@ -311,23 +311,12 @@ def deploy_worker(client: CoolifyClient, skip_build: bool = False) -> StepResult
|
|||||||
print(" Deploying worker service via Coolify API...")
|
print(" Deploying worker service via Coolify API...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Step 1: Write .env file to server
|
# Step 1: Update service compose with ${VARIABLE} syntax
|
||||||
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
|
|
||||||
print(" Updating worker service compose...")
|
print(" Updating worker service compose...")
|
||||||
client.update_service(WORKER_UUID, WORKER_COMPOSE_YAML)
|
client.update_service(WORKER_UUID, WORKER_COMPOSE_YAML)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# Step 3: Set connect_to_docker_network=True
|
# Step 2: Set connect_to_docker_network=True
|
||||||
print(" Ensuring coolify network connection...")
|
print(" Ensuring coolify network connection...")
|
||||||
import httpx
|
import httpx
|
||||||
resp = httpx.patch(
|
resp = httpx.patch(
|
||||||
@@ -339,6 +328,18 @@ def deploy_worker(client: CoolifyClient, skip_build: bool = False) -> StepResult
|
|||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
print(f" Warning: could not set connect_to_docker_network ({resp.status_code})")
|
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
|
# Step 4: Tag the latest API image as :latest
|
||||||
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(
|
||||||
@@ -408,7 +409,8 @@ def _wait_service_healthy(client: CoolifyClient, service_uuid: str, timeout: int
|
|||||||
status = svc.get("status", "unknown")
|
status = svc.get("status", "unknown")
|
||||||
elapsed = int(time.time() - start)
|
elapsed = int(time.time() - start)
|
||||||
print(f" [{elapsed}s] Service status: {status}")
|
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)
|
return StepResult(True, f"Service healthy: {status}", time.time() - start, svc)
|
||||||
if "failed" in status.lower() or "error" in status.lower():
|
if "failed" in status.lower() or "error" in status.lower():
|
||||||
return StepResult(False, f"Service failed: {status}", time.time() - start, svc)
|
return StepResult(False, f"Service failed: {status}", time.time() - start, svc)
|
||||||
|
|||||||
Reference in New Issue
Block a user