Skip to content

fix(mounts): normalize volume field casing to lowercase with backward compatibility - #573

Open
madejackson wants to merge 1 commit into
azukaar:unstablefrom
aseracorp:fix/normalize-mount-casing
Open

madejackson wants to merge 1 commit into
azukaar:unstablefrom
aseracorp:fix/normalize-mount-casing

Conversation

@madejackson

@madejackson madejackson commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Disclaimer

This PR was written with the help of Plurality (using model kimi 2.6)

I manually checked the code. It seems legit and should not rise any new issues. Nevertheless I am running this version of Cosmos Cloud on my nodes to catch potential issues asap.

There is one line I'm not sure we should leave in the code or not:

ReadOnly: false, // TODO: add support for this

Update: this gets addressed here: #599

Summary

Fixes the inconsistency where Volume Target and Source were the only fields using uppercase (Type, Source, Target) while every other runtime variable in Cosmos uses lowercase (type, source, target).

Problem

  • Market templates and Docker Compose imports use lowercase field names (source, target, type) — this is the Docker Compose spec convention.
  • Runtime container operations (create, update, export) used the raw Docker SDK mount.Mount struct, which serializes with uppercase Go exported fields (Source, Target, Type).
  • This caused the frontend to juggle two casing conventions depending on whether a volume came from a template, a compose file, or an inspected running container.

Solution

Introduced a Cosmos-local CosmosMount type with lowercase JSON tags and bidirectional conversion helpers:

Before After
[]mount.Mount ({"Type":"bind","Source":"/x","Target":"/y"}) []CosmosMount ({"type":"bind","source":"/x","target":"/y"})

Key changes

  • New type: src/docker/mount.go — CosmosMount with lowercase tags and helper methods:
    • ToDockerMount() / ToDockerMountSlice() — send to Docker SDK
    • FromDockerMount() / FromDockerMountSlice() — receive from Docker SDK
    • UnmarshalJSON() — accepts both lowercase and uppercase on input
  • Backend structs updated:
    • ContainerCreateRequestContainer.Volumes → []CosmosMount
    • ContainerForm.Volumes → []CosmosMount (JSON tag changed from Volumes → volumes)
  • Conversion points: CreateService(), UpdateContainerRoute(), ExportContainer() now convert at the Docker SDK boundary.
  • Frontend updated: volumes.jsx, docker-compose.jsx, newServiceForm.jsx use lowercase fields exclusively.

Backward Compatibility

The custom UnmarshalJSON on CosmosMount accepts both casing styles on input:

// Lowercase (new canonical) — ✅ works
{"type":"bind","source":"/host","target":"/cont"}

// Uppercase (legacy Docker SDK) — ✅ still works
{"Type":"volume","Source":"myvol","Target":"/data"}

Serialization always outputs lowercase, so clients and generated SDKs will gradually migrate without breaking.

Testing

  • go build ./src/docker/... and go build ./src/... pass
  • Verified lowercase input → correct parsing
  • Verified uppercase input → correct parsing (backward compat)
  • Verified serialization → always lowercase

Checklist

  • Branch targets unstable
  • Go code builds cleanly
  • Backward compatibility preserved for API consumers
  • Frontend volume flows updated (import, create, update, export)

@cla-bot

cla-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Cosmos Developer.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@madejackson
madejackson force-pushed the fix/normalize-mount-casing branch from 13aa266 to b91715d Compare August 24, 2026 08:55
@cla-bot cla-bot Bot added the cla-signed label Aug 24, 2026
@madejackson
madejackson force-pushed the fix/normalize-mount-casing branch 2 times, most recently from c6d5fb7 to 73d4993 Compare August 24, 2026 10:37
@cla-bot

cla-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Cosmos Developer.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@cla-bot cla-bot Bot removed the cla-signed label Aug 24, 2026
@madejackson
madejackson force-pushed the fix/normalize-mount-casing branch from 73d4993 to ca8dc24 Compare August 24, 2026 11:02
@cla-bot cla-bot Bot added the cla-signed label Aug 24, 2026
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 5, 2026
… - introduces the CosmosMount type this feature builds on)
@madejackson
madejackson force-pushed the fix/normalize-mount-casing branch 2 times, most recently from d7e6d5d to 0292ae2 Compare September 8, 2026 18:41
madejackson added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 8, 2026
…n-comments

Both stacked PRs share mount/volume/export code and depend on the same
dependency chain (azukaar#573 lowercase CosmosMount, azukaar#585 DurationStr). Resolve
the additive conflicts:

- mount.go: take azukaar#599's superset (SubPath/ReadOnly/NoCopy + helpers)
- volumes.jsx / newServiceForm.jsx: azukaar#599's Subpath/Read-only/NoCopy columns
  and file-picker 'any' (for file subpaths) layered on azukaar#590's lowercase fields
- api_blueprint.go: keep azukaar#590's omitempty tags (hide empty fields in the
  compose editor) + healthcheck nil-guard refactor; keep azukaar#599's
  ValidateMountConflicts + volume-subpath auto-create block
- export.go: keep azukaar#590's FormatShmSize + healthcheck pointer alloc; take
  azukaar#599's HostConfig.Mounts/FromDockerMount volume export (subpath-preserving)
- regenerate api-docs + go-sdk from merged code (CosmosMount fields,
  DurationStr healthcheck fields, mount readOnly/subpath/noCopy)

Verified: go build ./... , go test ./src/..., vite client-build all pass.
@madejackson
madejackson force-pushed the fix/normalize-mount-casing branch 2 times, most recently from e2c072b to 00fb9d7 Compare October 9, 2026 11:35
… compat

Replace raw Docker SDK mount.Mount usage with CosmosMount type that

uses lowercase JSON tags (type, source, target, read_only). This makes

volume definitions consistent across market templates, imports, and

runtime container management.

Previously, market templates used lowercase (source, target) while

runtime container volumes from the Docker SDK were serialized with

uppercase (Source, Target, etc.) due to Go's exported-field naming.

Changes:

New CosmosMount in src/docker/mount.go with lowercase JSON tags and

conversion helpers (ToDockerMount, FromDockerMount, etc.)

ContainerCreateRequestContainer.Volumes: []mount.Mount -> []CosmosMount

ContainerForm.Volumes: []mount.Mount -> []CosmosMount (tag Volumes->volumes)

ExportContainer(): Convert Docker mount.Mount -> CosmosMount on output

CreateService()/UpdateContainer(): Convert CosmosMount -> mount.Mount on input

Frontend volumes.jsx: Use lowercase field names throughout

Frontend docker-compose.jsx/newServiceForm.jsx: Map to lowercase

Backward compatibility:

Custom UnmarshalJSON on CosmosMount accepts both lowercase (canonical)

and uppercase (legacy Docker SDK) field names on input. Serialization

always outputs lowercase so clients gradually migrate.

Fixes casing inconsistency in volume handling across compose import,

container create, container update, and container export flows.
@madejackson
madejackson force-pushed the fix/normalize-mount-casing branch from 00fb9d7 to a671a82 Compare October 12, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant