fix: start.sh per node — declarative config + startup, no compose needed
This commit is contained in:
parent
a2650e5c36
commit
202f0e2dc8
1 changed files with 20 additions and 22 deletions
|
|
@ -57,27 +57,25 @@ def deploy_container(name, token, cloud, port, upstream_ip, upstream_port, label
|
||||||
host_dir = f"{BASE}/{name}"
|
host_dir = f"{BASE}/{name}"
|
||||||
os.makedirs(host_dir, exist_ok=True)
|
os.makedirs(host_dir, exist_ok=True)
|
||||||
|
|
||||||
# Generate compose.yaml
|
# Generate start.sh (declarative config + startup in one file)
|
||||||
compose_path = f"{host_dir}/compose.yaml"
|
start_path = f"{host_dir}/start.sh"
|
||||||
with open(compose_path, "w") as f:
|
with open(start_path, "w") as f:
|
||||||
f.write(f"""services:
|
f.write(f"""#!/bin/bash
|
||||||
wallarm:
|
# Wallarm node: {name}
|
||||||
image: {WALLARM_IMAGE}
|
docker rm -f {container} 2>/dev/null || true
|
||||||
container_name: {container}
|
docker run -d \\
|
||||||
restart: always
|
--name {container} \\
|
||||||
ports:
|
--restart always \\
|
||||||
- "{port}:80"
|
-p {port}:80 \\
|
||||||
environment:
|
-e WALLARM_API_TOKEN='{token}' \\
|
||||||
- WALLARM_API_TOKEN={token}
|
-e WALLARM_API_HOST={api_host} \\
|
||||||
- WALLARM_API_HOST={api_host}
|
-e WALLARM_MODE={mode} \\
|
||||||
- WALLARM_MODE={mode}
|
-v {host_dir}/nginx.conf:/etc/nginx/http.d/default.conf:ro \\
|
||||||
volumes:
|
{WALLARM_IMAGE}
|
||||||
- ./nginx.conf:/etc/nginx/http.d/default.conf:ro
|
sleep 3
|
||||||
logging:
|
docker ps --filter name={container} --format '{{{{.Status}}}}'
|
||||||
driver: json-file
|
|
||||||
options:
|
|
||||||
max-size: 10m
|
|
||||||
""")
|
""")
|
||||||
|
os.chmod(start_path, 0o755)
|
||||||
|
|
||||||
# Write nginx.conf with production defaults
|
# Write nginx.conf with production defaults
|
||||||
nginx_conf = f"{host_dir}/nginx.conf"
|
nginx_conf = f"{host_dir}/nginx.conf"
|
||||||
|
|
@ -106,8 +104,8 @@ def deploy_container(name, token, cloud, port, upstream_ip, upstream_port, label
|
||||||
}}
|
}}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
print(f"[{name}] Starting via compose...")
|
print(f"[{name}] Starting...")
|
||||||
r = run(f"cd {host_dir} && docker compose up -d", timeout=30)
|
r = run(f"bash {start_path}", timeout=30)
|
||||||
if r.returncode != 0:
|
if r.returncode != 0:
|
||||||
print(f"❌ {name}: {r.stderr}")
|
print(f"❌ {name}: {r.stderr}")
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue