-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(README): update the README for new setup
- Loading branch information
Showing
5 changed files
with
66 additions
and
117 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 |
---|---|---|
|
@@ -6,14 +6,14 @@ PG_USER=postgres | |
PG_PASSWORD=marble | ||
|
||
AUTHENTICATION_JWT_SIGNING_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAs+6r50m7qqLHHy7CvfmJPnAi+t/tubi7DPSM2jvA1etT1jEX\nrwbFbmooOu9LTgmjmxOq01p+XwkW1f7iPZViKrf7dEDEuqmpqYG9jPX4G/7xFcci\nGn1iSOiNx9awIKSYZa1wodlMCRM081DGqFNDMf1PScWIyM40nIwaGqLZht4HcOAq\nLbKDa15bxubBqZ9o/YnE1KmyBfq1tTnk0KzAb12Axt0xN4qB2zktsV/LLds+szMk\n/gRHjann1+fCZvxw1JzzRPtgeHLLYzn4ks3mwzy67RO3q/663KPZCsuYhlNCsMqp\n/HAbrF5PaihqzCZqLTDoIXXciCFFgwtLwm951wIDAQABAoIBAQCpb60tJX+1VYeQ\n06XK43rb8xjdiZUA+PYbYwZoUzBpwSq3Xo9g4E12hjzQEpqlJ+qKk+CfGm457AM3\nDMfbGhrRA2Oku4EGDdKYrnXikZVMN6yqx1RUAZJV+bfZYU+Fzbk8tjCEGG3DdfS8\n02nfBFkYb+MEIyGFhriAWmYSgxu4JTN0XRTyPqBytoSLqVCFbv0/yV2oJQDaXW08\nWAA8JtWhzqxACbFnPYe0hYUnrCA71t0v1P/N5uB4kKxI0tulGtW84noSyWA2LSdn\nJlKQW5WsyeMulGBMnIpj/OQJtQErupoITsh1TNi+6ffGgmuMCT1za70DHXVq9Ihu\nkpKBe0wRAoGBAOSarLfNvsS2lTH/8zPyhWBddCS5CfQAeUFLD5xWhQ7/6SenYzYY\n+oiiH2uL7d8grkobX5QLVvJ5ZXziYWoKgJe3SlrvRuNJZCAxvuynUCahhCT+chwW\nGz7ihXh3bGD0gtO6iogGBfrAkvRQnorkdSmVEZd1PsJV/lXp8LKgxJ91AoGBAMl+\ny/6NbzVHt9oQsrVrG/sCAOlqlfTt5KW6pI1WC4LoKBaGe+hy4emZ0G/M2feAJEPR\n92QrPRkVF5bVCjalJj42/7gQIl6r+DQ4+08gLB1MSpWua2M3UtEi/2gsMcQff/wg\n6kmNZObW5Jcnqpp6u72zQTQwF4H29XucV/Yw93abAoGADGvfIKmcSQIGv03CADuY\nRbEuQ2SOhuSTshmLApqs5jC/kXkF6gWXb18nx+c1iJ80+S/dlKS9F7XC7vM6CdIC\nRLwf3SsNNgJh32H0ltVMhJzYGk59EsuctWEHkZEjoW0HwstrBZMWNhbKpV3QD4n0\nV8sSxqEHRPX5ON/aRUp5BJUCgYEAlsymr2P6js2V80X7+Xqn/juJoyd6A0znioEd\nFgoHo3lMR09u/JC+Mq5DKOkPWAQ3H+rMU9NobpUyilf2xN7kuDtBNugcUO4zXCIp\nMxbI7URjrZJUHHUTLiIbNEOfG0DX8EJSFaoUkg7SFa5CKEsipt65Ne2oKkRBhLmF\nu2L6UXECgYBH1bpi0R6j7lIADtZtIJII/TezQbp+VK2R9qoNgkTnHoDjkRVR7v3m\n75wReMvTy1h0Qx/ROtStZz8d5uQuhdeJvbQPQR8KGFUFZDmVWxU+y15WI2H39FMA\nMireKxzCfGGtTsZnhDqYl9NuRPcAGYt5jvoERXlz7b69rkqQUrfy+Q==\n-----END RSA PRIVATE KEY-----" | ||
GCS_INGESTION_BUCKET="data-ingestion-tokyo-country-381508" | ||
GCS_CASE_MANAGER_BUCKET="case-manager-tokyo-country-381508" | ||
GCS_INGESTION_BUCKET="data-ingestion-bucket" | ||
GCS_CASE_MANAGER_BUCKET="case-manager-bucket" | ||
|
||
# The frontend sign | ||
FIREBASE_AUTH_EMULATOR_HOST="localhost:9099" | ||
|
||
# When using firebase emulator, JWT Token are issued for the audience 'tokyo-country-381508' which is the staging project. | ||
GOOGLE_CLOUD_PROJECT="tokyo-country-381508" | ||
# When using firebase emulator, JWT Token are issued for this audience | ||
GOOGLE_CLOUD_PROJECT="fake-project-id" | ||
|
||
MARBLE_ADMIN_EMAIL=[email protected] | ||
|
||
|
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,24 +1 @@ | ||
{ | ||
"projects": { | ||
"default": "tokyo-country-381508", | ||
"staging": "tokyo-country-381508", | ||
"production": "marble-prod-1" | ||
}, | ||
"targets": { | ||
"tokyo-country-381508": { | ||
"hosting": { | ||
"backoffice": [ | ||
"marble-backoffice-staging" | ||
] | ||
} | ||
}, | ||
"marble-prod-1": { | ||
"hosting": { | ||
"backoffice": [ | ||
"marble-backoffice-production" | ||
] | ||
} | ||
} | ||
}, | ||
"etags": {} | ||
} | ||
{} |
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
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 |
---|---|---|
|
@@ -7,85 +7,92 @@ This repo is the Marble backend implementation: | |
|
||
## Getting Started | ||
|
||
### Requirements | ||
### Setup your environment | ||
|
||
[Install Go](https://go.dev/doc/install) on your laptop (see the version in go.mod). | ||
|
||
> NB: To handle different versions, you can look at [Managing Go installations](https://go.dev/doc/manage-install) or use a version manager tool like [asdf](https://github.com/kennyp/asdf-golang) | ||
You may also need to [install the gcloud CLI](https://cloud.google.com/sdk/docs/install) in order to interact with deployed environments. | ||
Create you own `.env` file based on `.env.example`. You can fill it with your own values but it should work locally with the default values (except for third-party services functionalities). | ||
|
||
> NB: the staging GCP project is `tokyo-country-381508`- you may need to access it to test some features that depend on cloud infrastructure (you may need to ask for permissions). | ||
#### Setup the DB | ||
|
||
Launch the postgres DB used by the backend: | ||
|
||
### Deployment | ||
```sh | ||
docker compose up -d | ||
``` | ||
|
||
#### Prerequisites | ||
> NB: it creates a `marble-backend_postgres-db` volume to store PG data. | ||
Install firebase-tools (`npm install -g firebase-tools`) | ||
#### Firebase emulator suite for local development | ||
|
||
Install the [Firebase tools](https://firebase.google.com/docs/emulator-suite): | ||
|
||
```sh | ||
firebase login | ||
firebase init | ||
curl -sL firebase.tools | bash | ||
``` | ||
|
||
### Firebase emulator suite for local development | ||
Then start it using (replace `GOOGLE_CLOUD_PROJECT` with the value from your `.env` file): | ||
|
||
[Install the emulator suite](https://firebase.google.com/docs/emulator-suite) | ||
```sh | ||
firebase --project GOOGLE_CLOUD_PROJECT emulators:start --import=./firebase-local-data | ||
``` | ||
|
||
Then start it using: | ||
> NB: The `--import` flag is used to import the local data into the emulator. | ||
### Launch the project | ||
|
||
Export your `.env` file and run the root of the project: | ||
|
||
```sh | ||
firebase --project staging emulators:start --import=./firebase-local-data | ||
go run . --migrations --server | ||
``` | ||
|
||
Connect in the backoffice using: `[email protected]` (marble admin user created by default) | ||
Connect in the frontend using: `[email protected]` (admin of an organization created by default) | ||
> Using VSCode, you can also run the `Migrate and Launch (.env)` task in the "Run and debug" tab. This will load your env file, migrate the DB and start the server. | ||
#### How to add data to ./firebase-local-data | ||
## Application flags | ||
|
||
- Run firebase emulator with paramater: `--export-on-exit` | ||
`firebase --project staging emulators:start --import=./firebase-local-data --export-on-exit` | ||
- Add user, change options... | ||
- Exit the emulator | ||
- commit | ||
The application can be run with the following flags: | ||
|
||
### Lauch the project | ||
- `--migrations`: run the migrations | ||
- `--server`: run the server | ||
- in development, it also runs the `SeedZorgOrganization` usecase script from `usecases/seed_usecase` | ||
- `--scheduler`: run the scenario scheduling job | ||
- `--scheduled-executer`: execute scheduled scenario job | ||
- `--data-ingestion`: run data ingestion job | ||
|
||
#### Setup the DB | ||
> NB: `.vscode/launch.json` contains the configuration to run the app with these flags. | ||
You should first start the local DB to run the backend server: | ||
## API | ||
|
||
`docker compose up -d` : launch the postgres DB used by the backend. | ||
Creates a `marble-backend_postgres-db` volume to store PG data. | ||
The rooting of the application is defined inside `api/routes.go`. | ||
|
||
`docker volume rm marble-backend_postgres-db` deletes the PG volume, useful to reset the app to a known state | ||
For further information on the API, you can also refer to the following resources: | ||
|
||
In practice, this single-line will delete the stack and create a new one: | ||
`docker compose down && docker volume rm marble-backend_postgres-db && docker compose up -d` | ||
- [our API docs](https://docs.checkmarble.com/reference/introduction-1) for public facing reference | ||
- the Open API Specification defined in the frontend repository [here](https://github.com/checkmarble/marble-frontend/blob/main/packages/marble-api/scripts/openapi.yaml). | ||
|
||
#### Local (VS Code) | ||
## DB Seed and migrations | ||
|
||
The recommended way to run the backend is to run `Migrate and Launch (.env.local)` in the VSCode "Run and debug" tab (especially usefull to dev, as the task launch a debugger): | ||
The application uses [goose](https://github.com/pressly/goose) to manage migrations. | ||
|
||
- Start a DB using docker compose | ||
- Lauch the debug task `Migrate and Launch (.env.local)` (VS Code) that will migrate the DB and start the server. | ||
- Three other debug tasks exist that execute the actions running as batches on the cloud: batch data ingestion, scheduling of scenarios, execution of scheduled scenarios. | ||
Migrations are located in the `repositories/migrations` folder. | ||
|
||
You can also run the go service directly in the terminal. | ||
Execute the program with flags `-migrations` to run migrations | ||
|
||
- Create your local `.env` using the provided `.env.local`. | ||
- To create a `AUTHENTICATION_JWT_SIGNING_KEY` run `openssl genrsa -out signing.pem 2048` and save the value as a one liner using `\n` for line breaks, or take the one from `.env.local` - you may need to work out how to export multi-line env variables. | ||
- export your `.env` file | ||
- run `go run .` from the root folder | ||
## FAQ | ||
|
||
### DB Seed and migrations | ||
### How to update firebase local data ? | ||
|
||
- execute the program with flags -migrations to run migrations, -server to start the server | ||
- in development environment, -server additionally runs the SeedZorgOrganization usecase script from usecases/seed_usecase. | ||
- in the cloud staging environment, a dedicated Cloud Run jobs exists that runs the migrations on every new deployment | ||
- Run firebase emulator with paramater: `--export-on-exit` | ||
- Add user, change options... | ||
- Exit the emulator | ||
- commit | ||
|
||
## API | ||
### How to reset the DB ? | ||
|
||
The rooting of the application is defined inside `api/routes.go` | ||
`docker volume rm marble-backend_postgres-db` deletes the PG volume, useful to reset the app to a known state | ||
|
||
See [our API docs](https://docs.checkmarble.com/reference/introduction-1) for public facing reference or the Open API Specification for internal endpoints on Postman. | ||
In practice, this single-line will delete the stack and create a new one: | ||
`docker compose down && docker volume rm marble-backend_postgres-db && docker compose up -d` |
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