Documentation
¶
Overview ¶
Package specs is the named-spec store — store a spec once, reference it from many deployments.
WHAT THIS FIXES. Before this, every deployment carried its own copy of the spec, so 50 open PRs meant 50 byte-identical YAML files and a fix to the teardown logic had to be re-submitted 50 times. Worse, variables were not stored at all: `?PR=7` had to be repeated on every call, and passing a different value to `down` than to `up` silently tore down a *different stack* — the exact orphan class this project exists to prevent.
So a deployment now has two possible shapes:
inline { spec: "<yaml>" } its own copy, as before — still valid, still useful
for a one-off that shares nothing
referencing { specName: "web", vars: {…} } points at a named spec; the vars are STORED
Layout, alongside `deployments/`:
$PSTACK_DATA/specs/<name>/
spec.yml the spec source
compose.yml the compose file it references, when one was submitted with it
meta.json { name, kind, createdAt, updatedAt, description? }
Same reasoning as the deployment registry: a directory of YAML, not a database. It is a cache of intent, never the source of truth about what exists — that stays in Docker and in each axis's own `assert_*` probe.
Like the registry, meta.json is an ordered document (*omap.Map) with a typed view: the reference read it with a spread, so a key it never heard of came back in a list response in its place.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertValidSpecName ¶
AssertValidSpecName rejects a name that could not be a directory name.
func FindRequiredVars ¶
FindRequiredVars is which `${VAR}` references a spec cannot satisfy on its own.
Parsing needs every variable defined, so this probes with a sentinel environment and collects the names the parser rejects, one round at a time. Reported up front, a caller learns "this spec needs PR and GIT_SHA" from a list view instead of discovering it from a 400 on deploy.
Bounded: a spec whose own `env:` block is self-referential could otherwise loop. The result is sorted (`[...found].sort()` — byte order, which for identifier names is the same thing). The parser's error TEXT is scraped, which makes it a load-bearing internal contract.
Types ¶
type Error ¶
type Error struct{ Msg string }
Error is the store's own failure: a bad name, a rejected spec, no such spec.
type PutOptions ¶
type PutOptions struct {
ComposeYaml *string
// Description replaces the stored one when non-nil (`opts.description ?? prev?.description`).
Description *string
}
PutOptions are the extras a submission may carry.
type SpecMeta ¶
type SpecMeta struct {
Name string
// Kind is resolved from the stored source at write time, so a list view needs no re-parse.
Kind spec.Kind
Description string // "" when absent
CreatedAt int64
UpdatedAt int64
// RequiredVars are the variable names the spec interpolates but does not define — what a caller
// MUST supply. Never nil.
RequiredVars []string
// Doc is name, kind, description?, createdAt, updatedAt, requiredVars, plus any key another
// version wrote, in file order.
Doc *omap.Map
}
SpecMeta is meta.json. Doc is the stored document and what marshals; the rest is a decoded view.
func (SpecMeta) MarshalJSON ¶
MarshalJSON emits the stored document, as `{...meta}` did.
type SpecStore ¶
type SpecStore struct {
Root string
}
SpecStore is the named-spec store. Stateless apart from Root; safe to share.
func (*SpecStore) Get ¶
func (s *SpecStore) Get(name string) (*StoredSpec, error)
Get returns the spec, or nil when there is no spec.yml under that name.
func (*SpecStore) Put ¶
func (s *SpecStore) Put(name, specYaml string, opts PutOptions) (*StoredSpec, error)
Put creates or replaces a named spec.
Validated before anything is written, with sentinel values for whatever it interpolates — a named spec is a template, so it must be storable without knowing a particular PR's values.
type StoredSpec ¶
StoredSpec is a named spec with its paths.