Documentation
¶
Overview ¶
Package config loads and validates the runtime configuration from the process environment. Everything is injectable so the loader can be unit tested without touching the real environment.
Index ¶
Constants ¶
const ( DefaultDockerHost = "unix:///var/run/docker.sock" DefaultLabelPrefix = "npm" DefaultDebounceInterval = 3 * time.Second DefaultDebounceMaxWait = 30 * time.Second DefaultResyncInterval = 5 * time.Minute DefaultHTTPTimeout = 30 * time.Second // DefaultCertificatePoll is how often the certificate list is checked for // changes, so a certificate created in the UI reaches its hosts without a // restart. DefaultCertificatePoll = time.Minute // DefaultStopGrace covers a restart or a `docker compose up` recreate, so // neither produces a disable/enable cycle. DefaultStopGrace = time.Minute // DefaultDeleteGuard is the largest share of the managed resources a // single run may delete before it is stopped and reported. DefaultDeleteGuard = 0.5 )
Defaults used when the corresponding environment variable is unset.
const DefaultDeleteGuardMin = 3
DefaultDeleteGuardMin is how many deletions a run needs before the share guard applies.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// NPM / NPMplus API.
NPMURL string
NPMIdentity string
NPMSecret string
NPMTimeout time.Duration
NPMInsecureSkipVerify bool
// NPMFlavour pins the API dialect instead of probing for it.
NPMFlavour npm.Flavour
// Docker endpoint. Either a unix socket or a TCP endpoint pointing at a
// docker-socket-proxy (recommended, see SECURITY.md).
DockerHost string
// Behaviour.
LabelPrefix string
ResolveIP bool
NPMNetwork string
// StrictNetwork skips a container that is not attached to NPMNetwork
// instead of falling back to an address NPM cannot route to. Only has an
// effect when NPMNetwork is set.
StrictNetwork bool
// NPMContainer is the name of the NPM/NPMplus container. When set, its
// networks are used for upstream resolution (Redth: NPM_CONTAINER_NAME).
NPMContainer string
// ExposedByDefault manages every container carrying labels of the
// namespace, without requiring npm.enable=true.
ExposedByDefault bool
// StrictLabels skips a resource whose labels contain an unknown field.
StrictLabels bool
// PortPreference orders the exposed ports when a container has several.
PortPreference []int
// Defaults are the effective per-field defaults from the environment.
Defaults *fields.Defaults
// CertificatePartial decides what happens when no certificate covers
// every domain of a host.
CertificatePartial certs.Partial
// CertificateAutoCreate requests a Let's Encrypt certificate when the
// automatic selection finds nothing.
CertificateAutoCreate bool
// CertificatePoll is how often the certificate list is polled.
CertificatePoll time.Duration
// MigrateFromRedth takes over hosts created by Redth/npm-docker-sync.
MigrateFromRedth bool
// OnStop decides what happens to the resources of a container that is
// stopped but still exists.
OnStop docker.OnStop
// StopGrace is how long a stopped container is ignored, so a restart does
// not produce a disable/enable cycle.
StopGrace time.Duration
// InstanceID identifies this sync instance in the resource meta.
InstanceID string
// DeleteGuard is the largest share of the managed resources one run may
// delete; 0 disables the guard.
DeleteGuard float64
// DeleteGuardMin is how many deletions a run needs before the share guard
// applies at all.
DeleteGuardMin int
Kinds []npm.Kind
DebounceInterval time.Duration
DebounceMaxWait time.Duration
ResyncInterval time.Duration
DeleteOrphans bool
AdoptExisting bool
DryRun bool
ShutdownTimeout time.Duration
// Observability.
LogLevel slog.Level
LogFormat string
HealthAddr string
// LogPayloads mirrors full API request bodies into the debug log.
LogPayloads bool
// Warnings are non-fatal configuration problems, reported once at start.
Warnings []string
// Notices record which alias spelling of a variable was used, so a
// configuration copied from another project is traceable in the log.
Notices []string
}
Config is the fully resolved runtime configuration.
func Load ¶
Load reads the configuration using the supplied lookup function and the process environment. Pass os.Getenv and os.Environ() in production code; environ is only read to warn about misspelled NPM_<KIND>_<FIELD> variables.
func LoadForCheck ¶
LoadForCheck is Load without the NPM credentials, for the `validate` subcommand: a pre-deploy check reads labels and never talks to the API, so demanding an URL and a password would only stand in its way.