Skip to content

Commit

Permalink
Merge pull request #1485 from rodekruis/chore.onboarding-setup-improv…
Browse files Browse the repository at this point in the history
…ement

AB#26410 Make port ibf service port configurable locally and update setup Readme
  • Loading branch information
jannisvisser authored Mar 12, 2024
2 parents c8d512e + 731de25 commit ac8b4c0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 59 deletions.
80 changes: 29 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,92 +37,70 @@ This is the repository for the IBF-system. It includes a.o.:

![IBF-system design (draft)](./system-design/ibf-system-design.PNG)

## Installation
## Getting Started

1. Clone the repository

2. Setup env variables:

`cp example.env .env`

Fill in the .env variables with someone who has them.

3. Run `npm install` from the [API-service folder](./services/API-service)

4. Run `npm install` from the [IBF-dashboard folder](./interfaces/IBF-dashboard)

5. (Only if connecting local setup to remote database): Whitelist your machine IP at the database server
### Setup a local development-environment:

### Using npm commands
- Install Git: <https://git-scm.com/download/>
- Install Node.js: <https://nodejs.org/en/download/>

From root run

- npm run start:services
- npm run start:interface

### Using Docker
- Install the version specified in the [`.node-version`](.node-version)-file.
- To prevent conflicts between projects or components using other versions of Node.js it is recommended to use a 'version manager'.

```
docker compose -f docker-compose.yml up -d # for production
- [NVM - Node Version Manager](http://nvm.sh/) (for macOS/Linux).

docker compose up -d # for development (NOTE: this does not start the ibf-dashboard)
- [NVM for Windows](https://github.com/coreybutler/nvm-windows) (for Windows)

docker compose -f docker-compose.yml -f docker-compose.override.yml up -d # for development (same as previous line)
- [FNM](https://nodejs.org/en/download/package-manager/#fnm) (for Windows/macOS/Linux)

```
### Installation

### Without Docker (for local development)
1. Clone the repository

For local development you can also run and start the services and interface
without docker:
2. Setup env variables:

For API-service
`cp example.env .env`

- `cp .env services/API-service/.env`
- `cd services/API-service`
- `npm run start:dev`
Fill in the .env variables with someone who has them.

For IBF-dashboard
3. Run `npm run install:interface`

- `cd interfaces/IBF-dashboard`
- `npm start`
### Start apps

Suggestion: load everything through Docker, except IBF-dashboard. This has the benefit that changes in front-end code are immediately reflected, instead of having to rebuild.
From root run

- `docker compose up -d`
- `cd interfaces/IBF-dashboard`
- `npm start`
- `npm run start:services`
- `npm run start:interface`

### Load (local) database with data

When running Docker locally, a database-container will start (as opposed to remote servers, which
are connected to a database-server). For setting up a fully working version of the IBF-dasbhoard 2 steps are needed.

1. Seed database with initial static data

- `docker compose exec ibf-api-service npm run seed`

2. Load initial raster data
1. Load initial raster data

