bootstrap

package
v0.251.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 11 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 bootstrap reads the settings a server needs before it can read its settings.

Configuration lives in the database, which means the connection to the database cannot live there too. That one thing comes from the environment, and so does the seed for a database that has no configuration in it yet: a fresh instance has to be told its own name and where to listen before anyone can log in and change it.

The split matters once more than one instance is running. Anything in the database is shared, and changing it in the dashboard changes it everywhere. Anything here is per-process, and changing it means restarting that process — so this stays deliberately small.

Index

Constants

View Source
const Prefix = "TEANODE_"

Prefix is on the front of every variable this package reads.

Variables

This section is empty.

Functions

func SetSecretFile added in v0.86.0

func SetSecretFile(path string)

SetSecretFile is how the command line's --secret-file reaches every command that reads the environment through Load.

func Variables

func Variables() []string

Variables is every environment variable this package reads, fully prefixed.

Derived from the tables that read them rather than listed a second time, because a second list is one that goes out of date the first time somebody adds a variable and does not know it exists.

Types

type Bootstrap

type Bootstrap struct {
	// Database is where everything else is kept.
	Database config.Database

	// InstanceID distinguishes this process from the others sharing the
	// database. It is part of the primary key of the usage counters, which
	// are accumulated by reading a row, adding to it and writing it back —
	// safe only while no other instance is doing that to the same row.
	//
	// So it has to differ per process, and it has to be stable across a
	// restart of the same one, or yesterday's counters are stranded under a
	// name nothing writes to any more. A container's hostname is both.
	InstanceID string

	// UpgradeDirectory is where an upgrade stages a binary that cannot
	// replace the running one, and where the next start looks for it.
	//
	// Here rather than in the configuration, which is where every other path
	// this server uses lives, because of when it is needed. A staged binary
	// has to be found and run before anything opens the database — this
	// program reverts migrations it does not recognize, so an old binary that
	// reached the database first would undo the new one's schema — and the
	// configuration is in the database. So it comes from the environment, or
	// from the data directory the environment names, or from nowhere, in
	// which case a deployment that cannot write over its own binary is told
	// it cannot upgrade itself.
	UpgradeDirectory string

	// SecretFile is where the server secret is kept when it is kept out of
	// the database: --secret-file, or TEANODE_SECRET_FILE. Empty keeps it
	// in the database, as every server did before. Here because the
	// secret opens what the database holds, so it cannot come from there.
	SecretFile string

	// Seed is applied to the defaults when the database holds no
	// configuration yet, and ignored on every later start. See Seeded.
	//
	// It is not a complete configuration on its own — see SeedConfiguration,
	// which is what fills in the rest and says what is missing.
	Seed *config.Configuration

	// SeedDomain names a domain this server should serve, remembered as a
	// row in the domain table on a first run rather than as a setting. Empty
	// when the environment named none; the web UI adds domains afterwards.
	SeedDomain string

	// ServicePreset applies only when creating a new configuration.
	ServicePreset string
	// contains filtered or unexported fields
}

Bootstrap is what the environment says.

func Load

func Load() (*Bootstrap, error)

Load reads the environment.

Nothing here reaches the filesystem or the network, so it is safe to call before logging is configured and cheap to call in a test.

func (*Bootstrap) ReadSecretFile added in v0.86.0

func (self *Bootstrap) ReadSecretFile() (*config.SecretFile, error)

ReadSecretFile reads the server secret from where it is kept, or nil when it is kept in the database.

func (*Bootstrap) ReportIgnoredSeed

func (self *Bootstrap) ReportIgnoredSeed(current *config.Configuration)

ReportIgnoredSeed says which variables disagree with the configuration that is actually in force.

This is the confusing half of the design: an operator edits TEANODE_SERVER_NAME in their compose file, restarts, and nothing changes, because the database already has an answer and the database wins.

Only the ones that disagree are reported. A compose file sets all of these on every start and almost always sets them to what is already stored; warning about those too would put a wall of text in the log on every restart, and a warning that is always there is one nobody reads.

func (*Bootstrap) SeedConfiguration

func (self *Bootstrap) SeedConfiguration() (*config.Configuration, error)

func (*Bootstrap) SeedDomainRow

func (self *Bootstrap) SeedDomainRow(seed *config.Configuration) (*models.Domain, error)

SeedDomainRow is the domain a first run creates, with the parts that depend on values only settled once every variable has been applied: where its own records live, and a signing key. Nil when the environment named no domain.

Creating the domain here is what turns two variables into a working server: without it a first start would store a server with nowhere for mail to go, and the operator would be told to add a domain before they could reach the web UI that adds domains.

func (*Bootstrap) SeededNames

func (self *Bootstrap) SeededNames() []string

SeededNames lists the first-run variables that were set, whatever became of them.

func (*Bootstrap) WouldChange

func (self *Bootstrap) WouldChange(current *config.Configuration) ([]string, error)

WouldChange names the first-run variables that disagree with a stored configuration — the ones whose value is not already in force.

Jump to

Keyboard shortcuts

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