envnet

package
v0.1.4 Latest Latest
Warning

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

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

Documentation

Overview

Package envnet maps a tile to its environment's isolated Docker network and slug-based naming. Each environment holds one attachable overlay out of a pool (infra/netpool), the name says nothing, the env row is the mapping. Traefik is attached to every one so it can route HTTP to any tile, while tiles themselves can only reach their own environment (and a shared instance over its own network, repo.Tile.SharedNet).

Every docker object name is built here and nowhere else. Names are made of slugs joined by "_": Slugify emits only [a-z0-9-], so no slug can contain an underscore and the segments cannot be confused. A "-" separator would be ambiguous (stack "a-b" + env "c" reads the same as "a" + "b-c"), which is the collision this scheme exists to remove. Names are never parsed back; anything that needs the rows goes to the rows.

Nothing resolves a tile by container name, tiles get explicit DNS aliases (the tile slug and TileAlias), so the separator is operator-facing only.

Index

Constants

View Source
const (
	Prefix      = "stkr_"
	ImagePrefix = "stkr/"
)

Prefix opens every docker object stackr owns: networks, containers and the panel's own traefik/registry/relay containers. Images use ImagePrefix. Volumes are the exception, they keep the older "stackr-" prefix, because docker cannot rename a volume and a prefix change would detach live data (repo.StorageVolume).

Variables

This section is empty.

Functions

func Net

func Net(ctx context.Context, store repo.Store, envID string) (string, error)

Net is the overlay an environment sits on, without claiming one. Empty means nothing has deployed into the env yet.

func RecordProxyAddr

func RecordProxyAddr(ctx context.Context, store repo.Store, c *cluster.Cluster, envID, netName string)

RecordProxyAddr stores where Traefik sits on one environment network, feeding ${{ stackr.PROXY_IP }} / ${{ stackr.PROXY_CIDR }}. Call it after attaching.

Best-effort throughout: this is a convenience for config files, and no failure here should stop a deploy or stop Traefik serving. A missed write leaves the previous value standing until the next attach.

func ServiceFor

func ServiceFor(ctx context.Context, store repo.Store, t *repo.Tile) string

ServiceFor resolves the swarm service name for a tile ("" if its stack or environment is already gone, which teardown treats as nothing to remove).

func TearDown

func TearDown(ctx context.Context, store repo.Store, c *cluster.Cluster, t *repo.Tile)

TearDown removes everything docker holds for one tile: its service, and any container left under the tile's labels. Both halves are needed, removing a task's container only makes swarm start another, and a box that deployed before the swarm move still has plain containers under the same labels.

Best-effort throughout: a tile whose objects are already gone must not strand its rows.

func TileAlias

func TileAlias(tileID string) string

TileAlias is the tile's globally-unique DNS alias, used by Traefik which sits on every environment network (plain slugs would collide across envs).

func UpperEnv

func UpperEnv(ctx context.Context, store repo.Store, t *repo.Tile) bool

UpperEnv reports whether the tile lives above the default env, the first static env of its stack. Upper rungs get images by Promote from a plan row, so a build from branch head is refused there. store order, like the pr hook and allAuto.

Types

type Scope

type Scope struct {
	OrgSlug   string
	StackSlug string
	EnvSlug   string
}

Scope is the resolved naming context for one tile.

func Ensure

func Ensure(ctx context.Context, store repo.Store, c *cluster.Cluster, t *repo.Tile) (Scope, string, error)

Ensure resolves the tile's scope and claims the environment's overlay out of the pool if it has none yet. Returns the scope and the network name; nothing may derive the network from the scope.

Traefik is deliberately not attached here. It is a service now, and a service joining a network rolls every one of its tasks, an environment create would take 80 and 443 down. Traefik holds the whole pool from the moment it starts (infra/proxy), so the network this claims is already one of its own.

func ForStack

func ForStack(ctx context.Context, store repo.Store, st *repo.Stack, envSlug string) (Scope, error)

ForStack builds the scope for one environment of a stack, loading the org for its slug. Callers that hold the rows already use this over Resolve.

func Resolve

func Resolve(ctx context.Context, store repo.Store, t *repo.Tile) (Scope, error)

Resolve looks up the tile's stack and environment slugs.

func (Scope) ContainerName

func (s Scope) ContainerName(tileSlug, suffix string) string

ContainerName is the operator-facing container name for a tile; suffix distinguishes coexisting containers (e.g. deployment id) and may be empty. The suffix joins on the same separator: a slug can never contain one, so a tile named "site" with suffix "abc" cannot collide with a tile named "site_abc", no such slug exists.

func (Scope) ImageRepo

func (s Scope) ImageRepo(tileSlug string) string

ImageRepo is the local image repository for a tile's builds. No env in it: an image is a property of (stack, tile, commit), and baking the env in would make promoting a built image between environments impossible.

func (Scope) ServiceName

func (s Scope) ServiceName(tileSlug string) string

ServiceName is the swarm service for a tile: the scoped name with no suffix. Stable for the life of the tile, a deploy updates the service in place and swarm rolls the tasks, so unlike the old per-deployment container name there is nothing to disambiguate.

Jump to

Keyboard shortcuts

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