Epic: Move service selection into the backend API instead of pre-filtering the project in the CLI
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
This is a design epic, not a task to pick up. Start by reading how WithSelectedServices is applied in cmd/compose/up.go and cmd/compose/scale.go, then the reconciler's servicesUsingNetwork and servicesUsingVolume helpers. Done means maintainers agree on the ServiceSelection shape and the open questions in the issue are resolved; implementation work would follow in separate issues.
由索引模型根据 Issue 内容生成。
描述
"This issue was filed by an AI agent on a human's behalf. The human submitter may not have independently verified the report."
Summary
Service selection (up web, --no-deps, watch rebuilds, …) is currently applied by the callers of the backend, by pre-filtering the types.Project with WithSelectedServices. This issue proposes making the selection an explicit input of the backend API, so that the reconciler sees the whole model and decides what the selection means. It also matters for other consumers of pkg/api (library users, Docker Desktop, …): they should not have to reproduce the CLI's pre-filtering to get correct behavior.
Related: #14081 (converging the start phase into the plan engine), #14291.
Problem
Two different notions of "selection" coexist today:
Servicesin the API options (CreateOptions.Services, …) means targeted services. The reconciler still converges every other service, with theRecreateDependenciespolicy (reconcileService).- Pre-filtering the project (
project.WithSelectedServices(...), done incmd/compose/up.goandcmd/compose/scale.gofor--no-deps, and inwatch's rebuild) means the other services do not exist: they are moved toDisabledServices, andDependsOnof the kept services is pruned to the selection.
Because the reconciler receives a truncated model without knowing it, it makes wrong inferences. Concretely, it looks for the consumers of a network or volume in project.Services only (servicesUsingNetwork, servicesUsingVolume). With a narrowed project, a drifted network or volume that is also used by a service outside the selection looks unused by it:
- the plan stops/disconnects (or removes) only the selected services' containers, then tries to remove the network/volume, which fails with "in use";
- for a volume, the user is first asked to confirm a data-destroying recreation that cannot succeed.
I reproduced this at the reconciler level with unit tests, on a project narrowed to one service whose network (or volume) is shared with a disabled service that has a live container. up --no-deps <svc> and scale --no-deps build exactly such a project, so I expect the same exposure there; I have not reproduced it end to end against a daemon. Dependency pruning in WithSelectedServices may also affect config hashes; I have not checked that.
A narrow guard in the reconciler (leave a drifted resource alone, with a warning, while a disabled service's live container still holds it) is being added to #14291 for the watch rebuild. It is a mitigation: it works around the truncated model rather than removing the cause.
Proposal
Keep the full project as the model and pass the selection to the backend as data. A sketch, open for discussion:
// ServiceSelection scopes an operation to part of the project.
type ServiceSelection struct {
Services []string
Dependencies DependencyScope // include (default), ignore (--no-deps), dependents (watch rebuild)
}
carried by the options of the operations that converge or start containers (CreateOptions, UpOptions/StartOptions, ScaleOptions, WatchOptions), and applied at a single point, in the plan preparation, once the canonical project has been built.
Semantics the reconciler would own:
- The model stays whole: every consumer of a network or volume is visible, and the dependency graph is the real one.
- The selection bounds which services' containers may be created, recreated, started, stopped or waited on.
- Infrastructure needed by the selected services is created if missing. A drifted network or volume is recreated only if all its consumers are within the selection; otherwise it is kept, with a warning.
- Orphan detection is unaffected by the selection.
Compatibility
- Additive: a caller that keeps pre-filtering the project still works, since it just yields a project with fewer services.
- The existing
Servicesfields keep their current meaning ("targets"); the new field must not silently redefine them. - Commands that never go through the plan (
config,pull,push,run's own container) can keep pre-filtering client side. Migration can go command by command, starting withup,create,start,scaleandwatch.
Questions
- Is a single
ServiceSelectionvalue the right shape, or should the dependency scope stay a separate option? - Should
RecreateDependenciesbe folded into the selection, since it exists to express "what happens to services outside the targets"? - Are there library consumers relying on the current pre-filtering contract that this would break?
Feedback from anyone consuming pkg/api is welcome.
- 主要语言
- Go
- 星标
- 38.4k
- 派生
- 5.9k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 70
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
docker/compose 的其他 Issue
-
[BUG] <title>未关闭kind/bug status/0-triage
难度 5/5 一周以上 新手友好度 10/100
维护者通常 1 天内回复
-
Watch: exec mode可能已有人在做 @glours 于 4 天前认领。 未关闭kind/feature
docker/compose#14326 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Restore build concurrency limit now that bake supports it可能已有人在做 @maxproske 于 1 天前认领。 未关闭kind/feature
难度 3/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
-
[BUG] `start -p <name>` treats an optional (`required: false`) dependency as required可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 22/100
维护者通常 1 天内回复
-
[BUG] `mode` attribute in `configs` works but raises an unsupported warning可能已有人在做 @ndeloof 于 9 天前认领。 未关闭kind/bug
难度 3/5 1-2 天 新手友好度 58/100
docker/compose#14288 · 4 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 81/100
apache/rocketmq-dashboard#6895 ·
维护者通常 3 天内回复
-
难度 1/5 1 小时以内 新手友好度 87/100
777genius/agent-notifications#490 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
devantler-tech/ksail#7836 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
keyxmakerx/Chronicle#1469 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复