- Get the file `raster-files.zip` from [this folder](https://rodekruis.sharepoint.com/sites/510-CRAVK-510/Gedeelde%20%20documenten/Forms/AllItems.aspx?id=%2Fsites%2F510%2DCRAVK%2D510%2FGedeelde%20%20documenten%2F%5BRD%5D%20Impact%2Dbased%20forecasting%2FGeneral%5FData%2FProduction%20Data&p=true&originalPath=aHR0cHM6Ly9yb2Rla3J1aXMuc2hhcmVwb2ludC5jb20vc2l0ZXMvNTEwLUNSQVZLLTUxMC9fbGF5b3V0cy8xNS9ndWVzdGFjY2Vzcy5hc3B4P2ZvbGRlcmlkPTBmYTQ1NGU2ZGMwMDI0ZGJkYmE3YTE3ODY1NWJkYzIxNiZhdXRoa2V5PUFjcWhNODVKSFpZOGNjNkg3QlRLZ08wJmV4cGlyYXRpb249MjAyMS0xMS0yOVQyMyUzYTAwJTNhMDAuMDAwWiZydGltZT1zekJQVnJfSjJFZw).
- Unzip it in `services/API-service/geoserver-volume/raster-files` folder, such that that folder now has subfolders:
- `input`-folder: static raster files that are served through 'geoserver' to the 'IBF-dashboard'
- `mock-output`-foldermock output raster files that are used by the mock-endpoint (see below)
- `output`-folder: currently empty, but any raster files that are posted to the API-service by IBF-pipelines (or mock endpoint) will be stored here, and Geoserver will be able to read them from here.

3. Post 1st batch of dynamic data to database
2. Post static data and 1st batch of dynamic data to database

- login http://localhost:4000/docs#/--%20user%20--/UserController_login (click Try it out, fill in your username and password, and click Execute)
- Copy the resulting `user.token` of that api call
- Paste it to the Authorize button button at the top of that page
- by calling mock-endpoint
- see API documentation: http://localhost:3000/docs/#/scripts
- run for all countries and disaster-type at once: http://localhost:3000/docs/#/scripts/ScriptsController_mockAll
- or run for 1 country and 1 disaster-type: http://localhost:3000/docs/#/scripts/ScriptsController_mockDynamic
- see API documentation: http://localhost:4000/docs/#/scripts
- run for all countries and disaster-type at once: http://localhost:4000/docs/#/scripts/ScriptsController_mockAll
- or run for 1 country and 1 disaster-type: http://localhost:4000/docs/#/scripts/ScriptsController_mockDynamic
- or by having external pipeline make a call to IBF-system

### Installation result

These commands will install the IBF-system with listeners at,

1. [localhost:3000/docs](http://localhost:3000/docs) for the API-service documentation
1. [localhost:4000/docs](http://localhost:4000/docs) for the API-service documentation
2. \*development only - [localhost:4200](http://localhost:4200) for the web
interface

Expand All @@ -133,7 +111,7 @@ Please read the troubleshoot guidlelines to support the insatllation of IBF in t

## Integration tests

### Cypress
### Cypress (THE USE OF CYPRESS IS DEPRECATED FOR IBF)

We use Cypress for automated integration testing in this project.
Installation:
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ version: '3.8'

services:
ibf-api-service:
command: ['npm', 'run', 'start:dev']
command: [ 'npm', 'run', 'start:dev' ]
environment:
- NODE_ENV=development
- LOCAL_PORT_IBF_SERVICE=${LOCAL_PORT_IBF_SERVICE}
ports:
- 3000:3000
- ${LOCAL_PORT_IBF_SERVICE}:3000
depends_on:
- ibf-local-db
networks:
- web-server-network
- api-network

ibf-dashboard:
entrypoint: ['echo', 'Service ibf-dashboard disabled']
entrypoint: [ 'echo', 'Service ibf-dashboard disabled' ]

ibf-geoserver:
ports:
Expand Down
2 changes: 2 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ DB_PASSWORD=
SECRET=
RESET_SECRET=
NODE_ENV=
LOCAL_PORT_IBF_SERVICE=4000 # If you do not specify a port, the default port is 3000. this only applies to the override docker-compose file

# Token used to acces the water point data at https://data.waterpointdata.org/profile/edit/developer_settings
WATERPOINTDATA_TOKEN=
# This password is only needed for production
Expand Down
2 changes: 1 addition & 1 deletion interfaces/IBF-dashboard/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

export const environment = {
configuration: 'development',
apiUrl: 'http://localhost:3000/api', // API
apiUrl: `http://localhost:4000/api`, // API
useServiceWorker: false, // feature-flags
geoserverUrl: 'http://localhost:8081/geoserver/ibf-system/wms', // geoserver
ibfSystemVersion: 'v0.0.0', // version
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"install:interface": "npm install --no-optional --no-audit --no-fund --prefix interfaces/IBF-dashboard/",
"open": "npx npm-run-all open:ibf-api-service open:ibf-dashboard",
"open:ibf-dashboard": "open http://localhost:4200/",
"open:ibf-api-service": "open http://localhost:3000/docs",
"open:ibf-api-service": "open http://localhost:4000/docs",
"test:interface": "npm test --prefix interfaces/IBF-dashboard/",
"test:performance": "npm run lighthouse:run",
"test:integration": "npm run cypress:run",
Expand Down
1 change: 0 additions & 1 deletion services/API-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"start:dev": "npx tsc-watch --onSuccess \" node index.js \" --onFailure \"echo There was a problem with the build!\" -p tsconfig.json",
"prestart:prod": "tsc",
"start:prod": "node dist/main.js",
"seed": "npx ts-node src/scripts seed-init",
"test": "jest --config=jest.json --detectOpenHandles --forceExit --passWithNoTests",
"test:dev": "npm test -- --watchAll",
"test:coverage": "npm test -- --coverage --coverageDirectory=coverage",
Expand Down
3 changes: 1 addition & 2 deletions services/API-service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export const API_PATHS = {
const baseApiUrl = process.env.EXTERNAL_API_SERVICE_URL + 'api/';
const rootUrl =
process.env.NODE_ENV === 'development'
? `http://localhost:${PORT}/`
? `http://localhost:${process.env.LOCAL_PORT_IBF_SERVICE}/`
: process.env.EXTERNAL_API_SERVICE_URL;
export const EXTERNAL_API = {
root: rootUrl,
rootApi: `${rootUrl}/api`,
whatsAppStatus: baseApiUrl + API_PATHS.whatsAppStatus,
whatsAppIncoming: baseApiUrl + API_PATHS.whatsAppIncoming,
eventMapImage: baseApiUrl + API_PATHS.eventMapImage,
Expand Down

0 comments on commit ac8b4c0

Please sign in to comment.