-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/api-docs-gen
- Loading branch information
Showing
31 changed files
with
1,201 additions
and
943 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# This is a Dockerfile for building a container image for the Catalyst Event Database. | ||
# The container image is built from scratch and includes the necessary files for running | ||
# the database and its associated software. | ||
|
||
VERSION 0.7 | ||
|
||
# cspell: words | ||
|
||
# Event db builder target. Prepares all necessary artifacts. | ||
# Arguments: | ||
# * with_historic_data: add historic data from the `historic_data` dir (default `true`). | ||
# * with_test_data: add test data from the `test_data` dir (default `true`). | ||
builder: | ||
FROM github.com/input-output-hk/catalyst-ci/earthly/postgresql:v2.0.7+postgres-base | ||
|
||
ARG with_historic_data=true | ||
ARG with_test_data=true | ||
|
||
WORKDIR /build | ||
|
||
COPY refinery.toml . | ||
COPY --dir migrations . | ||
RUN mkdir data | ||
|
||
IF [ $with_historic_data = true ] | ||
COPY --dir historic_data . | ||
|
||
RUN python3 historic_data/fund_2/mk_fund2_sql.py historic_data/fund_2/fund2_database_encrypted.sqlite3 >> historic_data/fund_2.sql | ||
RUN python3 historic_data/fund_3/mk_fund3_sql.py historic_data/fund_3/fund3_database_encrypted.sqlite3 >> historic_data/fund_3.sql | ||
RUN python3 historic_data/fund_4/mk_fund4_sql.py historic_data/fund_4/fund4_database_encrypted.sqlite3 >> historic_data/fund_4.sql | ||
RUN python3 historic_data/fund_5/mk_fund5_sql.py historic_data/fund_5/fund5_database_encrypted.sqlite3 >> historic_data/fund_5.sql | ||
RUN python3 historic_data/fund_6/mk_fund6_sql.py historic_data/fund_6/fund6_database_encrypted.sqlite3 >> historic_data/fund_6.sql | ||
RUN python3 historic_data/fund_7/mk_fund7_sql.py historic_data/fund_7/fund7_database_encrypted.sqlite3 >> historic_data/fund_7.sql | ||
RUN python3 historic_data/fund_8/mk_fund8_sql.py historic_data/fund_8/fund8_database_encrypted.sqlite3 >> historic_data/fund_8.sql | ||
RUN python3 historic_data/fund_9/mk_fund9_sql.py historic_data/fund_9/fund9_database_encrypted.sqlite3 >> historic_data/fund_9.sql | ||
RUN python3 historic_data/fund_9/mk_fund9_voteplan_sql.py historic_data/fund_9/fund9_database_encrypted.sqlite3 >> historic_data/fund_9.sql | ||
|
||
RUN mv ./historic_data/*.sql ./data | ||
END | ||
|
||
IF [ $with_test_data = true ] | ||
COPY --dir test_data . | ||
|
||
RUN mv ./test_data/*.sql ./data | ||
END | ||
|
||
DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:v2.0.7+BUILDER | ||
|
||
check: | ||
FROM +builder | ||
|
||
DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:v2.0.7+CHECK | ||
|
||
format: | ||
LOCALLY | ||
|
||
DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:v2.0.7+FORMAT --src=$(echo ${PWD}) | ||
|
||
# Build event db docker image. | ||
# Arguments: | ||
# * tag: docker image `tag`. | ||
# * registry: docker image `registry`. | ||
# * with_historic_data: add historic data from the `historic_data` dir (default `true`). | ||
# * with_test_data: add test data from the `test_data` dir (default `true`). | ||
build: | ||
ARG with_historic_data=true | ||
ARG with_test_data=true | ||
ARG tag="latest" | ||
ARG registry | ||
|
||
FROM +builder --with_historic_data=$with_historic_data --with_test_data=$with_test_data | ||
|
||
DO github.com/input-output-hk/catalyst-ci/earthly/postgresql:v2.0.7+BUILD --tag=$tag --registry=$registry --image_name=event-db | ||
|
||
test: | ||
FROM github.com/input-output-hk/catalyst-ci/earthly/postgresql:v2.0.7+postgres-base | ||
|
||
COPY github.com/input-output-hk/catalyst-ci/earthly/utils:v2.0.7+shell-assert/assert.sh . | ||
|
||
COPY ./docker-compose.yml . | ||
WITH DOCKER \ | ||
--compose docker-compose.yml \ | ||
--load event-db:latest=(+build --with_historic_data=false) \ | ||
--service event-db \ | ||
--allow-privileged | ||
RUN sleep 5;\ | ||
res=$(psql postgresql://catalyst-event-dev:CHANGE_ME@0.0.0.0:5432/CatalystEventDev -c "SELECT COUNT(*) FROM event");\ | ||
|
||
source assert.sh;\ | ||
expected=$(printf " count \n-------\n 5\n(1 row)");\ | ||
assert_eq "$expected" "$res" | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,27 @@ | ||
# Catalyst Event Database | ||
|
||
This crate defines the structure and RUST access methods for the Catalyst Event Database. | ||
This crate defines the necessary migrations, seed data and docker image builder for the Catalyst Event Database. | ||
|
||
## Starting a Local Test DB with Docker and Earthly | ||
|
||
Firstly you will need to prepare a docker images with all migrations and data. | ||
|
||
Prepare a event-db docker image with the historic data | ||
(from the root directory) | ||
Prepare a event-db docker image with the historic and test data | ||
|
||
```sh | ||
earthly ./containers/event-db-migrations+docker | ||
``` | ||
|
||
Prepare a event-db docker image with the test data | ||
(from the root directory) | ||
|
||
```sh | ||
earthly ./containers/event-db-migrations+docker --data=test | ||
earthly ./catalyst-gateway/event-db+build --tag "latest" --registry "" --with_historic_data true --with_test_data true | ||
``` | ||
|
||
Run a event db docker container | ||
(from the root directory) | ||
|
||
```sh | ||
docker-compose -f src/event-db/docker-compose.yml up migrations | ||
docker-compose -f catalyst-gateway/event-db/docker-compose.yml up event-db | ||
``` | ||
|
||
This will run postgres on port `5432` | ||
|
||
## GraphQL | ||
This will run postgres on port `5432`. | ||
|
||
GraphQL is ONLY used for the admin interface. | ||
It is configured with the `setup/graphql-setup.sql`. | ||
|
||
For local testing, make sure the local `event-db` is setup and running, as described above. | ||
Then: | ||
To test that docker image builds fine and migrations correctly applies run | ||
|
||
```sh | ||
setup/start-graphql.sh | ||
earthly -P ./catalyst-gateway/event-db+test | ||
``` | ||
|
||
See <https://www.graphile.org/postgraphile/> for documentation on the GraphQL server. | ||
|
||
### GraphQL Users | ||
|
||
There are two GraphQL Users: | ||
|
||
* `cat_admin`: Full admin access to the database. | ||
* `cat_anon`: Unauthenticated read-only access to the database. | ||
|
||
To authenticate, as the `cat_admin` user, execute the `authenticate` mutation. | ||
This will return a Signed JWT Token for the user. | ||
The JWT Token needs to be included as a `bearer` token `Authorization` header in subsequent requests. | ||
Authentication only last 1 Hour, after which a new token must be requested. | ||
|
||
When authenticated as the `cat_admin` user, new `cat_admin` users can be registered with the `registerAdmin` mutation. | ||
|
||
Further Security Roles or Admin management functions can be added as required. | ||
|
||
#### Authentication API | ||
|
||
The GraphQL server exposes 2 **Mutations** that are used for security. | ||
|
||
If the user is NOT authenticated, they can not update any data in the database, only read data. | ||
|
||
To authenticate run the `authenticate` mutation with the email address and password of the user to be authenticated. | ||
If successful, this mutation will return a JWT which will have 1 hr of Life. | ||
Place the returned JWT in an `Authorization: Bearer <JWT>` header for all subsequent calls. | ||
|
||
`currentAcct` query will return the authenticated user's current account details and role. | ||
|
||
To register a new user, the `registerAdmin` mutation can be used. | ||
It will only work if the user is properly authenticated with a `cat_admin` role. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,23 @@ | ||
version: "3" | ||
|
||
services: | ||
postgres: | ||
image: postgres:14 | ||
restart: unless-stopped | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: CatalystEventDev | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] | ||
interval: 2s | ||
timeout: 5s | ||
retries: 10 | ||
ports: | ||
- 5432:5432 | ||
# cspell: words | ||
|
||
migrations: | ||
image: migrations:latest | ||
services: | ||
event-db: | ||
image: event-db:latest | ||
environment: | ||
# Required environment variables for migrations | ||
- DB_HOST=postgres | ||
- DB_HOST=localhost | ||
- DB_PORT=5432 | ||
- DB_NAME=CatalystEventDev | ||
- DB_DESCRIPTION="Catalyst Event DB" | ||
- DB_SUPERUSER=postgres | ||
- DB_SUPERUSER_PASSWORD=postgres | ||
- DB_USER=catalyst-event-dev | ||
- DB_USER_PASSWORD=CHANGE_ME | ||
- ADMIN_ROLE_PASSWORD=CHANGE_ME | ||
- ADMIN_USER_PASSWORD=CHANGE_ME | ||
- ANON_ROLE_PASSWORD=CHANGE_ME | ||
- STAGE=dev | ||
depends_on: | ||
postgres: | ||
condition: service_healthy | ||
|
||
- INIT_AND_DROP_DB=true | ||
- WITH_MIGRATIONS=true | ||
- WITH_SEED_DATA=true | ||
ports: | ||
- 5432:5432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.