Skip to content

format: tell whether a volume can be said in the short syntax - #986

Open
ndeloof wants to merge 1 commit into
compose-spec:mainfrom
ndeloof:volume-short-syntax
Open

ndeloof wants to merge 1 commit into
compose-spec:mainfrom
ndeloof:volume-short-syntax

Conversation

@ndeloof

@ndeloof ndeloof commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

What this PR does, in one sentence

Adds format.IsShortSyntaxExpressible, which tells whether a volume can be written as a plain [SOURCE:]TARGET[:OPTIONS] string and mean exactly the same thing.

Context

volumes entries come in two syntaxes, and an implementation that hands them to an engine has to know which ones it can send as a string (the Binds of the Docker API) and which need more (the Mount API). Today each implementation guesses it option by option: Docker Compose keeps a list of the options that force the Mount API, and a volume nobody listed (for instance a target containing a colon, docker/compose#12993) silently takes the wrong path or is misread. The answer is a property of the volume, and it is the parser's to give.

What the PR brings

  • format.ShortSyntax(v) renders the volume in the short syntax and reports whether it could; format.IsShortSyntaxExpressible(v) is the boolean. A volume is expressible when some spelling of it parses back, with ParseVolume, as the very same volume, so the answer cannot drift from the parser.
  • What is not expressible: what the short syntax has no place for (tmpfs, image, subpath, labels, consistency, extensions, a recursive bind, a bind that doesn't create its host path, nocopy on a bind…), and what it would read otherwise (a colon in a source or a target, a bind source that is not a path, a one-letter volume name read as a drive letter). z/Z/propagation on a named volume are expressible, as the parser puts them in the volume's bind.
  • Purely additive: nothing in the loader, the model or the schema changes, and the function is not called by compose-go itself. Tests cover each class above, plus the round trip (what it renders parses back to the same volume).

This is deliberately small and independent of the mounts proposal in #979, so the check can be used, and discussed, on its own.

🤖 Generated with Claude Code

ShortSyntax renders a volume as `[SOURCE:]TARGET[:OPTIONS]` when some
spelling of it parses back as the very same volume, and
IsShortSyntaxExpressible reports it. A volume the short syntax has no place
for (tmpfs, image, subpath, labels, consistency, extensions, a bind that
doesn't create its host path or is recursive...) or would read otherwise
(a colon in a path, a bind source that is not a path, a one letter volume
name read as a drive) is not expressible, and can only be written in the
long syntax.

It lets an implementation decide, without guessing from each option, which
volumes it can hand over as a plain string (the `Binds` of the Docker API)
and which need more.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>

@glours glours 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.

LGTM

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