Skip to content

Commit 604b54e

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 604b54e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

podman_compose.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,23 @@ 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+
if service_name == scale_args[0]:
2088+
replicas = try_int(scale_args[1], fallback=1)
2089+
elif "scale" in service_desc:
2090+
# Check `scale` value from compose yaml file
2091+
replicas = try_int(service_desc.get("scale"), fallback=1)
2092+
elif (
2093+
"deploy" in service_desc
2094+
and "replicas" in service_desc.get("deploy", {})
2095+
and "replicated" == service_desc.get("deploy", {}).get("mode", '')
2096+
):
2097+
# Check `deploy: replicas:` value from compose yaml file
2098+
# Note: All conditions are necessary to handle case
2099+
replicas = try_int(service_desc.get("deploy", {}).get("replicas"), fallback=1)
20842100

20852101
container_names_by_service[service_name] = []
20862102
for num in range(1, replicas + 1):
@@ -3366,12 +3382,13 @@ def compose_up_parse(parser):
33663382
action="store_true",
33673383
help="Remove containers for services not defined in the Compose file.",
33683384
)
3385+
# `--scale` argument needs to store as single value and not append,
3386+
# as multiple scale values could be confusing.
33693387
parser.add_argument(
33703388
"--scale",
33713389
metavar="SERVICE=NUM",
3372-
action="append",
3373-
help="Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if "
3374-
"present.",
3390+
help="Scale SERVICE to NUM instances. "
3391+
"Overrides the `scale` setting in the Compose file if present.",
33753392
)
33763393
parser.add_argument(
33773394
"--exit-code-from",

0 commit comments

Comments
 (0)