fix: flat structure — compose.yaml + nginx.conf, production defaults
- /opt/fw/{name}/compose.yaml (flat, no subdirs)
- /opt/fw/{name}/nginx.conf (client_max_body_size 1024m, timeouts 300s)
- restart: always in compose + systemd units for dockerd/containerd
This commit is contained in:
parent
30fb7b2010
commit
a2650e5c36
1 changed files with 30 additions and 28 deletions
|
|
@ -50,20 +50,45 @@ def deploy_container(name, token, cloud, port, upstream_ip, upstream_port, label
|
|||
print(f"[{name}] Pulling Wallarm image...")
|
||||
run(f"docker pull {WALLARM_IMAGE}", timeout=300)
|
||||
|
||||
# Remove old container if exists
|
||||
# Remove old container
|
||||
container = f"wallarm-{name}"
|
||||
run(f"docker rm -f {container} 2>/dev/null", timeout=10)
|
||||
|
||||
host_dir = f"{BASE}/{name}"
|
||||
os.makedirs(f"{host_dir}/etc", exist_ok=True)
|
||||
os.makedirs(f"{host_dir}/nginx", exist_ok=True)
|
||||
# Write default nginx config if not exists
|
||||
nginx_conf = f"{host_dir}/nginx/default.conf"
|
||||
os.makedirs(host_dir, exist_ok=True)
|
||||
|
||||
# Generate compose.yaml
|
||||
compose_path = f"{host_dir}/compose.yaml"
|
||||
with open(compose_path, "w") as f:
|
||||
f.write(f"""services:
|
||||
wallarm:
|
||||
image: {WALLARM_IMAGE}
|
||||
container_name: {container}
|
||||
restart: always
|
||||
ports:
|
||||
- "{port}:80"
|
||||
environment:
|
||||
- WALLARM_API_TOKEN={token}
|
||||
- WALLARM_API_HOST={api_host}
|
||||
- WALLARM_MODE={mode}
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/http.d/default.conf:ro
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
""")
|
||||
|
||||
# Write nginx.conf with production defaults
|
||||
nginx_conf = f"{host_dir}/nginx.conf"
|
||||
if not os.path.exists(nginx_conf):
|
||||
with open(nginx_conf, "w") as f:
|
||||
f.write(f"""server {{
|
||||
listen 80;
|
||||
server_name _;
|
||||
client_max_body_size 1024m;
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
|
||||
location /wallarm-status {{
|
||||
wallarm_status on;
|
||||
|
|
@ -81,29 +106,6 @@ def deploy_container(name, token, cloud, port, upstream_ip, upstream_port, label
|
|||
}}
|
||||
""")
|
||||
|
||||
# Generate docker-compose.yml + start
|
||||
compose_path = f"{host_dir}/docker-compose.yml"
|
||||
with open(compose_path, "w") as f:
|
||||
f.write(f"""services:
|
||||
wallarm:
|
||||
image: {WALLARM_IMAGE}
|
||||
container_name: {container}
|
||||
restart: always
|
||||
ports:
|
||||
- "{port}:80"
|
||||
environment:
|
||||
- WALLARM_API_TOKEN={token}
|
||||
- WALLARM_API_HOST={api_host}
|
||||
- WALLARM_MODE={mode}
|
||||
volumes:
|
||||
- ./nginx/default.conf:/etc/nginx/http.d/default.conf:ro
|
||||
- ./etc:/opt/wallarm/etc
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
""")
|
||||
|
||||
print(f"[{name}] Starting via compose...")
|
||||
r = run(f"cd {host_dir} && docker compose up -d", timeout=30)
|
||||
if r.returncode != 0:
|
||||
|
|
|
|||
Loading…
Reference in a new issue