volumecheck

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

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

View Source
const DoneFile = ".volume-check.done"

DoneFile marks that the sidecar ran, so the supervising script can wait for it without blocking startup for long.

View Source
const HintFile = ".compose-volume-warning.json"

HintFile is the name of the state file written next to the data directory.

View Source
const SocketEnv = "ARTEX_REDTEAM_DOCKER_SOCK"

SocketEnv overrides the Docker socket path (tests and unusual installs).

Variables

This section is empty.

Functions

func ClearHint

func ClearHint(dataDir string) error

ClearHint removes a stale hint (the machine no longer has old volumes) and still leaves the done marker.

func LogLines

func LogLines(h *Hint) []string

LogLines renders the multi-line startup warning. Each returned line already starts with "[volume]" so callers can log them verbatim.

func Notice

func Notice(h *Hint) string

Notice is the short one-line version surfaced in the system settings page.

func RunSidecar

func RunSidecar(dataDir string) int

RunSidecar is the `-volume-check` entry point. It must never make the boot fail: every error is printed and turned into exit code 0.

func WriteHint

func WriteHint(dataDir string, h *Hint) error

WriteHint persists the hint atomically, then leaves the done marker.

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

func BuildHint(current string, containers []dockerContainer, volumes []dockerVolume) *Hint

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).

func Detect

func Detect(ctx context.Context, c *http.Client) (*Hint, error)

Detect queries the Docker API and returns the hint for the current project. It is exported so tests can drive it with a fake socket.

func ReadHint

func ReadHint(dataDir string) (*Hint, error)

ReadHint loads the hint file. A missing file means "no sidecar ran" and is not an error for the caller.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL