-
Notifications
You must be signed in to change notification settings - Fork 1
Environment Files
Procodile can load an env file when starting the supervisor:
procodile start --env-file
procodile start --env-file .env.productionIf no file is provided, Procodile uses .env.
Relative paths are resolved from the application root.
For example:
procodile start -r /srv/myapp --env-fileProcodile reads:
/srv/myapp/.env
Environment variables are applied in the following order, from lowest to highest priority:
- Global
envfromProcfile.options - Global
envfromProcfile.local - The env file loaded with
--env-file -
processes.<process_name>.envfromProcfile.options -
processes.<process_name>.envfromProcfile.local
In practice, this means:
- the env file overrides global environment variables
- per-process environment variables override the env file
-
PROC_NAME,PID_FILE,APP_ROOT, andPORTare managed by Procodile and cannot be overridden by user-defined values
Environment variable names are treated case-insensitively, so they must be unique after being normalized to uppercase.
For example:
foo=foo
Foo=fooThis will produce a runtime issue such as:
Duplicate key FOO found in .env
Later variables in the same env file may reference earlier ones.
For example:
ENV1=foo
ENV2=${ENV1}This is valid, and ENV2 resolves to foo.
Env files are loaded through Crystal shards lucky_env, so LUCKY_ENV is supported.
If LUCKY_ENV is set, LuckyEnv first looks for an environment-specific file:
-
LUCKY_ENV=development→.env.development -
LUCKY_ENV=test→.env.test -
LUCKY_ENV=production→.env.production
If no matching file is found, or if LUCKY_ENV is not set, .env is used.
Changing an env file does not update the environment of processes that are already running.
New env file values are applied the next time a process is started or restarted.
For example, if you change .env and run:
procodile restart -p app1then app1 will read the updated env file, but app2 will keep its old environment until it is started or restarted later.
Likewise, procodile reload reloads Procodile configuration, but it does not restart running processes just to pick up env file changes.
The same rule applies to configured env values from the options files: reload updates Procodile's in-memory configuration immediately, but running processes keep their current environment until they are started or restarted again.
Given:
# Procfile.options
env:
APP_MODE: production
LOG_LEVEL: info
processes:
web:
env:
LOG_LEVEL: debugand:
# .env
APP_MODE=staging
API_HOST=api.internalthen:
-
APP_MODEbecomesstaging -
API_HOSTcomes from the env file - the global
LOG_LEVELremainsinfo -
LOG_LEVELremainsdebugforweb
That is the intended precedence:
process env > env file > global env