Skip to content

Commit

Permalink
Add dotenv config (#51)
Browse files Browse the repository at this point in the history
* Add dotenv for easier configuration on bare host

* fix changelog

* typo fix
  • Loading branch information
tot-ra authored Oct 25, 2021
1 parent 315860a commit 7e8b611
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 27 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ node_modules/
.atom-build.json
.project
coverage
dist
dist

# Config
.env
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.0] - 2021-10-25

### Updated

- Added dotenv and ability to set configuration vars in .env file

## [2.0.1] - 2021-10-25

### Updated

- Security update elliptic from 6.5.3 to 6.5.4

## [2.0.0] - 2021-10-01
Expand Down Expand Up @@ -159,7 +167,8 @@ DELETE /schema/:schemaId
- Frontend app
- Examples of gateway + 2 federated services

[unreleased]: https://github.com/pipedrive/graphql-schema-registry/compare/v2.0.1...HEAD
[unreleased]: https://github.com/pipedrive/graphql-schema-registry/compare/v2.1.0...HEAD
[2.1.0]: https://github.com/pipedrive/graphql-schema-registry/compare/v2.0.1...v2.1.0
[2.0.1]: https://github.com/pipedrive/graphql-schema-registry/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/pipedrive/graphql-schema-registry/compare/v1.2.5...v2.0.0
[1.2.5]: https://github.com/pipedrive/graphql-schema-registry/compare/v1.2.4...v1.2.5
Expand Down
71 changes: 47 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,60 @@ Graphql schema storage as dockerized on-premise service for federated graphql ga
- separate ephemeral automatic PQs, registered by frontend (use cache only with TTL) from true PQs backend-registered persisted queries (use DB only)
- async schema registration of new schema with events to avoid polling. `schema-registry -> kafka -> gateway`

## Configuration

We use environment variables for configuration.
You can:

- pass them directly
- add .env file and dotenv will pick them up
- add them to `docker-compose.yml` or `Dockerfile`

The following are the different environment variables that are looked up that allow configuring the schema registry in different ways.

| Variable Name | Description | Default |
| --------------------- | ----------------------------------------------------------------------------- | ------------------------- |
| DB_HOST | Host name of the MySQL server | gql-schema-registry-db |
| DB_USERNAME | Username to connect to MySQL | root |
| DB_SECRET | Password used to connect to MySQL | root |
| DB_PORT | Port used when connecting to MySQL | 3306 |
| DB_NAME | Name of the MySQL database to connect to | schema-registry |
| DB_EXECUTE_MIGRATIONS | Controls whether DB migrations are executed upon registry startup or not | true |
| REDIS_HOST | Host name of the Redis server | gql-schema-registry-redis |
| REDIS_PORT | Port used when connecting to Redis | 6379 |
| REDIS_SECRET | Password used to connect to Redis | Empty |
| ASSETS_URL | Controls the url that web assets are served from | localhost:6001 |
| NODE_ENV | Specifies the environment. Use _production_ to load js/css from `dist/assets` | Empty |

For development we rely on docker network and use hostnames from `docker-compose.yml`.
For dynamic service discovery, see `app/config.js`. Node service uses to connect to mysql & redis and change it if you install it with own setup. If you use dynamic service discovery (consul/etcd), edit `diplomat.js`

## Installation

We have [docker image published](https://hub.docker.com/r/pipedrive/graphql-schema-registry) for main node service.
With default settings, UI should be accessible at [http://localhost:6001](http://localhost:6001)

### On bare host

```
docker-compose up
git clone https://github.com/pipedrive/graphql-schema-registry.git && cd graphql-schema-registry
cp example.env .env && nano .env
node schema-registry.js
```

UI should be now at [http://localhost:6001](http://localhost:6001)
### Docker image

## Configuration
We have [docker image published](https://hub.docker.com/r/pipedrive/graphql-schema-registry) for main node service.

We rely on docker network and uses hostnames from `docker-compose.yml`.
Check `app/config.js` to see credentials that node service uses to connect to mysql & redis and change it if you install it with own setup. If you use dynamic service discovery (consul/etcd), edit `diplomat.js`
```
docker run -e DB_HOST=localhost -e DB_USERNAME=root pipedrive/graphql-schema-registry
```

The following are the different environment variables that are looked up that allow configuring the schema registry in different ways.
### Docker-compose

| Variable Name | Description | Default |
| --------------------- | -------------------------------------------------------------------------- | ------------------------- |
| DB_HOST | Host name of the MySQL server | gql-schema-registry-db |
| DB_USERNAME | Username to connect to MySQL | root |
| DB_SECRET | Password used to connect to MySQL | root |
| DB_PORT | Port used when connecting to MySQL | 3306 |
| DB_NAME | Name of the MySQL database to connect to | schema-registry |
| DB_EXECUTE_MIGRATIONS | Controls whether DB migrations are executed upon registry startup or not | true |
| REDIS_HOST | Host name of the Redis server | gql-schema-registry-redis |
| REDIS_PORT | Port used when connecting to Redis | 6379 |
| REDIS_SECRET | Password used to connect to Redis | Empty |
| ASSETS_URL | Controls the url that web assets are served from | localhost:6001 |
| NODE_ENV | Specifies the environment. Use _production_ for production like deployment | Empty |

**Note** about `NODE_ENV`: setting the `NODE_ENV` environment variable to _production_ will tell the registry
to serve web assets (js, css) from their compiled versions in the `dist/assets` directory.
```
git clone https://github.com/pipedrive/graphql-schema-registry.git && cd graphql-schema-registry
docker-compose up
```

## Use cases

Expand All @@ -75,9 +96,11 @@ On service start-up (runtime), make POST to /schema/push to register schema (see
Make sure to handle failure.

### Schema migration

If service A contains schema that needs to be migrated to service B, we need to orchestrate schema & traffic change.
Instead of juggling with schema status flags, we suggest the following scenario:
- service B gets deployed with new schema which includes cycle of attempts to register new schema (for example every 5 sec).

- service B gets deployed with new schema which includes cycle of attempts to register new schema (for example every 5 sec).
- schema-registry responds with validation errors
- service A without conflicting schema gets deployed & updates schema-registry
- service B manages to register new schema & stops the cycle
Expand Down
7 changes: 7 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB_HOST=gql-schema-registry-db
DB_USERNAME=root
DB_SECRET=root
DB_PORT=3306
DB_NAME=schema-registry
ASSETS_URL=http://localhost:6001
NODE_ENV=production
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 @@ -44,6 +44,7 @@
"body-parser": "^1.19.0",
"dataloader": "^2.0.0",
"date-fns": "^2.9.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"graphql": "^15.4.0",
"graphql-voyager": "^1.0.0-rc.31",
Expand Down
1 change: 1 addition & 0 deletions schema-registry.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config();
const logger = require('./app/logger');
const CustomSqlMigrationSource = require('./app/database/sql-migration-source');

Expand Down

0 comments on commit 7e8b611

Please sign in to comment.