Skip to content

Commit 40f3870

Browse files
committed
Updates handling of scale/replicas args in CLI & compose file (Issue: containers#267)
Signed-off-by: Yashodhan Pise <[email protected]>
1 parent d1ba2f4 commit 40f3870

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

podman_compose.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,22 @@ def _parse_compose_file(self):
20802080
container_names_by_service = {}
20812081
self.services = services
20822082
for service_name, service_desc in services.items():
2083-
replicas = try_int(service_desc.get("deploy", {}).get("replicas"), fallback=1)
2083+
replicas = 1
2084+
if "scale" in args and args.scale is not None:
2085+
# Check `--scale` args from CLI command
2086+
scale_args = (args.scale.split('='))
2087+
replicas = try_int(scale_args[1], fallback=1) if service_name == scale_args[0] else 1
2088+
elif "scale" in service_desc:
2089+
# Check `scale` value from compose yaml file
2090+
replicas = try_int(service_desc.get("scale"), fallback=1)
2091+
elif (
2092+
"deploy" in service_desc
2093+
and "replicas" in service_desc.get("deploy", {})
2094+
and "replicated" == service_desc.get("deploy", {}).get("mode", '')
2095+
):
2096+
# Check `deploy: replicas:` value from compose yaml file
2097+
# Note: All conditions are necessary to handle case
2098+
replicas = try_int(service_desc.get("deploy", {}).get("replicas"), fallback=1)
20842099

20852100
container_names_by_service[service_name] = []
20862101
for num in range(1, replicas + 1):
@@ -3366,12 +3381,13 @@ def compose_up_parse(parser):
33663381
action="store_true",
33673382
help="Remove containers for services not defined in the Compose file.",
33683383
)
3384+
# `--scale` argument needs to store as single valye and not append,
3385+
# as multiple scale values could be confusing.
33693386
parser.add_argument(
33703387
"--scale",
3371-
metavar="SERVICE=NUM",
3372-
action="append",
33733388
help="Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if "
33743389
"present.",
3390+
metavar="SERVICE=NUM",
33753391
)
33763392
parser.add_argument(
33773393
"--exit-code-from",

0 commit comments

Comments
 (0)