Skip to content
Draft
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
20 changes: 15 additions & 5 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,8 @@ def _parse_compose_file(self) -> None:
}
requested_profiles = set(args.profile).union(profiles_from_env)

target_service = (args and 'service' in args and args.service) or None

compose: dict[str, Any] = {}
# Iterate over files primitively to allow appending to files in-loop
files_iter = iter(files)
Expand Down Expand Up @@ -2319,7 +2321,8 @@ def _parse_compose_file(self) -> None:
# Solution is to remove 'include' key from compose obj. This doesn't break
# having `include` present and correctly processed in included files
del compose["include"]
resolved_services = self._resolve_profiles(compose.get("services", {}), requested_profiles)
resolved_services = self._resolve_profiles(compose.get("services", {}), requested_profiles,
target_service)
compose["services"] = resolved_services
if not getattr(args, "no_normalize", None):
compose = normalize_final(compose, self.dirname)
Expand All @@ -2341,7 +2344,7 @@ def _parse_compose_file(self) -> None:
services = {}
log.warning("WARNING: No services defined")
# include services with no profile defined or the selected profiles
services = self._resolve_profiles(services, requested_profiles)
services = self._resolve_profiles(services, requested_profiles, target_service)

# NOTE: maybe add "extends.service" to _deps at this stage
flat_deps(services, with_extends=True)
Expand Down Expand Up @@ -2476,21 +2479,28 @@ def _parse_compose_file(self) -> None:
self.container_by_name = {c["name"]: c for c in given_containers}

def _resolve_profiles(
self, defined_services: dict[str, Any], requested_profiles: set[str] | None = None
self,
defined_services: dict[str, Any],
requested_profiles: set[str] | None = None,
target: str | None = None,
) -> dict[str, Any]:
"""
Returns a service dictionary (key = service name, value = service config) compatible with
the requested_profiles list.
the requested_profiles list and target service.

The returned service dictionary contains all services which do not include/reference a
profile in addition to services that match the requested_profiles.
profile, match the requested_profiles, and match profiles of an explicitly targeted service.

:param defined_services: The service dictionary
:param requested_profiles: The profiles requested using the --profile arg.
:param target: Name of service targeted by the current command
"""
if requested_profiles is None:
requested_profiles = set()

if target:
requested_profiles |= set(defined_services.get(target, {}).get("profiles", []))

services = {}

for name, config in defined_services.items():
Expand Down
Loading