Skip to content

feat(docker): user-set vs runtime config + persist HJSON comments - #590

Open
madejackson wants to merge 2 commits into
azukaar:unstablefrom
aseracorp:pr/hjson-comments
Open

madejackson wants to merge 2 commits into
azukaar:unstablefrom
aseracorp:pr/hjson-comments

Conversation

@madejackson

@madejackson madejackson commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Config vs runtime values + HJSON comment persistence in the compose editor

This PR is the combined follow-up to the HJSON display work: it shows the user-set config (instead of the live runtime state) and preserves HJSON comments in the compose editor.

🧩 Dependencies (all required — merge these first, in any order)

This branch is stacked on the following PRs. Each is needed because the code here builds on types/behavior they introduce:

# PR Why it's required
#584 Display & edit JSON payloads as HJSON HJSON infra (hjson.jsx, toHjson, parseJsonOrHjson) that the compose editor edits in
#585 store healthcheck durations as compose-style strings DurationStr / FormatDuration used by the export/diff code
#579 end-to-end depends_on + network_mode ContainerRefToName, depends_on label handling, network-mode ref resolution
#573 normalize volume field casing to lowercase CosmosMount (lowercase volume fields) used by export.go
#567 add support for shm_size ShmSize / ByteSize byte-size string handling
#495 Add Exec form to command/entrypoint strslice.StrSlice exec/shell form for command/entrypoint

1️⃣ Show user-set vs image-default config

Currently the compose editor always shows the live Docker runtime state, mixing user-set values with image-Dockerfile defaults (ENV, CMD, EXPOSE, HEALTHCHECK, WORKDIR, USER) and Cosmos bookkeeping labels.

  • ExportContainerRuntime: exports only explicitly-set settings by diffing ContainerInspect against ImageInspectWithRaw:
    • env: only entries not in the image env or with a different value
    • labels: only labels are hidden if they are inherited verbatim from the image. The only label prefix hidden unconditionally is cosmos.compose.* (the internal per-node HJSON comment labels — returned separately via the comments field, not as user config). All other labels — including other cosmos.* / cosmos-* bookkeeping (cosmos.stack, cosmos-stack, cosmos.stack.main, cosmos-stack-main, cosmos-network-name, …) and com.docker.compose.* — are kept. The internal com.docker.compose.depends_on label is still stripped (its data is exposed via the depends_on field).
    • command/entrypoint/workingdir/user/stopsignal/hostname/domainname/healthcheck: only when they differ from the image
    • runtime/shm_size: hidden when they equal the docker daemon's defaults (read from the daemon)
    • ports/volumes/networks/resources/restart/dns exported as-is (no image baseline)
    • falls back to full runtime export if the image is unavailable
  • ExportContainerRoute: ?from=initial (default) = diff; ?from=runtime = full live state
  • Frontend: compose-editor gets a themed "Show runtime values" switch that re-fetches; newService.jsx re-syncs the editor when the service prop changes; empty fields (ports: [], routes: null, etc.) hidden via omitempty.

2️⃣ Persist HJSON comments in cosmos.compose.* labels

Comments aren't representable in JSON, so the editor previously lost them on save.

  • Client: extractComments() builds a node-path → comment map; injectComments() restores them; create() sends $$comments; export returns comments.
  • Backend: src/docker/comments.go stores each comment as cosmos.compose.<path> label and reads them back; CreateServiceRoute extracts $$comments; ExportContainerRoute returns the map.

Notes

@cla-bot cla-bot Bot added the cla-signed label Sep 1, 2026
@madejackson madejackson changed the title feat(docker): persist HJSON comments in cosmos.compose.* labels feat(docker): user-set vs runtime config + persist HJSON comments Sep 1, 2026
@madejackson
madejackson force-pushed the pr/hjson-comments branch 3 times, most recently from 693cf5e to 8ecf449 Compare September 5, 2026 15:22
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 added a commit to aseracorp/Cosmos-Server that referenced this pull request Sep 9, 2026
…path (azukaar#599)

Reconcile the clean azukaar#599 branch (built on upstream, minus generated
files) with azukaar#590's stacked feature work. Shared files take the canonical
union: azukaar#590's omitempty/shm_size/strslice + azukaar#599's subpath/nocopy.

Verified: go build ./..., docker tests pass.
@madejackson
madejackson force-pushed the pr/hjson-comments branch 2 times, most recently from 1b01a13 to d82778f Compare October 9, 2026 11:35
@cla-bot

cla-bot Bot commented Oct 9, 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: madejackson.
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

Copy link
Copy Markdown
Contributor Author

Rebased this branch on top of the updated #584 (f60d7bc3) so the stack is honest: #584 now provides the HJSON infra (including the min-quote presentation + grammar), and this PR's single commit carries only the user-set-vs-runtime export + comment preservation on top. The final hjson.jsx here is byte-identical to what was previously shipped; the history is just cleaner.

Replace raw JSON.stringify output with HJSON (hjson.github.io) in the
compose editor, docker-compose JSON import, API config preview modals and
the event explorer: unquoted keys, always-quoted string values, trailing
separators, no escaping noise. The compose editor/import parse HJSON on
submit (JSON first, HJSON fallback — a superset), so users can paste either.
Pure frontend preprocessing: the backend still receives and emits JSON.

Includes a Prism grammar that keeps the familiar editor colors with HJSON:
keys red, string values green, numbers/booleans/null purple, comments and
multiline strings/block-comments grey/green. Strings containing #, // or :
stay single quoted strings; comments containing ':' stay comments.

Files:
- client/src/utils/hjson.jsx (new): toHjson + parseJsonOrHjson
- client/src/utils/hjsonGrammar.js (new): Prism HJSON grammar
- newService.jsx / docker-compose.jsx: init/parse as JSON-or-HJSON
- apiModal.jsx / eventsExplorer.jsx: render payloads/events as HJSON
- package.json / package-lock.json: add hjson dependency
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