Skip to content

Conversation

@Mewsen
Copy link
Contributor

@Mewsen Mewsen commented Jul 23, 2025

Moves ParseVolume() to a new internal package to remove the dependency on cli/compose/loaderin cli/command/container/opts.go
fixes #6188

- What I did
Removed the cli/compose/loader dependency from cli/command/container.
- How I did it
Moved the cli/compose/loader.ParseVolume function to a new internal package named parsevolume.
- How to verify it
Verify that the cli/command/container package does not import cli/compose/loader.
- Human readable description for the release notes

Moved ParseVolume function from cli/compose/loader/volume.go to new internal package named parsevolume

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/compose/loader/loader.go 33.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

thank you!

I left some suggestions, but opened a quick try of those as a PR against your PR branch;

If you merge that PR, my commit will show up here (we can squash later)

// add any bind targets to the list of container volumes
for bind := range copts.volumes.GetMap() {
parsed, err := loader.ParseVolume(bind)
parsed, err := parsevolume.ParseVolume(bind)
Copy link
Member

Choose a reason for hiding this comment

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

As we're moving this internal, we could take the opportunity to rename, e.g. volumespec for the package, and making this volumespec.Parse().

@@ -1,4 +1,4 @@
package loader
package parsevolume
Copy link
Member

Choose a reason for hiding this comment

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

We should probably move the related types as well, then alias the ones in the old location; this keeps backward-compatibility in case anyone currently imports cli/compose/loader and who may be using the things we moved.

Go does allow aliasing types that are internal, which means we can keep the implementation internal, and still keep the existing place. (for now at least). If we'd ever be working on re-implementing, we could split the two (as command/container only uses it internally.

@thaJeztah
Copy link
Member

Also opened a temporary draft PR rebased on current master to run CI

func ParseVolume(spec string) (types.ServiceVolumeConfig, error) {
volume := types.ServiceVolumeConfig{}
// Parse parses a volume spec without any knowledge of the target platform
func Parse(spec string) (VolumeConfig, error) {
Copy link
Contributor

@ndeloof ndeloof Jul 24, 2025

Choose a reason for hiding this comment

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

IMHO this should be part of the moby API, so that Compose doesn't need a copy of this func in https://github.com/compose-spec/compose-go/blob/6d8281ca46429b18d5fb6e1a1f94bcd11489c578/format/volume.go#L32

Copy link
Member

Choose a reason for hiding this comment

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

Yes; TBD where the best place would be, and this is definitely not the final state. There's currently already at least two (or three, if you add the fork in compose) places where this is maintained, which is horrible because some parts of it are definitely non-trivial.

I recall some discussion happened at the time when this parsing was added from the "libcompose" rewrite in Go (moby/moby#27998), which got later rewritten again, and ironically, #152 was done because there lived 3 separate implementations in the CLI, but there's also a daemon-side package to handle parsing, but it's neither part of the API, nor of the Client;
https://github.com/moby/moby/blob/fcb916ad17311aec838e03b47f93bfc70639fdf5/daemon/volume/mounts/parser.go#L28-L50

But there's people breathing down my neck to "ship the modules" and it's much easier to add things than to remove things (or break things) if we want the modules to remain SemVer, so this is just an intermediate step; likely to be (re)unified after a cleanup of these code-bases.

@thaJeztah thaJeztah added this to the 29.0.0 milestone Jul 24, 2025
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Jul 24, 2025
Moves ParseVolume() to a new internal package to remove the dependency
on cli/compose/loader in cli/command/container/opts.go

refactor to keep types isolated

- rename the package to "volumespec" to reuse the name of the package
  as part of the name (parsevolume.ParseVolume() -> volumespec.Parse())
- move the related compose types to the internal package as well,
  and rename them to be more generic (not associated with "compose");
  - ServiceVolumeConfig -> VolumeConfig
  - ServiceVolumeBind -> BindOpts
  - ServiceVolumeVolume -> VolumeOpts
  - ServiceVolumeImage -> ImageOpts
  - ServiceVolumeTmpfs -> TmpFsOpts
  - ServiceVolumeCluster -> ClusterOpts
- alias the internal types inside cli/compose/types to keep backward
  compatibility (for any external consumers); even though the implementation
  is internal, Go allows aliasing types to use them externally.

Signed-off-by: Michael Tews <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM let me get this one in 😄

@thaJeztah thaJeztah merged commit 2f87a11 into docker:master Jul 25, 2025
87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli/command/container: remove dependency on cli/compose/loader.ParseVolume

4 participants