deployurls

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package deployurls keeps an immutable hostname for each recent successful deploy: a retained service that runs that attempt's pinned image and sleeps when idle, so a past deployment can be opened without rolling back.

Index

Constants

View Source
const (
	// EnvKeep is how many recent successful deploys per app keep a URL; 0 turns the feature off.
	EnvKeep = "APP_DEPLOY_URL_KEEP"
	// EnvIdleMinutes is how long a retained deploy runs without traffic before it sleeps.
	EnvIdleMinutes = "APP_DEPLOY_URL_IDLE_MINUTES"
	// EnvInterval is how often the syncer looks for new deploys.
	EnvInterval = "APP_DEPLOY_URL_INTERVAL"
)

Environment variables that tune deploy URLs.

View Source
const (
	DefaultKeep        = 3
	DefaultIdleMinutes = 5
	DefaultInterval    = time.Minute
)

Defaults for the variables above.

Variables

This section is empty.

Functions

func Clone

Clone is the retained service for w: the app's config restored to that attempt, running the pinned image, with no volumes, host ports, hooks or automatic rollback, so an old deploy cannot touch live data or fight the app.

func Key

func Key(a store.DeployAttempt) string

Key is the short, DNS-safe identity of an attempt: the commit when it has one, else its id.

func ServiceName

func ServiceName(app, key string) string

ServiceName is the retained service for app and key; it doubles as the host label.

Types

type Config

type Config struct {
	Keep        int
	IdleMinutes int
	Interval    time.Duration
}

Config is the environment-driven tuning.

func ConfigFromEnv

func ConfigFromEnv(getenv func(string) string) Config

ConfigFromEnv reads the Env* variables, using defaults for anything missing or malformed.

func FromProcessEnv

func FromProcessEnv() Config

FromProcessEnv is ConfigFromEnv over the process environment.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether any URLs are kept.

type Store

type Store interface {
	ListDesiredServices(ctx context.Context) ([]store.DesiredService, error)
	SaveDesiredService(ctx context.Context, svc store.DesiredService) error
	ListDeployAttempts(ctx context.Context, serviceName string) ([]store.DeployAttempt, error)
	ListRollbackPins(ctx context.Context, serviceName string) ([]store.RollbackPin, error)
	SetAppSleepIdle(ctx context.Context, serviceName string, minutes int, now time.Time) error
	SetAppSleepHold(ctx context.Context, serviceName string, hold bool, now time.Time) error
	ListDeployURLs(ctx context.Context, appName string) ([]store.DeployURL, error)
	SaveDeployURL(ctx context.Context, u store.DeployURL) error
	DeleteDeployURL(ctx context.Context, serviceName string) error
}

Store is what the syncer needs; *store.DB satisfies it.

type Syncer

type Syncer struct {
	Store  Store
	Config Config
	// HostFor returns the hostname for a retained service, or "" when none can be formed.
	HostFor func(ctx context.Context, serviceName string) string
	// Remove deletes a retained service and tears its containers down.
	Remove func(ctx context.Context, serviceName string) error
	// Nudge asks the reconcilers to run now.
	Nudge  func()
	Now    func() time.Time
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Syncer reconciles retained deploy services against each app's recent deploys.

func (*Syncer) Run

func (s *Syncer) Run(ctx context.Context) error

Run syncs every Config.Interval until ctx ends.

func (*Syncer) Sync

func (s *Syncer) Sync(ctx context.Context) error

Sync runs one pass. A failure on one app is logged and does not stop the rest.

type Wanted

type Wanted struct {
	Attempt     store.DeployAttempt
	Key         string
	ServiceName string
	Pin         *store.RollbackPin
	Ref         string
	// Live is true while the attempt is what the app runs now: the app's own URL serves it.
	Live bool
}

Wanted is one deploy attempt that should have a URL.

func Plan

func Plan(app store.DesiredService, attempts []store.DeployAttempt, pins []store.RollbackPin, keep int) []Wanted

Plan picks the newest keep successful attempts whose content can still be redeployed (a registry digest or a rollback pin). Two attempts of the same commit share one URL, the newest. Image GC is untouched: it only frees what no pin or running service holds.

Jump to

Keyboard shortcuts

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