Skip to content

feat(up): stamp com.docker.compose project/service labels on containers#110

Merged
Cyb3rDudu merged 2 commits into
Mcrich23:mainfrom
DonsWayo:feat/compose-project-labels
Jun 27, 2026
Merged

feat(up): stamp com.docker.compose project/service labels on containers#110
Cyb3rDudu merged 2 commits into
Mcrich23:mainfrom
DonsWayo:feat/compose-project-labels

Conversation

@DonsWayo

@DonsWayo DonsWayo commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

container-compose up names containers <project>-<service> but writes no labels
(container inspectlabels: {}). External tools (GUIs, dashboards, scripts) that want to
group a stack's containers are forced to guess from the name prefix, which mis-groups
unrelated containers that merely share a prefix (e.g. qa-web + qa-cache).

This stamps the de-facto-standard Docker Compose labels on each container at creation:

  • com.docker.compose.project=<project>
  • com.docker.compose.service=<service>

so any tool can group a stack reliably via labels. No behavior change otherwise
down/ps continue to work by name.

Diff

One file, +6 in ComposeUp.swift, right after --name is appended:

runCommandArgs.append(contentsOf: ["--label", "com.docker.compose.project=\(projectName)"])
runCommandArgs.append(contentsOf: ["--label", "com.docker.compose.service=\(serviceName)"])

Verified (macOS 26, container 1.0.0)

$ container-compose up -d --file docker-compose.yml   # name: lblproj, service: one
$ container inspect lblproj-one | jq .configuration.labels
{
  "com.docker.compose.project": "lblproj",
  "com.docker.compose.service": "one"
}
$ container-compose down --file docker-compose.yml     # tears down unchanged

Built from source and run against a real daemon; swift build clean.

Notes

Containers created by `up` carry no labels, so tools that want to group a stack must
guess from the `<project>-<service>` name prefix — which mis-groups unrelated containers
that merely share a prefix. Stamp the de-facto-standard Docker Compose labels at creation:

  com.docker.compose.project=<project>
  com.docker.compose.service=<service>

so any tool can group reliably via `container inspect`. No behavior change otherwise;
down/ps continue to work by name.

Verified on macOS 26 + container 1.0.0: after `up`, `container inspect <project>-<service>`
shows both labels; `down` tears the stack down unchanged.
DonsWayo added a commit to DonsWayo/consai that referenced this pull request Jun 17, 2026
)

Adds label-based grouping as step 0 of assembly (always on, no guessing): containers
carrying com.docker.compose.project group into a .composeLabeled stack regardless of the
name-prefix setting. This is reliable (no false 'qa' stack, #12) and groups externally-
launched stacks once the compose tool labels them (upstream Mcrich23/Container-Compose#110).

- StackOrigin.composeLabeled (trusted; no 'wild' badge; link a compose file to enable up/down)
- ProjectRegistry.composeProjectLabel constant + label grouping before known/inferred
- StackSection offers 'Link compose file' for any unlinked stack
- Test: label grouping works with inference off; unlabeled containers stay standalone
- Verified live: a patched-container-compose 'shop' stack groups with no 'wild' badge

Closes #14
@Cyb3rDudu Cyb3rDudu self-assigned this Jun 23, 2026
@Cyb3rDudu Cyb3rDudu requested review from Cyb3rDudu and Mcrich23 June 23, 2026 05:48
Generalize the com.docker.compose.* label stamping introduced in this PR:

- Model Service.labels: [String: String]? (property, CodingKeys, decoder,
  memberwise init), matching the existing Network/Volume pattern, so the
  Compose `labels:` directive on a service is no longer silently ignored.
- In configService, pass user labels through as `--label key=value`, then
  stamp com.docker.compose.project/service on top so they take precedence
  over any user value for the same key. Keys are emitted sorted for a
  deterministic `container run` argv.

Add a dynamic test (testUpStampsComposeLabels) plus dockerComposeYaml10
that asserts the compose labels are stamped, user labels pass through, and
the stamped service label overrides a colliding user-defined value.

swift build + swift build --build-tests both clean.
@Cyb3rDudu Cyb3rDudu force-pushed the feat/compose-project-labels branch from 2682ea4 to ebefa65 Compare June 23, 2026 07:04

@Cyb3rDudu Cyb3rDudu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good - correct mechanism, right label namespace for tool interop, and verified working. We can add a dynamic test (up → assert both labels present via inspect) so this doesn't silently regress; (2) when service.labels support lands later, make sure these two compose labels are applied last / take precedence over a user setting the same key. Nice that it composes cleanly with #104 and #113. consider folding this into the existing labels: pass-through pattern (see the commented-out network-labels block) for consistency and to also pick up user-defined service labels.

@Cyb3rDudu Cyb3rDudu removed the request for review from Mcrich23 June 23, 2026 07:08

@Cyb3rDudu Cyb3rDudu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good — generalized label stamping + test, builds clean, signed.

@Cyb3rDudu Cyb3rDudu closed this Jun 25, 2026
@Cyb3rDudu Cyb3rDudu reopened this Jun 25, 2026
@Cyb3rDudu Cyb3rDudu closed this Jun 25, 2026
@Cyb3rDudu Cyb3rDudu reopened this Jun 25, 2026
@Cyb3rDudu Cyb3rDudu closed this Jun 25, 2026
@Cyb3rDudu Cyb3rDudu reopened this Jun 25, 2026
@Cyb3rDudu Cyb3rDudu closed this Jun 27, 2026
@Cyb3rDudu Cyb3rDudu reopened this Jun 27, 2026
@Cyb3rDudu Cyb3rDudu merged commit ab1e5c7 into Mcrich23:main Jun 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants