From 1428a8e006cff51b17ddb7bbf9d6eb9c3b9f1bb3 Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Fri, 13 Aug 2021 01:35:20 +0200 Subject: [PATCH] feat(config): Improve configurability of database by env This patch implements 6 additional environment variables that are used for configuration of the database in order to allow easier configuration in containerised environments, such as Kubernetes. An example is the upcoming deployment of the demo instance that will use an operator-backed postgresql database. This operator exposes username and password as separate variables and while it's obviously possible to generate a dbURL from that, this won't be possible without additional code. Aiming for a solution in Hedgedoc itself, will help us to enable other people in using Hedgedoc on Kubernetes without resulting in overly customised setups for simple tasks like this. Signed-off-by: Sheogorath --- docs/content/configuration.md | 6 ++++++ lib/config/environment.js | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/docs/content/configuration.md b/docs/content/configuration.md index 937a9e9c2..c6e3fc3eb 100644 --- a/docs/content/configuration.md +++ b/docs/content/configuration.md @@ -24,6 +24,12 @@ to `config.json` before filling in your own details. | -------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | `CMD_CONFIG_FILE` | **no default**, `/path/to/config.json` | optional override for the path to HedgeDoc's config file | | `db` | | **`undefined`**, `{ "dialect": "sqlite", "storage": "./db.hedgedoc.sqlite" }` | set the db configs, [see more here](https://sequelize.org/v5/manual/dialects.html) | +| `db.username` | `CMD_DB_USERNAME` | **`undefined`**, `hedgedoc-db-user` | Username used to authenticate to the database (host). | +| `db.password` | `CMD_DB_PASSWORD` | **`undefined`** | Password used to authenticate to the database (host). | +| `db.database` | `CMD_DB_DATABASE` | **`undefined`**, `hedgedoc` | Name of the database used to store hedgedoc data. | +| `db.host` | `CMD_DB_HOST` | **`undefined`**, `db-host.example.com` | Hostname used to connect the database server. | +| `db.post` | `CMD_DB_PORT` | **`undefined`**, `5432` | Port used to connect the database server. | +| `db.dialect` | `CMD_DB_DIALECT` | **`undefined`**, `postgres`, `mariadb` | [Dialect](https://sequelize.org/v5/manual/dialects.html) / protocol used to connect to the database. | | `dbURL` | `CMD_DB_URL` | **`undefined`**, `postgres://username:password@localhost:5432/hedgedoc` or `mysql://username:password@localhost:3306/hedgedoc` | Set the db in URL style. If set, then the relevant `db` config entries will be overridden. | | `loglevel` | `CMD_LOGLEVEL` | **`info`**, `debug` ... | Defines what kind of logs are provided to stdout. Available options: `debug`, `verbose`, `info`, `warn`, `error` | | `forbiddenNoteIDs` | `CMD_FORBIDDEN_NOTE_IDS` | **`['robots.txt', 'favicon.ico', 'api', 'build', 'css', 'docs', 'fonts', 'js', 'uploads', 'vendor', 'views']`**, `['robots.txt']` or `'robots.txt'` | disallow creation of notes, even if `allowFreeUrl` or `CMD_ALLOW_FREEURL` is `true` | diff --git a/lib/config/environment.js b/lib/config/environment.js index de4bd8731..1a43a88f9 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -35,6 +35,14 @@ module.exports = { forbiddenNoteIDs: toArrayConfig(process.env.CMD_FORBIDDEN_NOTE_IDS), defaultPermission: process.env.CMD_DEFAULT_PERMISSION, dbURL: process.env.CMD_DB_URL, + db: { + username: process.env.CMD_DB_USERNAME, + password: process.env.CMD_DB_PASSWORD, + host: process.env.CMD_DB_HOST, + port: process.env.CMD_DB_PORT, + database: process.env.CMD_DB_DATABASE, + dialect: process.env.CMD_DB_DIALECT + }, sessionSecret: process.env.CMD_SESSION_SECRET, sessionLife: toIntegerConfig(process.env.CMD_SESSION_LIFE), tooBusyLag: toIntegerConfig(process.env.CMD_TOOBUSY_LAG),