Skip to content

Commit d007b86

Browse files
committed
Updates handling of scale/replicas args in CLI & compose file (Issue: containers#267)
1 parent d1ba2f4 commit d007b86

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

podman_compose.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,17 @@ 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 = try_int(args.scale, fallback=1) if "scale" in args else 1
2084+
# Skip `scale` or `replicas` check from compose yaml
2085+
# if `--scale=<NUM>` is specifiec in CLI arg
2086+
if 1 == replicas:
2087+
if "scale" in service_desc:
2088+
# Attempt to read parameter scale for service from compose yaml file
2089+
replicas = try_int(service_desc.get("scale"), fallback=1)
2090+
if "replicas" in service_desc:
2091+
# Attempt to read parameter deploy.replicas for service from compose yaml file
2092+
# Note: both conditions are necessary to handle case if `has_key("deploy")` is false
2093+
replicas = try_int(service_desc.get("deploy", {}).get("replicas"), fallback=1)
20842094

20852095
container_names_by_service[service_name] = []
20862096
for num in range(1, replicas + 1):
@@ -3366,12 +3376,15 @@ def compose_up_parse(parser):
33663376
action="store_true",
33673377
help="Remove containers for services not defined in the Compose file.",
33683378
)
3379+
# `--scale` argument needs to store as single valye and not append,
3380+
# as multiple scale values could be confusing.
33693381
parser.add_argument(
33703382
"--scale",
3371-
metavar="SERVICE=NUM",
3372-
action="append",
3383+
# action="store",
33733384
help="Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if "
33743385
"present.",
3386+
metavar="SERVICE=NUM",
3387+
type=int,
33753388
)
33763389
parser.add_argument(
33773390
"--exit-code-from",

0 commit comments

Comments
 (0)