feat(service): add Compose profiles support#126
Open
ryan106 wants to merge 1 commit into
Open
Conversation
Adds `profiles` to Service plus a repeatable --profile flag and COMPOSE_PROFILES env var support, gating default service selection per the Compose spec (explicit targets and dependencies bypass the gate). up/build/down share one selection algorithm (Service.selectServices) so all three behave consistently for the same profile-gated graph; down now prints a note listing anything skipped due to an inactive profile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Compose spec lets services be gated behind named profiles:
docker composeonly startsdebug-toolswhendebugis active (--profile debugorCOMPOSE_PROFILES=debug);container-composehas noprofilessupport at all — the key is silently ignored, so profile-gated services always start. Projects that rely on Docker Compose profiles to scope multi-team stacks (auth-only vs. full-engine vs. frontend, etc.) can't reproduce that behavior.Solution
profiles: [String]?toService(plain list of strings per spec — no shorthand string form).--profileflag to the sharedComposeFileOptionsgroup (used byup/down/build), plus support for the spec'sCOMPOSE_PROFILESenvironment variable (comma-separated), merged with--profile.Service.isProfileEligible(activeProfiles:)implements the spec's default gate: noprofiles(or empty) → always eligible; otherwise eligible only if one of the service's profiles is active.Service.selectServices(from:requestedServices:activeProfiles:)is the shared selection algorithm forup,build, anddown: it seeds from either the explicitly requested services or the profile-eligible set, then walksdepends_on— matching the spec's stated exceptions, where an explicitly-named service and any service reached only as a dependency both bypass the profile gate regardless of their ownprofiles.ComposeBuildandComposeDownreuseselectServicesfor their own default (no explicit service args) selection, sobuild/up/downbehave consistently for the same profile-gated dependency graph.downadditionally prints a note listing any services skipped because their profile isn't active, so cleanup gaps aren't silent.Changes
Sources/Container-Compose/Codable Structs/Service.swift—profilesfield + decoding,isProfileEligible(activeProfiles:), and the sharedselectServices(from:requestedServices:activeProfiles:)(moved here alongsidetopoSortConfiguredServicessince it's now used by all three subcommands, not justup).Sources/Container-Compose/Commands/ComposeFileOptions.swift—--profileoption +activeProfiles(merges withCOMPOSE_PROFILES).Sources/Container-Compose/Commands/ComposeUp.swift— callsService.selectServices.Sources/Container-Compose/Commands/ComposeBuild.swift,ComposeDown.swift— default-selection paths now reuseService.selectServicesfor parity withup.Tests/Container-Compose-StaticTests/ProfilesTests.swift— decoding, eligibility, default/active/explicit/dependency selection, CLI parsing, andCOMPOSE_PROFILESmerging (suite marked.serializedsince two tests mutate the process environment).Tests/Container-Compose-StaticTests/ServiceDependencyTests.swift— updated one existing call site for theselectServicesrename.