LemonCore.Runtime.Env (lemon_core v0.1.0)

View Source

Environment resolution for Lemon runtime startup.

Centralises all the environment-variable defaults and path normalization that previously lived in bin/lemon and bin/lemon-dev shell scripts.

Port defaults

PortEnv varDefault
controlLEMON_CONTROL_PLANE_PORT4040
webLEMON_WEB_PORT4080
simLEMON_SIM_UI_PORT4090

Usage

env = LemonCore.Runtime.Env.resolve()
env.control_port   #=> 4040
env.web_port       #=> 4080
env.lemon_root     #=> "/path/to/lemon"

Summary

Functions

Applies resolved port values to the OTP application environment so running apps pick up the right port without restarts.

Returns the effective control-plane port.

Returns true when debug mode is enabled via LEMON_DEBUG or LEMON_LOG_LEVEL=debug.

Returns the Lemon project root directory.

Returns the Erlang distribution cookie.

Returns the Erlang node name to use (defaults to "lemon").

Validates that a production-grade cookie has been configured.

Resolves the runtime environment from system environment variables and defaults.

Returns the effective sim-ui port.

Returns the effective web port.

Types

t()

@type t() :: %LemonCore.Runtime.Env{
  control_port: pos_integer(),
  debug: boolean(),
  dotenv_dir: String.t() | nil,
  lemon_root: String.t() | nil,
  node_cookie: String.t() | nil,
  node_name: String.t(),
  sim_port: pos_integer(),
  web_port: pos_integer()
}

Functions

apply_ports(env)

@spec apply_ports(t()) :: :ok

Applies resolved port values to the OTP application environment so running apps pick up the right port without restarts.

Safe to call multiple times (idempotent).

control_port()

@spec control_port() :: pos_integer()

Returns the effective control-plane port.

debug?()

@spec debug?() :: boolean()

Returns true when debug mode is enabled via LEMON_DEBUG or LEMON_LOG_LEVEL=debug.

lemon_root()

@spec lemon_root() :: String.t()

Returns the Lemon project root directory.

Reads LEMON_PATH if set; falls back to the directory two levels above this file's location (i.e. the umbrella root when running from source).

node_cookie()

@spec node_cookie() :: String.t() | nil

Returns the Erlang distribution cookie.

node_name()

@spec node_name() :: String.t()

Returns the Erlang node name to use (defaults to "lemon").

require_prod_cookie!()

@spec require_prod_cookie!() :: :ok

Validates that a production-grade cookie has been configured.

Raises RuntimeError if the cookie is the hardcoded dev default. Call this from the boot sequence when running in a production context (e.g. when RELEASE_NODE is set or MIX_ENV=prod).

resolve()

@spec resolve() :: t()

Resolves the runtime environment from system environment variables and defaults.

sim_port()

@spec sim_port() :: pos_integer()

Returns the effective sim-ui port.

web_port()

@spec web_port() :: pos_integer()

Returns the effective web port.