> For the complete documentation index, see [llms.txt](https://gift.icbest.ca/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gift.icbest.ca/getting-started/environnement-variables.md).

# Environnement variables

### How configuration works

Settings come from three places. The first one that has a value wins:

1. **Environment variables** (highest priority). Docker `environment:`, `-e`, or your system environment. They override everything and cannot be changed in the admin panel.
2. **`settings.json`** in `/data`. Saved from the admin panel. Non-secret settings only.
3. **Default values** hardcoded in the app.

**Secrets** can only be set with environment variables. They are never saved to `settings.json`.

#### Migrating from `.env`

If you have an old `/data/.env`, leave it in place. On first start the app copies the non-secret values to `settings.json`. Once `settings.json` appears in `/data`, you can delete the `.env` file.

**Secrets from the old `.env` are only used for that first migration.** Set them as environment variables going forward (for example `SECRET_KEY`, which is required).

### Secrets (environment variables only)

<table data-search="false"><thead><tr><th>Key</th><th>What it does</th><th>Default</th></tr></thead><tbody><tr><td><code>SECRET_KEY</code></td><td>Secures session cookies. Must be private and unpredictable. Changing it signs users out but does not delete accounts or gifts.</td><td><code>changethis</code> (replace it!)</td></tr><tr><td><code>MAILJET_API_KEY</code></td><td>Needed for Mailjet emails. If missing, the app will NOT contact Mailjet.</td><td>[empty]</td></tr><tr><td><code>MAILJET_API_SECRET</code></td><td>Needed for Mailjet emails.</td><td>[empty]</td></tr><tr><td><code>SMTP_PASSWORD</code></td><td>SMTP password. Use this <strong>or</strong> <code>SMTP_PASSWORD_FILE</code>, not both.</td><td>[empty]</td></tr><tr><td><code>SMTP_PASSWORD_FILE</code></td><td>Path to a file inside the container containing the SMTP password (a trailing newline is removed). Not both with <code>SMTP_PASSWORD</code>.</td><td>[empty]</td></tr><tr><td><code>OIDC_CLIENT_ID</code></td><td>See OIDC Support.</td><td>[empty]</td></tr><tr><td><code>OIDC_CLIENT_SECRET</code></td><td>See OIDC Support.</td><td>[empty]</td></tr></tbody></table>

### Email settings

Mailjet is the default provider. Set `EMAIL_PROVIDER=smtp` to use SMTP. There is no automatic fallback between providers.

| Key              | What it does                                                                                                                       | Default                              |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| `EMAIL_PROVIDER` | `mailjet` or `smtp`.                                                                                                               | `mailjet`                            |
| `SYSTEM_EMAIL`   | Sender address for notifications. Use one your provider allows. Editable in the admin panel unless set as an environment variable. | \[empty]                             |
| `SMTP_HOST`      | SMTP server hostname. Required for SMTP.                                                                                           | \[empty]                             |
| `SMTP_PORT`      | SMTP port.                                                                                                                         | `587` (`465` if `SMTP_SECURITY=ssl`) |
| `SMTP_SECURITY`  | `starttls`, `ssl` (TLS from the start), or `none` (trusted local relay only). The certificate and hostname are always verified.    | `starttls`                           |
| `SMTP_USERNAME`  | SMTP login. Leave empty with no password for an unauthenticated relay.                                                             | \[empty]                             |

SMTP variables are set as environment variables (not in the admin panel). Login over `SMTP_SECURITY=none` is refused.

### App settings

Editable in the admin panel, unless the same key is set as an environment variable.

<table data-search="false"><thead><tr><th>Key</th><th>What it does</th><th>Default</th></tr></thead><tbody><tr><td><code>SYSTEM_EMAIL</code></td><td>Sender address for notifications. Use one your provider allows. Editable in the admin panel unless set as an environment variable.</td><td>[empty]</td></tr><tr><td><code>DELETE_DAYS</code></td><td>Days before bought ideas are auto-deleted. See Deletion Script.</td><td><code>30</code></td></tr><tr><td><code>OIDC_SERVER_METADATA_URL</code></td><td>See OIDC Support.</td><td>[empty]</td></tr><tr><td><code>OIDC_LOGOUT_URL</code></td><td>See OIDC Support.</td><td>[empty]</td></tr><tr><td><code>PRIMARY_OIDC_FIELD</code></td><td>See OIDC Support.</td><td><code>email</code></td></tr><tr><td><code>SECONDARY_OIDC_FIELD</code></td><td>See OIDC Support.</td><td><code>preferred_username</code></td></tr><tr><td><code>PRIMARY_DB_FIELD</code></td><td>See OIDC Support.</td><td><code>email</code></td></tr><tr><td><code>SECONDARY_DB_FIELD</code></td><td>See OIDC Support.</td><td><code>username</code></td></tr><tr><td><code>ENABLE_AUTO_REGISTRATION</code></td><td>See OIDC Support.</td><td><code>false</code></td></tr><tr><td><code>ENABLE_DEFAULT_LOGIN</code></td><td>See OIDC Support.</td><td><code>true</code></td></tr><tr><td><code>LOGIN_PAGE_MESSAGE</code></td><td>Message at the top of the login form.</td><td><code>No account? Contact a family member to create an account!</code></td></tr><tr><td><code>REORDERING</code></td><td>Allows reordering ideas on the my_ideas page.</td><td><code>true</code></td></tr><tr><td><code>IMGENABLED</code></td><td>Allows images in ideas (tries auto-fetch, then asks for a link if it fails).</td><td><code>false</code></td></tr><tr><td><code>CURRENCY_SYMBOL</code></td><td>Symbol for the idea value.</td><td><code>$</code></td></tr><tr><td><code>CURRENCY_POSITION</code></td><td>Symbol position: <code>before</code> or <code>after</code>.</td><td><code>before</code></td></tr><tr><td><code>ENABLE_SELF_REGISTRATION</code></td><td>Lets people register on the login page.</td><td><code>false</code></td></tr><tr><td><code>JOINING_CODE</code></td><td>Needed to self register. Empty means no code is asked.</td><td>[empty]</td></tr><tr><td><code>ENABLE_LINK_SHARING</code></td><td>Lets users share their lists with an external link.</td><td><code>true</code></td></tr><tr><td><code>HIDE_PURCHASER</code></td><td>Controls whether the purchaser is hidden.</td><td><code>user_choice</code></td></tr></tbody></table>

### Docker Gunicorn variables

Can be set at container creation (v2.6.4 and up). Gunicorn also uses files located in the `./data` folder.

| Key                | What it does                                | Default        |
| ------------------ | ------------------------------------------- | -------------- |
| `GUNICORN_THREADS` | Number of worker threads handling requests. | `4`            |
| `GUNICORN_BIND`    | Address and port inside the container.      | `0.0.0.0:5000` |

Example:

```sh
docker run -p 80:80 -e GUNICORN_THREADS=2 -e GUNICORN_BIND=0.0.0.0:80 -e SECRET_KEY=your-private-random-value -v ./data:/app/data icbest/giftmanager
```
