mirror of
https://gitlab.sectorq.eu/home/docker-compose.git
synced 2025-12-14 18:34:53 +01:00
build
This commit is contained in:
@@ -1,9 +1,50 @@
|
|||||||
import yaml
|
import yaml
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
stack_name = sys.argv[1]
|
stack_name = sys.argv[1]
|
||||||
INPUT_FILE = f"{stack_name}/docker-compose.yml"
|
INPUT_FILE = f"{stack_name}/docker-compose.yml"
|
||||||
OUTPUT_FILE = f"__swarm/{stack_name}/{stack_name}-swarm.yml"
|
OUTPUT_FILE = f"__swarm/{stack_name}/{stack_name}-swarm.yml"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def fix_env_file(filepath):
|
||||||
|
"""Convert YAML-style env (KEY: value) into Docker env (KEY=value)."""
|
||||||
|
fixed_lines = []
|
||||||
|
changed = False
|
||||||
|
|
||||||
|
with open(filepath, "r") as f:
|
||||||
|
for line in f:
|
||||||
|
stripped = line.strip()
|
||||||
|
|
||||||
|
# Skip empty/comment lines
|
||||||
|
if not stripped or stripped.startswith("#"):
|
||||||
|
fixed_lines.append(line)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Match YAML-style: KEY: value
|
||||||
|
m = re.match(r"^([A-Za-z0-9_]+):\s*(.*)$", stripped)
|
||||||
|
if m:
|
||||||
|
key, value = m.groups()
|
||||||
|
fixed = f"{key}={value}\n"
|
||||||
|
fixed_lines.append(fixed)
|
||||||
|
changed = True
|
||||||
|
else:
|
||||||
|
# Validate Docker env format
|
||||||
|
if " " in stripped:
|
||||||
|
raise ValueError(f"Invalid env line (contains spaces): {stripped}")
|
||||||
|
if ":" in stripped:
|
||||||
|
raise ValueError(f"Invalid env line (contains colon): {stripped}")
|
||||||
|
fixed_lines.append(line)
|
||||||
|
|
||||||
|
# Write back only if changes were needed
|
||||||
|
if changed:
|
||||||
|
with open(filepath, "w") as f:
|
||||||
|
f.writelines(fixed_lines)
|
||||||
|
print(f"[FIXED] Converted YAML env → Docker env in {filepath}")
|
||||||
|
else:
|
||||||
|
print(f"[OK] .env file already valid: {filepath}")
|
||||||
|
|
||||||
def convert_ports(ports):
|
def convert_ports(ports):
|
||||||
"""Convert short port syntax to Swarm long syntax."""
|
"""Convert short port syntax to Swarm long syntax."""
|
||||||
result = []
|
result = []
|
||||||
@@ -98,6 +139,7 @@ def convert_compose_to_swarm(data):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
fix_env_file(f"__swarm/{stack_name}/stack.env") # NEW FIX STEP
|
||||||
with open(INPUT_FILE, "r") as f:
|
with open(INPUT_FILE, "r") as f:
|
||||||
compose = yaml.safe_load(f)
|
compose = yaml.safe_load(f)
|
||||||
#input(compose)
|
#input(compose)
|
||||||
|
|||||||
Reference in New Issue
Block a user