21 lines
606 B
Python
Executable File
21 lines
606 B
Python
Executable File
import json
|
|
|
|
data = json.loads(json_data)
|
|
|
|
env_file = "env_vars.sh"
|
|
|
|
with open(env_file, "w") as f:
|
|
f.write("# Environment variables generated from JSON data\n")
|
|
for ip, services in data.items():
|
|
if services:
|
|
for service in services:
|
|
_service = service["name"]
|
|
ports = service["ports"]
|
|
i = 1
|
|
for port in ports:
|
|
f.write(f"export {_service}_{i}_IP={ip}\n")
|
|
f.write(f"export {_service}_{i}_PORT={port['port']}\n")
|
|
i += 1
|
|
|
|
import os
|
|
os.chmod(env_file, 0o755) |