Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote all string values to reduce probability of compose syntax errors #51

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove no longer necessary workarounds
  • Loading branch information
Galaxy102 committed Nov 14, 2022
commit 3b7eed29344fead95eb9dbae3dd04e71a448c353
18 changes: 2 additions & 16 deletions autocompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def render(struct, args, networks, volumes):
if args.version == 1:
pyaml.p(OrderedDict(struct))
else:
ans = {"version": '"3.6"', "services": struct}
ans = {"version": '3.6', "services": struct}

if networks is not None:
ans["networks"] = networks
Expand All @@ -128,20 +128,6 @@ def render(struct, args, networks, volumes):
pyaml.p(OrderedDict(ans), string_val_style='"')


def is_date_or_time(s: str):
for parse_func in [datetime.date.fromisoformat, datetime.datetime.fromisoformat]:
try:
parse_func(s.rstrip("Z"))
return True
except ValueError:
pass
return False


def fix_label(label: str):
return f"'{label}'" if is_date_or_time(label) else label


def generate(cname, createvolumes=False):
c = docker.from_env()

Expand Down Expand Up @@ -171,7 +157,7 @@ def generate(cname, createvolumes=False):
"environment": cattrs.get("Config", {}).get("Env", None),
"extra_hosts": cattrs.get("HostConfig", {}).get("ExtraHosts", None),
"image": cattrs.get("Config", {}).get("Image", None),
"labels": {label: fix_label(value) for label, value in cattrs.get("Config", {}).get("Labels", {}).items()},
"labels": cattrs.get("Config", {}).get("Labels", {}),
"links": cattrs.get("HostConfig", {}).get("Links"),
#'log_driver': cattrs.get('HostConfig']['LogConfig']['Type'],
#'log_opt': cattrs.get('HostConfig']['LogConfig']['Config'],
Expand Down