envops

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package envops holds environment lifecycle operations shared by the web UI and automation triggers (PR webhooks): config-only cloning and full teardown. clone-with-data (db dump/restore, volume copy) is the planned follow-up and slots in here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoHost

func AutoHost(res repo.DomainResource, orgSlug, stackSlug, envSlug, tileSlug string, isDefaultEnv bool) string

AutoHost is the generated hostname for a tile under a domain resource: dotted segments truncated at the owning level (a stack-owned base already implies the stack, so its segment is dropped), the default env's slug omitted unless the resource opts in.

func BackfillVariables

func BackfillVariables(ctx context.Context, store repo.Store) error

BackfillVariables projects existing tiles' env blobs into `variables` rows.

The resolver reads rows only. Rows are written when a tile is written, so an upgraded install has tiles whose env exists solely in the blob, and those apps would deploy with an empty environment, silently, until someone happened to re-save them. This runs once at startup after the cipher is loaded (the migration itself can't do it: the blob is encrypted).

Skips any tile that already has rows, so a structured edit is never overwritten by a stale blob.

goes away with the blob at R7's follow-up, along with projectEnvVars.

func CheckOrgSquat

func CheckOrgSquat(ctx context.Context, store repo.Store, host, ownOrgID string) error

CheckOrgSquat rejects a hostname whose first label is another organization's slug. Generated hostnames nest under an org's own domains, so a host like orgb.example.com claimed by org A can shadow or impersonate org B's addresses. Every path that accepts a hostname goes through here: org domain resources, tile-level custom domains and config-as-code domain blocks.

func ConvertLegacyMounts

func ConvertLegacyMounts(ctx context.Context, store repo.Store) error

ConvertLegacyMounts is the one-shot upgrade to volume tiles: every named `name:/path` line on a service becomes an attached volume tile keeping the legacy docker volume name (data preserved). Bind-mount paths (starting with / or .) stay as text, they're host paths, not volumes. Guarded by a settings flag so it runs once.

func CopyLayout

func CopyLayout(ctx context.Context, store repo.Store, fromEnvID, toEnvID string)

CopyLayout copies one environment's saved card positions onto another's canvas. Env layouts are slug-keyed (clones keep slugs), so rows transfer verbatim; uuid-keyed nodes (resources, jobs, port forwards) would point into the source env, so they're skipped and those cards auto-place. Best-effort, a layout is cosmetic and must never fail a clone.

func HostTaken

func HostTaken(all []repo.DomainResource, host string) bool

HostTaken reports whether another resource already owns host (hosts are globally unique, the DB index enforces it, this gives a friendly error).

func SavePRConfig

func SavePRConfig(ctx context.Context, store repo.Store, stackID string, cfg PRConfig) error

SavePRConfig persists a stack's PR-environment config.

func ValidateResourceHost

func ValidateResourceHost(host string) error

ValidateResourceHost checks a domain-resource host: non-empty, lowercase, a bare hostname (no scheme, slash, port or spaces). One rule shared by the panel forms and the API so every surface rejects the same inputs.

func VisibleDomainResources

func VisibleDomainResources(all []repo.DomainResource, stackID, orgID string) []repo.DomainResource

VisibleDomainResources filters to what a stack may claim under, its own, its org's, the instance's, nearest level first, then a declared resource ahead of an undeclared one, oldest first within that.

Declared wins because the wizard hands an org with no domain of its own a default under the server's hostname, so its stacks get names at all. That row is older than anything a config file declares later, and oldest-first alone would leave the default beating the domain the file actually asked for.

Types

type Ops

type Ops struct {
	Store repo.Store
	RT    *runtime.Runtime
	// Cluster is what the managed-tiles service is built from. Required on
	// every path that provisions or tears down: a nil one used to fall back
	// to the local socket, silently (docs/plans/35-cluster.md).
	Cluster *cluster.Cluster
	PX      *proxy.Proxy
	// DBs lets Teardown reclaim the slices an ephemeral env provisioned.
	// Optional: the paths that only clone or route leave it nil.
	DBs *managedtiles.Service
}

Ops bundles the dependencies environment operations need.

func (Ops) CloneTiles

func (o Ops) CloneTiles(ctx context.Context, env *repo.Environment) error

CloneTiles copies every tile of env.BaseEnvID into env: same config, fresh identity (id, webhook token, db password). Sibling references survive: any env var mentioning a base db tile's password is rewritten to the clone's new password (hosts stay the same, slug aliases are per-env-network). Config-only, domains are not copied (hosts are globally unique) and no containers are started.

func (Ops) EnsureAutoDomain

func (o Ops) EnsureAutoDomain(ctx context.Context, env *repo.Environment, t *repo.Tile) error

EnsureAutoDomain gives a service tile its generated hostname under the nearest domain resource visible to its stack. Fired on request (config `auto: true`, panel/CLI ask, clone of a tile that had one), never automatically for every tile. Idempotent; a stale generated row (the naming pattern or resource changed) is replaced. HTTPS: per-host Let's Encrypt http-challenge, works at any dot depth, no wildcard cert.

func (Ops) Teardown

func (o Ops) Teardown(ctx context.Context, stack *repo.Stack, env *repo.Environment) error

Teardown removes an environment's containers, proxy routes, and network, then its rows (tiles cascade). DB volumes are kept, matching single-db deletes.

RT and PX are treated as optional here, the same way DBs already is: every call through them is best-effort (the errors are discarded, a container that is already gone must not strand the rows), so skipping them when there is no docker to talk to changes nothing for the server and lets the row-level half of teardown (slice reclaim and the variable cleanup below) be tested without one.

func (Ops) TeardownStack

func (o Ops) TeardownStack(ctx context.Context, stack *repo.Stack) error

TeardownStack tears every environment of a stack down, which is what has to happen before the stack row goes: DeleteStack cascades the rows, and a pooled overlay is only ever freed by name, so a plain cascade left every environment's network claimed forever and its services running on a network nothing owned.

type PRConfig

type PRConfig struct {
	Enabled bool   `json:"enabled"`
	Secret  string `json:"secret"` // webhook HMAC secret
	// Inverted so the zero value keeps both on for existing stacks.
	NoComment bool `json:"no_comment"` // suppress the sticky PR preview comment
	NoStatus  bool `json:"no_status"`  // suppress the commit status check
}

PRConfig enables GitHub pull-request environments for one stack. What each PR env contains comes from the config file's pr_envs: template, not from a base environment, there is nothing to pick here.

func LoadPRConfig

func LoadPRConfig(ctx context.Context, store repo.Store, stackID string) PRConfig

LoadPRConfig reads a stack's PR-environment config (zero value if unset).

Jump to

Keyboard shortcuts

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