Documentation
¶
Overview ¶
Package containerdump takes a snapshot of a store whose client tools live where the store does — inside its container.
A snapshot is made by the database's OWN tools (`pg_dump`, `mysqldump`), and w17 ran them on the machine w17ctl runs on. That machine often does not have them, and not by accident: a project driven by `w17ctl stack up` keeps everything in Docker on purpose — an adopter reported having no `go` either, and asked why w17 was telling them to install a Postgres client when one was already running two inches away, inside the container w17ctl had just started.
So when the host has no client, the dump runs in the container that serves the store. Found by the PORT the caller is already dialling: whatever publishes it is the store, whether compose started it or a bare `docker run` did.
The stream is the same either way — plain SQL from the same tool with the same flags — so a snapshot taken through the container restores through the host and back.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComposeServiceFor ¶
ComposeServiceFor names the compose SERVICE of the container that publishes the DSN's port, or "" when there is none.
It exists because a store has two names that are not required to agree: the connection name an author picks in their targets, and the compose service name in their stack file. `stack build` quiesced by excluding CONNECTION names from a list of SERVICE names, so where the two differed the store was stopped like anything else — and the snapshot arranged to run inside that container then failed with "pg_dump: executable file not found", which reads like a missing tool rather than a container that is no longer running. Crossing the namespaces through the container is the one comparison that does not depend on the two names matching.
Types ¶
type Snapshotter ¶
type Snapshotter struct {
// contains filtered or unexported fields
}
Snapshotter runs a store's own dump/restore client inside the container that serves it.
func For ¶
func For(ctx context.Context, dsn string) *Snapshotter
For returns a container-backed Snapshotter for a DSN, or nil when there is no container to use.
Nil rather than an error: this is a FALLBACK. The caller's first choice is the host's own client, and "no container either" has to read as "this route is unavailable" so the caller can say something true about both.
func ForReason ¶
func ForReason(ctx context.Context, dsn string) (*Snapshotter, string)
ForReason is For plus the reason it declined, in a phrase that completes "the dump could not run inside a container: …".
The reason exists because declining used to be SILENT. With two stores in a project the fallback engaged for one and not the other, and the only thing the person saw was the host error — `pg_dump: executable file not found in $PATH` — which names the host and says nothing about the route that was tried and refused. Nobody could tell whether the fallback had failed or simply did not exist. A fallback that declines without a word is indistinguishable from one that is not there.
func (*Snapshotter) Container ¶
func (s *Snapshotter) Container() string
Container is the container the snapshot would run in, for a message that says where the work happened.
func (*Snapshotter) Dump ¶
Dump streams the store's contents, produced by the client inside the container. The flags mirror the host-side snapshotter's exactly — a stream that only one of the two can read would make the route a person took part of whether their snapshot is restorable.
func (*Snapshotter) StoreObjects ¶
func (s *Snapshotter) StoreObjects(ctx context.Context) ([]string, error)
StoreObjects implements migrate.ObjectCounter through the same container.
The question matters most on THIS route: it is the one that can reach a database the store does not name, because the container is found by published PORT when the compose stack does not answer. An object-less dump here is therefore genuinely ambiguous, and this is what resolves it — asked of the store's own DSN inside the container, so the answer comes from the same place the dump would have come from.
The SQL is the public migrate package's constant, not a second spelling of it: two copies of "what counts as an object" would be free to disagree, and the disagreement would read as a snapshot accepted on one route and refused on the other.