Skip to content

Read the volume mapping from the panel's own container - #338

Merged
athNdev merged 3 commits into
mainfrom
feat/volume-mapping
Nov 4, 2026
Merged

athNdev merged 3 commits into
mainfrom
feat/volume-mapping

Conversation

@athNdev

@athNdev athNdev commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Closes the two deployment asks: the variables are no longer needed, and the mapping is validated as the stack comes up.

The variables are gone

CARBONPANEL_HOST_DATA_PATH and CARBONPANEL_DATA_DIR restated the compose volume mapping by hand, so they could silently disagree with the mount they described. At startup the panel now inspects its own container (docker inspect $HOSTNAME) and reads the host source of /app/data. docker.TranslateToHostPath uses that mapping, so a server directory seen at /app/data/servers/x is requested as <host source>/servers/x.

Removed from docker-compose.yml, all four OIDC examples, the manual-review harness, README.md, DESIGN.md and the four getting-started pages.

Validity is checked as compose spins up

Situation Result
data dir not on a persistent mount FATAL, before the database is created
data dir mounted read-only FATAL — no write permission on the mount dir
container user cannot write the dir FATAL — verified with a probe file, not a mode bit
data dir is a tmpfs FATAL — discarded with the container
relative CARBONPANEL_HOST_DATA_PATH FATAL — mount path should be absolute
backups or scratch not mounted WARN — allowed (S3-only keeps a local scratch dir)
override disagrees with the detected mount WARN — the mount wins, the variable can be removed

The mount-presence check reads /proc/self/mountinfo and runs before storage initialisation, so a missing volume fails without writing anything into the container layer. The daemon-backed check still runs afterwards and covers platforms without mountinfo.

Compatibility

The override is still read when the mount table cannot be read — a Docker socket proxy that forbids GET /containers/** would otherwise break a working deployment — and is logged as deprecated. CARBONPANEL_DATA_DIR is only consulted in that same fallback; storage.data_dir is the source of truth.

Verification

Disposable containers against the WSL daemon (29.3.0), with a freshly cross-built Linux binary:

  • data mounted → Server data directory /app/data maps to /tmp/cpm/data on the Docker host (container mount), then starts;
  • nothing mounted → refuses with the directory named and the compose line to add;
  • read-only mount → refuses with no write permission on the mount dir;
  • CARBONPANEL_HOST_DATA_PATH=opt/carbon-panel/data → refuses with mount path should be absolute before migrations run;
  • CARBONPANEL_HOST_DATA_PATH=/srv/stale with a mounted data dir → detects /tmp/cpm/data, warns that the variable disagrees;
  • data mounted, backups and tmp not → starts with two warnings.

go build ./..., go vet ./..., go test ./... and knowledge-lint (10/10) pass. New tests cover the mountinfo parser, the covering-mount rule, each refusal, the override precedence, and SelfMounts against a fake daemon.

CARBONPANEL_HOST_DATA_PATH and CARBONPANEL_DATA_DIR restated the compose
volume mapping by hand, so they could silently disagree with it. The panel now
reads its own container's mounts at startup: /app/data maps to whatever the
compose file mounted it from, and the daemon is asked for that path.

Startup validates the mapping before anything writes to it:

- a data directory that is not on a persistent mount is refused from the
  container mount table, before the database exists;
- a read-only mount, a tmpfs data directory and a directory the process
  cannot write are refused, the last with a probe file rather than a mode bit;
- a relative legacy override is refused as 'mount path should be absolute';
- backups and scratch space that are not mounted are warned about, not
  refused, because an S3-only deployment keeps a local scratch dir.

The compose files, OIDC examples and deployment docs drop both variables. The
override is still read when the mount table is unavailable (a Docker socket
proxy that forbids container reads) and is reported as deprecated; when it
disagrees with the detected mount the mount wins and the log says so.

Verified in disposable containers against the WSL daemon: mounted data dir
starts and logs the detected mapping; no data mount, read-only mount and a
relative override each stop with the expected message; an unmounted backup dir
starts with a warning.
The filesystem type is only used to exclude virtual mounts while parsing, so
keeping it on the struct tripped the unused linter.
errcheck holds new code to the full standard; the read-only open is
best-effort but the close still has to be acknowledged.
@athNdev
athNdev merged commit f7b0c1f into main Nov 4, 2026
12 checks passed
@athNdev
athNdev deleted the feat/volume-mapping branch November 4, 2026 03:05
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.

1 participant