Environment Read environment variables are only read during bootstrap
- Comparing
- v1 to v2
- Current
- Read the document
Context
Some values the panel needs, such as secrets, come from environment variables, variables,
supplied either through the process
process environment or through a local env file. They are needed while the panel is being being
configured. Once it has been,
, nothing should depend on reading them directly.
Decision
Environment variables are held by I will hold environment variables in Env, a static singleton initialised once once
during bootstrap from either the
the $_ENV superglobal or an env file, and it exists Env will exist only during initial initial
bootstrapping. Initialising it a second time,
, or reading from it before it has been initialised, throwswill throw, and its its
typed accessors will throw when a value cannot be cast
cast to the type requested. Code outside bootstrap does will not read read
environment variables.
Alternatives
No alternatives were weighed.
Consequences
Easier:
- Environment
variables arevariables will be available anywhere during bootstrap withoutbeingbeing passed around. - Reading a variable as a specific type
failswill fail loudly when its value cannot be cast.
Harder:
- Nothing in the type system
stopswill stop code outside bootstrap from readingEnv, so keeping it to bootstraprelies onwill rely on discipline. - An env file
iswill be read intoEnvalone, without populating$_ENV, so nothing else in the processsees itswill see its values.
Constrained:
- Components will receive values drawn from the environment through their configuration, not by reading
thethe environment. - Configuration
resolveswill resolve environment variables while it is loaded.
Sources
- Issue #22, Engine - Config, : environment variables loaded from the
$_ENVsuperglobal or a local env file. - Commit c4c9f51, "Initial config work", , on the branch of PR #25: the first code of
Env, which iscreated. - Commit 599a0ea, "Introduce an exception around env initialisation", , on the same branch: throwing when
Envis used before initialisation or initialised twice. - PR #25, feat(config): Add config component, merged and squashed as 180794a:
Envas merged, which isdecided. Envbeing a static singleton by design that exists only during initial bootstrapping, and its typed accessors throwing when a value cannot be cast: first written down on .- Issue #31, Engine - Config - TOML, revision of in its edit history: configuration resolving environment
variables against
Envwhile it is loaded, taken from what followed rather than anticipated.
Source adr/0006-environment-at-bootstrap.md · commit 9444a99 · published