Documentation
¶
Overview ¶
Package volumecheck detects the "empty database after switching compose project directories" trap.
Compose derives the project name from the directory name, and the named volume `pgdata` is per project. A user who clones/renames the repo to a new directory and runs `docker compose up` therefore gets a brand-new empty volume — the old data is still on the machine under the old project's volume, but nothing points at it anymore and the app silently starts with an empty database.
Detection runs in a short-lived sidecar container (the `volume-check` compose service) that has the Docker socket mounted read-only. It writes a hint file into the shared data directory; the main process reads it at startup and only warns when its own database is still uninitialised. Nothing is migrated automatically — the hint only names the old volume/directory and prints the commands needed to reconnect.
Index ¶
Constants ¶
const DoneFile = ".volume-check.done"
DoneFile marks that the sidecar ran, so the supervising script can wait for it without blocking startup for long.
const HintFile = ".compose-volume-warning.json"
HintFile is the name of the state file written next to the data directory.
const SocketEnv = "ARTEX_REDTEAM_DOCKER_SOCK"
SocketEnv overrides the Docker socket path (tests and unusual installs).
Variables ¶
This section is empty.
Functions ¶
func ClearHint ¶
ClearHint removes a stale hint (the machine no longer has old volumes) and still leaves the done marker.
func LogLines ¶
LogLines renders the multi-line startup warning. Each returned line already starts with "[volume]" so callers can log them verbatim.
func RunSidecar ¶
RunSidecar is the `-volume-check` entry point. It must never make the boot fail: every error is printed and turned into exit code 0.
Types ¶
type Hint ¶
type Hint struct {
CurrentProject string `json:"current_project"`
OldProjects []Project `json:"old_projects"`
}
Hint is the payload written by the sidecar and consumed by the app.
func BuildHint ¶
BuildHint is the pure part of Detect: it keeps only `pgdata` volumes owned by other compose projects and enriches them with the bind-mounted data directory recorded on those projects' containers (stopped containers included).
type Project ¶
type Project struct {
// Name is the compose project name (by default the directory name).
Name string `json:"name"`
// Volume is the detected `<project>_pgdata` volume, if any.
Volume string `json:"volume,omitempty"`
// DataDir is the host path of the project's bind-mounted `./data`, when a
// stopped/running container of that project still records it.
DataDir string `json:"data_dir,omitempty"`
}
Project describes a compose project that may still own old data.