Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Use .env instead of local.js and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pantsel authored and Panagis Tselentis committed Aug 21, 2018
1 parent 031aa05 commit cac450d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 65 deletions.
7 changes: 7 additions & 0 deletions .env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
PORT=1337
NODE_ENV=production
KONGA_HOOK_TIMEOUT=120000
DB_ADAPTER=postgres
DB_URI=postgresql://localhost:5432/konga
KONGA_LOG_LEVEL=warn
TOKEN_SECRET=some_secret_token
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ nbproject
/www/
/kongadata/
/certs/
/.env
.env
112 changes: 49 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ _Konga is not an official app. No affiliation with [Kong](https://www.konghq.com
- [**Used libraries**](#used-libraries)
- [**Installation**](#installation)
- [**Configuration**](#configuration)
- [**Environment variables**](#environment-variables)
- [**Running Konga**](#running-konga)
- [**Upgrading**](#upgrading)
- [**FAQ**](#faq)
Expand Down Expand Up @@ -51,23 +52,22 @@ It also works with Kong 0.13.* yet without the ability to manage services and ro

## Prerequisites
- A running [Kong installation](https://getkong.org/)
- Nodejs >= 8.11.3
- Nodejs >= 8 (8.11.3 LTS is recommended)
- Npm

## Used libraries
* Sails.js, http://sailsjs.org/
* AngularJS, https://angularjs.org/
* Bootstrap, http://getbootstrap.com/

## Installation

Install `npm` and `node.js`. Instructions can be found [here](http://sailsjs.org/#/getStarted?q=what-os-do-i-need).

Install `bower`, `gulp` and `sails` packages.
Install `bower`, ad `gulp` packages.
```
$ git clone https://github.com/pantsel/konga.git
$ cd konga
$ npm install
$ npm i
```

## Configuration
Expand All @@ -77,11 +77,33 @@ settings.
There is an example configuration file on following path.

```
config/local_example.js
.env_example
```

Just copy this to `config/local.js` and make necessary changes to it. Note that this
`local.js` file is in .gitignore so it won't go to VCS at any point.
Just copy this to `.env` and make necessary changes to it. Note that this
`.env` file is in .gitignore so it won't go to VCS at any point.

## Environment variables
These are the general environment variables Konga uses.

| VAR | DESCRIPTION | VALUES | DEFAULT |
|--------------------|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------|----------------------------------------------|
| PORT | The port that will be used by Konga's server | - | 1337 |
| NODE_ENV | The environment | `production`,`development` | `development` |
| SSL_KEY_PATH | If you want to use SSL, this will be the absolute path to the .key file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
| SSL_CRT_PATH | If you want to use SSL, this will be the absolute path to the .crt file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
| KONGA_HOOK_TIMEOUT | The time in ms that Konga will wait for startup tasks to finish before exiting the process. | - | 60000 |
| DB_ADAPTER | The database that Konga will use. If not set, the localDisk db will be used. | `mongo`,`mysql`,`postgres`,`sqlserver` | - |
| DB_URI | The full db connection string. Depends on `DB_ADAPTER`. If this is set, no other DB related var is needed. | - | - |
| DB_HOST | If `DB_URI` is not specified, this is the database host. Depends on `DB_ADAPTER`. | - | localhost |
| DB_PORT | If `DB_URI` is not specified, this is the database port. Depends on `DB_ADAPTER`. | - | DB default. |
| DB_USER | If `DB_URI` is not specified, this is the database user. Depends on `DB_ADAPTER`. | - | - |
| DB_PASSWORD | If `DB_URI` is not specified, this is the database user's password. Depends on `DB_ADAPTER`. | - | - |
| DB_DATABASE | If `DB_URI` is not specified, this is the name of Konga's db. Depends on `DB_ADAPTER`. | - | `konga_database` |
| DB_PG_SCHEMA | If using postgres as a database, this is the schema that will be used. | - | `public` |
| KONGA_LOG_LEVEL | The logging level | `silly`,`debug`,`info`,`warn`,`error` | `debug` on dev environment & `warn` on prod. |
| TOKEN_SECRET | The secret that will be used to sign JWT tokens issued by Konga | - | - |


### Databases Integration

Expand All @@ -94,45 +116,42 @@ The application also supports some of the most popular databases out of the box:
1. MySQL
2. MongoDB
3. PostgresSQL
4. SQL Server

In order to use them, in your `/config/local.js` replace
```
models: {
connection: process.env.DB_ADAPTER || 'localDiskDb',
}
```
with
In order to use them, set the appropriate env vars in your `.env` file.


## Running Konga

### Development
```
models: {
connection: process.env.DB_ADAPTER || 'the-name-of-adapter-you-wish-to-use', // 'mysql', 'mongo', 'sqlserver' or 'postgres'
}
$ npm start
```
Konga GUI will be available at `http://localhost:1337`

See [Sails adapters](http://sailsjs.com/documentation/concepts/extending-sails/adapters/available-adapters) for further configuration
### Production

*****************************************************************************************
##### Note :
In case of `MySQL`, `PostgresSQL` or `SQL Server` adapters,
you will need to prepare the database as explained on the next topic.
In case of `MySQL` or `PostgresSQL` adapters, Konga will not perform db migrations when running in production mode.

*****************************************************************************************
You can manually perform the migrations by calling ```$ node ./bin/konga.js prepare```
, passing the args needed for the database connectivity.

## Running Konga
For example:

### Development
```
$ npm start
$ node ./bin/konga.js prepare --adapter postgres --uri postgresql://localhost:5432/konga
```
Konga GUI will be available at `http://localhost:1337`
The process will exit after all migrations are completed.

### Production
*****************************************************************************************

Finally:
```
$ npm run production
```
Konga GUI will be available at `http://localhost:1337`


### Production Docker Image

The following instructions assume that you have a running Kong instance following the
Expand All @@ -152,20 +171,7 @@ $ docker run -p 1337:1337 \
1. ##### Prepare the database
> **Note**: You can skip this step if using the `mongo` adapter.
Konga will not perform db migrations when running in production mode.

You can manually perform the migrations by calling ```$ node ./bin/konga.js prepare```
, passing the args needed for the database connectivity.

The available adapters are ```'postgres', or 'mysql'```

```
$ node ./bin/konga.js prepare --adapter {adapter_name} --uri {full_connection_string}
```
The process will exit after all migrations are completed.

If you're deploying Konga via the docker image, you can prepare the database using
an ephemeral container running the prepare command.
You can prepare the database using an ephemeral container that runs the prepare command.

**Args**

Expand All @@ -174,10 +180,9 @@ argument | description | default
-c | command | -
-a | adapter (can be `postgres` or `mysql`) | -
-u | full database connection url | -
-p | port | `1339`

```
$ docker run --rm pantsel/konga:next -c prepare -a {{adapter}} -u {{connection-uri}} -p {{port}}
$ docker run --rm pantsel/konga:next -c prepare -a {{adapter}} -u {{connection-uri}}
```


Expand Down Expand Up @@ -224,26 +229,7 @@ This user data is populated to the database if there is not already any user dat

You may also configure Konga to authenticate via [LDAP](./docs/LDAP.md).

## Environment variables
These are the general environment variables Konga uses.

| VAR | DESCRIPTION | VALUES | DEFAULT |
|--------------------|----------------------------------------------------------------------------------------------------------------------------|----------------------------------------|----------------------------------------------|
| PORT | The port that will be used by Konga's server | - | 1337 |
| NODE_ENV | The environment | `production`,`development` | `development` |
| SSL_KEY_PATH | If you want to use SSL, this will be the absolute path to the .key file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
| SSL_CRT_PATH | If you want to use SSL, this will be the absolute path to the .crt file. Both `SSL_KEY_PATH` & `SSL_CRT_PATH` must be set. | - | null |
| KONGA_HOOK_TIMEOUT | The time in ms that Konga will wait for startup tasks to finish before exiting the process. | - | 60000 |
| DB_ADAPTER | The database that Konga will use. If not set, the localDisk db will be used. | `mongo`,`mysql`,`postgres`,`sqlserver` | - |
| DB_URI | The full db connection string. Depends on `DB_ADAPTER`. If this is set, no other DB related var is needed. | - | - |
| DB_HOST | If `DB_URI` is not specified, this is the database host. Depends on `DB_ADAPTER`. | - | localhost |
| DB_PORT | If `DB_URI` is not specified, this is the database port. Depends on `DB_ADAPTER`. | - | DB default. |
| DB_USER | If `DB_URI` is not specified, this is the database user. Depends on `DB_ADAPTER`. | - | - |
| DB_PASSWORD | If `DB_URI` is not specified, this is the database user's password. Depends on `DB_ADAPTER`. | - | - |
| DB_DATABASE | If `DB_URI` is not specified, this is the name of Konga's db. Depends on `DB_ADAPTER`. | - | `konga_database` |
| DB_PG_SCHEMA | If using postgres as a database, this is the schema that will be used. | - | `public` |
| KONGA_LOG_LEVEL | The logging level | `silly`,`debug`,`info`,`warn`,`error` | `debug` on dev environment & `warn` on prod. |
| TOKEN_SECRET | The secret that will be used to sign JWT tokens issued by Konga | - | - |
## Upgrading
In some cases a newer version of Konga may introduce new db tables, collections or changes in schemas.
The only thing you need to do is to start Konga in dev mode once so that the migrations will be applied.
Expand Down
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* The same command-line arguments are supported, e.g.:
* `node app.js --silent --port=80 --prod`
*/

require('dotenv').config()

// Ensure a "sails" can be located:
let sails;
Expand Down
1 change: 1 addition & 0 deletions bin/konga.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node bin
require('dotenv').config()
var argv = require('minimist')(process.argv.slice(2));
var child_process = require('child_process');
var spawn = child_process.spawn
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"bcryptjs": "2.3.0",
"bluebird": "3.0.5",
"bower": "^1.8.4",
"dotenv": "^6.0.0",
"ejs": "^2.6.1",
"grunt": "^1.0.3",
"grunt-contrib-clean": "^1.1.0",
Expand Down

0 comments on commit cac450d

Please sign in to comment.