diff --git a/sources/python/main.py b/sources/python/main.py index e799efb..55fa215 100644 --- a/sources/python/main.py +++ b/sources/python/main.py @@ -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: