Repository navigation
refactor: use compose-spec/compose-go/v2 for fixupComposeYaml - #7422
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
|
@rfay, from the git history I see you left Looks like I'm making a second attempt to implement it. |
|
Ambitious! |
|
Pretty amazing that you seem to have gotten that all the way to clean with a very modest set of line changes. |
|
And it will be much better after the next refactor: -ComposeYaml map[string]interface{} `yaml:"-"`
+ComposeYaml *composeTypes.Project `yaml:"-"`We parse |
43cf7b8 to
a7468b4
Compare
|
I see potential for further refactoring, but it's better to leave that for other PRs. Ready for review. |
a7468b4 to
7001416
Compare
Claude Code Summary of ChangesThis PR modernizes how DDEV handles Docker Compose YAML files by switching from manual parsing to using the official Docker Compose library. Key Changes:1. New Library Integration
2. Type System Upgrade
3. Better YAML Processing (
4. Updated Docker Compose Version Requirement
Why This Matters:For Users: More reliable handling of complex Docker Compose configurations, especially when editing For Developers:
Trade-off: The binary size increases by ~2MB due to the additional library, but this provides much more robust YAML handling. This is essentially DDEV saying "instead of reinventing the wheel for Docker Compose parsing, let's use the official tools that Docker itself uses." |
rfay
left a comment
There was a problem hiding this comment.
Well, it's beautiful, what can I say! Congratulations! Thank you!
I opened #7472, which is certainly not the fault of this PR. Stepping through your lovely compose PR I note that the project is first created in cmd/pull.go's init(). Yuck to inits! Then it happens again in push.go's init(). Then it finally happens in root.go's init(), snapshot_restore.go, start.go, ddevapp.go's Start() (probably the first time it was actually needed).
|
|
||
| // createComposeProject creates a compose project from a string | ||
| func createComposeProject(yamlStr string) (*composeTypes.Project, error) { | ||
| project, err := composeLoader.LoadWithContext( |
| if project.Networks == nil { | ||
| project.Networks = composeTypes.Networks{} | ||
| } | ||
| if project.Services == nil { | ||
| project.Services = composeTypes.Services{} | ||
| } | ||
| if project.Volumes == nil { | ||
| project.Volumes = composeTypes.Volumes{} | ||
| } |
There was a problem hiding this comment.
It would be weird if any of these things happened, true?
There was a problem hiding this comment.
Yes, but to avoid some random panic, we need to have these.
| XHGuiHTTPPort string `yaml:"xhgui_http_port,omitempty"` | ||
| HostXHGuiPort string `yaml:"host_xhgui_port,omitempty"` | ||
| XHProfMode types.XHProfMode `yaml:"xhprof_mode,omitempty"` | ||
| ComposeYaml *composeTypes.Project `yaml:"-"` |
| return err | ||
| } | ||
|
|
||
| // CheckAddonIncompatibilities looks for problems with docker-compose.*.yaml 3rd-party services |
There was a problem hiding this comment.
I guess this has all been taken care of because we used compose to load?
There was a problem hiding this comment.
Yes, and it could be deleted even earlier, the networks were added automatically anyway.
| for serviceName, s := range services.(map[string]interface{}) { | ||
| service := s.(map[string]interface{}) | ||
| if env, ok := service["environment"].(map[string]interface{}); ok { | ||
| var virtualHost string |
7001416 to
097e119
Compare
|
Rebased to get Windows test fixup. |
The Issue
It's hard to edit
.ddev/.ddev-docker-compose-full.yamlby doing manual YAML parsing.How This PR Solves The Issue
Uses
github.com/compose-spec/compose-go/v2(adds ~2 MB to theddevbinary size).Changes the
app.ComposeYaml:Bumps
DockerComposeVersionConstraintfrom>= 2.5.1to>= 2.24.3(which is used in Docker Desktop with Docker Engine 25.0, see https://docs.docker.com/desktop/release-notes/) (and rename toComposeVersionConstraint)Docker 25.0 is our current recommended minimum.
Manual Testing Instructions
Automated Testing Overview
Release/Deployment Notes
It's important to keep
github.com/compose-spec/compose-go/v2library in sync with what is used indocker-compose.