From b478b1947cf80758787a4e46c8ed8b8b635824de Mon Sep 17 00:00:00 2001 From: Ruben Date: Mon, 11 Mar 2024 11:10:30 +0100 Subject: [PATCH 1/4] AB#26410 Make port ibf service port configurable locally --- docker-compose.override.yml | 6 +++--- example.env | 2 ++ interfaces/IBF-dashboard/src/environments/environment.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 0de83a03c..6592fc711 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -2,11 +2,11 @@ version: '3.8' services: ibf-api-service: - command: ['npm', 'run', 'start:dev'] + command: [ 'npm', 'run', 'start:dev' ] environment: - NODE_ENV=development ports: - - 3000:3000 + - ${LOCAL_PORT_IBF_SERVICE}:3000 depends_on: - ibf-local-db networks: @@ -14,7 +14,7 @@ services: - api-network ibf-dashboard: - entrypoint: ['echo', 'Service ibf-dashboard disabled'] + entrypoint: [ 'echo', 'Service ibf-dashboard disabled' ] ibf-geoserver: ports: diff --git a/example.env b/example.env index f085eb83a..9594846a1 100644 --- a/example.env +++ b/example.env @@ -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 diff --git a/interfaces/IBF-dashboard/src/environments/environment.ts b/interfaces/IBF-dashboard/src/environments/environment.ts index 33ffb2266..4a3b14dd1 100644 --- a/interfaces/IBF-dashboard/src/environments/environment.ts +++ b/interfaces/IBF-dashboard/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { configuration: 'development', - apiUrl: 'http://localhost:3000/api', // API + apiUrl: `http://localhost:${process.env['LOCAL_PORT_IBF_SERVICE'] ? process.env['LOCAL_PORT_IBF_SERVICE'] : 3000}/api`, // API useServiceWorker: false, // feature-flags geoserverUrl: 'http://localhost:8081/geoserver/ibf-system/wms', // geoserver ibfSystemVersion: 'v0.0.0', // version From 585fd0ca0ed25bd64c6ddceccd535319120a99b6 Mon Sep 17 00:00:00 2001 From: Ruben Date: Mon, 11 Mar 2024 11:18:52 +0100 Subject: [PATCH 2/4] Hardcode 4000 in frontend AB#26410 --- interfaces/IBF-dashboard/src/environments/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/IBF-dashboard/src/environments/environment.ts b/interfaces/IBF-dashboard/src/environments/environment.ts index 4a3b14dd1..b27f78a0a 100644 --- a/interfaces/IBF-dashboard/src/environments/environment.ts +++ b/interfaces/IBF-dashboard/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { configuration: 'development', - apiUrl: `http://localhost:${process.env['LOCAL_PORT_IBF_SERVICE'] ? process.env['LOCAL_PORT_IBF_SERVICE'] : 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 From 1ea4d857972fec5f68e8e920821f016917adb59f Mon Sep 17 00:00:00 2001 From: Ruben Date: Mon, 11 Mar 2024 11:57:28 +0100 Subject: [PATCH 3/4] Port 4000 in docs AB#26410 --- README.md | 12 ++++++------ docker-compose.override.yml | 1 + services/API-service/src/config.ts | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 923b8764c..bb50fc761 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ For IBF-dashboard 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. -- `docker compose up -d` +- `n` - `cd interfaces/IBF-dashboard` - `npm start` @@ -113,16 +113,16 @@ are connected to a database-server). For setting up a fully working version of t 3. Post 1st batch of dynamic data to database - 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 @@ -133,7 +133,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: diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 6592fc711..6b01a8fbf 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -5,6 +5,7 @@ services: command: [ 'npm', 'run', 'start:dev' ] environment: - NODE_ENV=development + - LOCAL_PORT_IBF_SERVICE=${LOCAL_PORT_IBF_SERVICE} ports: - ${LOCAL_PORT_IBF_SERVICE}:3000 depends_on: diff --git a/services/API-service/src/config.ts b/services/API-service/src/config.ts index f86ec3973..97f9e8d7b 100644 --- a/services/API-service/src/config.ts +++ b/services/API-service/src/config.ts @@ -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, From 731de25da9299b00f0bca36c76e06f231c83f0b9 Mon Sep 17 00:00:00 2001 From: Ruben Date: Mon, 11 Mar 2024 13:19:45 +0100 Subject: [PATCH 4/4] Update readme.md AB#26410 --- README.md | 70 +++++++++++-------------------- package.json | 2 +- services/API-service/package.json | 1 - 3 files changed, 25 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index bb50fc761..efa5827df 100644 --- a/README.md +++ b/README.md @@ -37,72 +37,47 @@ 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: +- Install Node.js: -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 -- `n` -- `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: @@ -110,8 +85,11 @@ are connected to a database-server). For setting up a fully working version of t - `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:4000/docs/#/scripts - run for all countries and disaster-type at once: http://localhost:4000/docs/#/scripts/ScriptsController_mockAll diff --git a/package.json b/package.json index e7661764a..0f4af1d5c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/services/API-service/package.json b/services/API-service/package.json index 3f89a65b0..d1b535818 100644 --- a/services/API-service/package.json +++ b/services/API-service/package.json @@ -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",