An example is often worth a thousand words. This repository is provided as an example of how to leverage Gearshaft to run autonomous components. There is a registration
component which is setup to be run inside a single host
.
- Run a Postgres instance
- Provision a message store database
- Configure the Postgres credentials used by the example
- Run the tests:
npm test
- Run the host:
npm run dev
- Write a test message:
node registration/test/interactive/create-registration.js
Use Docker to run Postgres or install Postgres from scratch. The automated tests expect the following defaults which can be overriden:
- HOST:
localhost
- PORT:
5432
(Postgres default) - USER:
postgres
- PASS:
NInAN5t3kJo8d7I3
You can run Postgres with docker as follows:
docker run --name pg -d -p 5432:5432 -e POSTGRES_PASSWORD=NInAN5t3kJo8d7I3 postgres:10.5
Terminate Postgres and delete all data as follow:
docker rm -fv pg
-
Install the Postgres client (psql)
Ubuntu:
sudo apt install postgresql-client
-
(Re)create the message store database and user credentials
If you are using the default (compromised) credentials, simply run:
npm run recreate
.If you are not using the default credentials, customize these commands as necessary:
-
Create the message_store database:
PGHOST=localhost \ PGUSER=postgres \ PGPASSWORD=NInAN5t3kJo8d7I3 \ ./gems/bin/evt-pg-recreate-db
-
Assign the message_store user a password:
PGHOST=localhost \ PGUSER=postgres \ PGPASSWORD=NInAN5t3kJo8d7I3 \ psql -c "alter role message_store with password 'NInAN5t3kJo8d7I3';"
-
The configuration is managed using the rc module. Create a .gearshaft_examplerc
file in the project root directory with the following fields to customize the Postgres connection settings:
{
"postgres": {
"host": "some-host-name",
"user": "some-pg-user",
"password": "some-pg-pass",
"database": "some-pg-database"
}
}