From 689d377683ece43db7ce8e13e90028744193f4b6 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 4 Nov 2024 00:39:21 +0100 Subject: [PATCH] Add docker-compose defaults --- main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index cef698a..fffdc98 100755 --- a/main.py +++ b/main.py @@ -66,10 +66,13 @@ def write_build_unit(args, yaml_dict: dict, service_name: str): def write_network_units(args, yaml_dict): - for network_name in yaml_dict.get("networks", []): + networks = yaml_dict.get("networks", {}) + if "default" not in networks: + networks["default"] = None + for network_name in networks: out_file = args.output_dir / f"{network_name}.network" print(f'Generating network "{network_name}" ({out_file})') - network = yaml_dict["networks"].get(network_name) + network = networks.get(network_name) if network is None: network = {} @@ -148,6 +151,11 @@ def write_service_units(args, yaml_dict): if "volumes" in service: enforce_list("volumes", service) unit_file["Container"]["Volume"] = service["volumes"] + if "networks" in service: + enforce_list("networks", service) + unit_file["Container"]["Network"] = service["networks"] + else: + unit_file["Container"]["Network"] = ["default"] if "devices" in service: unit_file["Container"]["AddDevice"] = service["devices"] if "userns_mode" in service: