Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 39 additions & 6 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3107,24 +3107,57 @@ async def compose_up(compose: PodmanCompose, args: argparse.Namespace) -> int |
.decode("utf-8")
.splitlines()
)
created_containers = []
diff_hashes = [i for i in hashes if i and i != compose.yaml_hash]
if (args.force_recreate and len(hashes) > 0) or len(diff_hashes):
if args.force_recreate and (hashes or diff_hashes):
log.info("recreating: ...")
down_args = argparse.Namespace(**dict(args.__dict__, volumes=False, rmi=None))
await compose.commands["down"](compose, down_args)
log.info("recreating: done\n\n")
# args.no_recreate disables check for changes (which is not implemented)
else:
# args.no_recreate disables check for changes (which is not implemented)
# so let's just check for running containers
created_containers = (
(
await compose.podman.output(
[],
"ps",
[
"--filter",
f"label=io.podman.compose.project={compose.project_name}",
"--filter",
"status=created",
"--filter",
"status=running",
"-a",
"--format",
"{{ .Names }}",
],
)
)
.decode("utf-8")
.splitlines()
)
log.debug("** Existing containers: %s", created_containers)

await create_pods(compose)
exit_code = 0

for cnt in compose.containers:
if cnt["_service"] in excluded:
log.debug("** skipping: %s", cnt["name"])
continue
podman_args = await container_to_args(compose, cnt, detached=False, no_deps=args.no_deps)
subproc_exit_code = await compose.podman.run([], "create", podman_args)
if subproc_exit_code is not None and subproc_exit_code != 0:
exit_code = subproc_exit_code

if args.force_recreate or cnt["name"] not in created_containers:
podman_args = await container_to_args(
compose, cnt, detached=False, no_deps=args.no_deps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also check for running containers and not start these?

Copy link
Author

@doc-sheet doc-sheet Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked - podman start for already started container just exits with rc 0 so I skipped extra validation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think it makes sense to add an explanatory comment near the call to podman start then.

)
subproc_exit_code = await compose.podman.run([], "create", podman_args)

if subproc_exit_code is not None and subproc_exit_code != 0:
exit_code = subproc_exit_code
else:
subproc_exit_code = 0

if not args.no_start and args.detach and subproc_exit_code is not None:
container_exit_code = await run_container(
Expand Down
6 changes: 1 addition & 5 deletions tests/integration/service_scale/test_podman_compose_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ def test_scaleup_cli(self) -> None:
"--scale",
"service1=4",
])
# error code 125 is expected as podman-compose complains about already used name
# "podman-compose_service1_1" for the 1st container
# Nevertheless, following containers are still created to scale as expected
# (in test case till 3 containers)
self.assertEqual(return_code, 125)
self.assertEqual(return_code, 0)

output, _, return_code = self.run_subprocess([
podman_compose_path(),
Expand Down