The Game Panel Design record
The Game Panel
ADR-0006 Accepted

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 are variables will be available anywhere during bootstrap without being being passed around.
  • Reading a variable as a specific type fails will fail loudly when its value cannot be cast.

Harder:

  • Nothing in the type system stops will stop code outside bootstrap from reading Env, so keeping it to bootstrap relies on will rely on discipline.
  • An env file is will be read into Env alone, without populating $_ENV, so nothing else in the process sees its will see its values.

Constrained:

  • Components will receive values drawn from the environment through their configuration, not by reading the the environment.
  • Configuration resolves will resolve environment variables while it is loaded.

Sources

  • Issue #22, Engine - Config, : environment variables loaded from the $_ENV superglobal or a local env file.
  • Commit c4c9f51, "Initial config work", , on the branch of PR #25: the first code of Env, which is created.
  • Commit 599a0ea, "Introduce an exception around env initialisation", , on the same branch: throwing when Env is used before initialisation or initialised twice.
  • PR #25, feat(config): Add config component, merged and squashed as 180794a: Env as merged, which is decided.
  • Env being 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 Env while it is loaded, taken from what followed rather than anticipated.

Source adr/0006-environment-at-bootstrap.md · commit 9444a99 · published