specs

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT, MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func AssertValidSpecName(name string) error

AssertValidSpecName rejects a name that could not be a directory name.

func FindRequiredVars

func FindRequiredVars(source string) []string

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.

func IsError

func IsError(err error) bool

IsError reports whether err is a *Error.

Types

type Error

type Error struct{ Msg string }

Error is the store's own failure: a bad name, a rejected spec, no such spec.

func (*Error) Error

func (e *Error) Error() string

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

func (m SpecMeta) MarshalJSON() ([]byte, error)

MarshalJSON emits the stored document, as `{...meta}` did.

func (SpecMeta) Pairs

func (m SpecMeta) Pairs() jsonx.Object

Pairs is the document as an ordered object a route can extend (`{ ...stored, source }`). Do not embed SpecMeta in a response struct: the promoted MarshalJSON would swallow the outer fields.

type SpecStore

type SpecStore struct {
	Root string
}

SpecStore is the named-spec store. Stateless apart from Root; safe to share.

func New

func New(dataDir string) *SpecStore

New returns the store rooted at <dataDir>/specs.

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

func (s *SpecStore) List() ([]SpecMeta, error)

List is every spec with a readable meta.json, newest updatedAt first.

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.

func (*SpecStore) Remove

func (s *SpecStore) Remove(name string) error

Remove deletes a named spec.

Callers MUST check for referencing deployments first — a dangling reference would leave a deployment that can never be torn down, since resolving it needs the spec. The API enforces it; this layer stays mechanical.

func (*SpecStore) Source

func (s *SpecStore) Source(name string) (string, error)

Source is the raw source, for showing or editing.

type StoredSpec

type StoredSpec struct {
	SpecMeta
	Dir      string
	SpecPath string
}

StoredSpec is a named spec with its paths.

Jump to

Keyboard shortcuts

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