This commit is contained in:
2025-11-30 15:35:00 +01:00
parent 63bf6b805b
commit bf052fae54
4 changed files with 50 additions and 21 deletions

View File

@@ -7,7 +7,9 @@ OUTPUT_FILE = f"__swarm/{stack_name}/{stack_name}-swarm.yml"
def convert_ports(ports):
"""Convert short port syntax to Swarm long syntax."""
result = []
print(f"Converting ports: {ports}")
for p in ports:
print(f"Port entry: {p}")
if isinstance(p, str):
# format: "8080:80"
pub, tgt = p.split(":")
@@ -45,9 +47,15 @@ def ensure_labels_as_string(labels):
def convert_compose_to_swarm(data):
services = data.get("services", {})
input(services)
for name, svc in services.items():
print(f"Converting service: {name} , svc: {svc}")
if name in ["container_name", "restart", "depends_on"]:
continue
svc.pop('restart', None)
svc.pop('depends_on', None)
svc.pop('container_name', None)
# 1) Convert environment list → dict (strings)
if "environment" in svc and isinstance(svc["environment"], list):
svc["environment"] = env_list_to_dict(svc["environment"])
@@ -77,6 +85,7 @@ def convert_compose_to_swarm(data):
# 6) Convert ports to long format
if "ports" in svc:
input(svc)
svc["ports"] = convert_ports(svc["ports"])
# 7) Remove container_name (not allowed in Swarm)
@@ -87,7 +96,7 @@ def convert_compose_to_swarm(data):
def main():
with open(INPUT_FILE, "r") as f:
compose = yaml.safe_load(f)
input(compose)
swarm = convert_compose_to_swarm(compose)
with open(OUTPUT_FILE, "w") as f: