Skip to content

Update README.md #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,31 @@ luarocks install config-by-env

### source
Clone this repo and run:
```
```bash
luarocks make
```

You will also need to enable this plugin by adding it to the list of enabled plugins using `KONG_PLUGINS` environment variable or the `plugins` key in `kong.conf`

```bash
export KONG_PLUGINS=config-by-env

```
OR

```bash
plugins=config-by-env
```


This plugin requires `KONG_ENV` environment variable to be set in nginx. To do that check this [article](https://discuss.konghq.com/t/set-multiple-env-nginx-directives/7532). A command like below should work and help you set environment variable in Nginx.

```
```bash
export KONG_ENV=production && export KONG_NGINX_MAIN_ENV=KONG_ENV && kong start
```


## How does it work?
1. Let us assume following config is stored in schema.
**Note**: *default | staging | production* are possible values of `KONG_ENV` environment variable.
```
```json
{
"default": {
"redis": {
Expand All @@ -68,7 +69,7 @@ export KONG_ENV=production && export KONG_NGINX_MAIN_ENV=KONG_ENV && kong start
```
2. When an nginx worker starts, this plugin reads plugin's config from DB and caches it in memory.
3. Uses plugin's config extracted in step 2 to merges environment specific config with the `default` config. When `KONG_ENV=staging`, config after merging with `default` config will be:
```
```json
{
"redis": {
"host": "http://redis%TEAM_NAME%.dream11-staging.local",
Expand All @@ -78,7 +79,7 @@ export KONG_ENV=production && export KONG_NGINX_MAIN_ENV=KONG_ENV && kong start
}
```
4. Let's say we set environment variable `TEAM_NAME=user-profile`, then config after interpolating environment variables will be:
```
```json
{
"redis": {
"host": "http://redis-user-profile.dream11-staging.local",
Expand All @@ -88,7 +89,7 @@ export KONG_ENV=production && export KONG_NGINX_MAIN_ENV=KONG_ENV && kong start
}
```
5. The final config from step 4 will be saved as a Lua table in L1 and L2 cache using [lua-resty-mlcache](https://github.com/thibaultcha/lua-resty-mlcache) library. This config will also be set in request context for other plugins to access this config.
```
```lua
local config_by_env = kong.ctx.shared.config_by_env
local redis_host = config_by_env["redis"]["host"]
```
Expand Down