Add config environment variables

The config file can now be specified with `INVIDIOUS_CONFIG_FILE`.
A YAML formatted string can still be passed with `INVIDIOUS_CONFIG`, replacing
the config file.

Additionally all options can now be specified as environment variables.
The syntax for variable names is `INVIDIOUS_` followed by the option name in
upper case. The values are parsed as YAML.

These new env vars only update the provided main configuration, but it is
possible to point the config file at the example config and then use env vars
for all config options:
```
INVIDIOUS_CONFIG_FILE=./config/config.example.yml \
INVIDIOUS_CHANNEL_THREADS=10 \
./invidious
```
This commit is contained in:
saltycrys 2021-01-23 18:58:13 +01:00
parent dd2a7f91cc
commit f1a7ee997b
2 changed files with 59 additions and 5 deletions

View file

@ -30,11 +30,8 @@ require "./invidious/*"
require "./invidious/routes/**"
require "./invidious/jobs/**"
ENV_CONFIG_NAME = "INVIDIOUS_CONFIG"
CONFIG_STR = ENV.has_key?(ENV_CONFIG_NAME) ? ENV.fetch(ENV_CONFIG_NAME) : File.read("config/config.yml")
CONFIG = Config.from_yaml(CONFIG_STR)
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)
CONFIG = Config.load
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)
PG_URL = URI.new(
scheme: "postgres",