From 33fb990cebd136f330b28a46c154a96f9d715307 Mon Sep 17 00:00:00 2001 From: andrea rota Date: Thu, 11 Nov 2021 11:44:27 +0000 Subject: [PATCH] use a distinct envvar to set daemon listen ports when running Express natively --- README.md | 25 ++++++++++++++++--- .../config/custom-environment-variables.json | 2 +- api/apps/api/config/default.json | 2 +- api/apps/api/src/main.ts | 2 +- .../config/custom-environment-variables.json | 2 +- api/apps/geoprocessing/config/default.json | 2 +- api/apps/geoprocessing/src/main.ts | 2 +- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a73b30f0c6..0dbf17a3f0 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,10 @@ details. * `API_AUTH_X_API_KEY` (string, required): a secret used as API key for requests from the Geoprocessing service to the API; can be generated similarly to `API_AUTH_JWT_SECRET` - * `API_SERVICE_PORT` (number, required): the port on which the API service - should listen on the local machine + * `API_SERVICE_PORT` (number, required): the port exposed by Docker for the + API service; when running an instance under Docker Compose, NestJS will + always be listening on port 3000 internally, and this is mapped to + `API_SERVICE_PORT` when exposed outside of the container * `API_SERVICE_URL` (URL, optional, default is http://api:3000): the internal (docker-compose or k8s cluster) where the API service can be reached by other services running in the cluster @@ -67,8 +69,11 @@ details. PostgreSQL connection (API) * `API_POSTGRES_DB` (string, required): name of the database to be used for the PostgreSQL connection (API) - * `GEOPROCESSING_SERVICE_PORT` (number, required): the port on which the - Geoprocessing service should listen on the local machine + * `GEOPROCESSING_SERVICE_PORT` (number, required): the port exposed by Docker + for the Geoprocessing service; when running an instance under Docker + Compose, NestJS will always be listening on port 3000 internally, and this + is mapped to `GEOPROCESSING_SERVICE_PORT` when exposed outside of the + container * `POSTGRES_GEO_SERVICE_PORT` (number, required): the port on which the geoprocessing PostgreSQL service should listen on the local machine * `GEOPROCESSING_RUN_MIGRATIONS_ON_STARTUP`: (`true|false`, optional, default @@ -110,6 +115,18 @@ The PostgreSQL credentials are used to create a database user when the PostgreSQL container is started for the first time. PostgreSQL data is persisted via a Docker volume. +#### Running API and Geoprocessing services natively + +When running the API and Geoprocessing services without relying on Docker +Compose for container orchestration, the following two environment variables can +be used to set on which port the NestJS/Express daemon should be listening, +instead of the hardcoded port `3000` which is used in Docker setups. + +* `API_DAEMON_LISTEN_PORT` (number, optional, default is 3000): port on which + the Express daemon of the API service will listen +* `GEOPROCESSING_DAEMON_LISTEN_PORT` (number, optional, default is 3000): port + on which the Express daemon of the Geoprocessing service will listen + ### Running the Marxan Cloud platform Run `make start` to start all the services. diff --git a/api/apps/api/config/custom-environment-variables.json b/api/apps/api/config/custom-environment-variables.json index 55efcdb79d..a30e972f28 100644 --- a/api/apps/api/config/custom-environment-variables.json +++ b/api/apps/api/config/custom-environment-variables.json @@ -30,7 +30,7 @@ }, "api": { "url": "API_SERVICE_URL", - "port": "API_SERVICE_PORT" + "daemonListenPort": "API_DAEMON_LISTEN_PORT" }, "storage": { "sharedFileStorage": { diff --git a/api/apps/api/config/default.json b/api/apps/api/config/default.json index f6ac82f6ef..4d11af943c 100644 --- a/api/apps/api/config/default.json +++ b/api/apps/api/config/default.json @@ -15,7 +15,7 @@ }, "api": { "url": "http://api:3000", - "port": 3000 + "daemonListenPort": 3000 }, "jobOptions":{ "removeOnComplete": 100, diff --git a/api/apps/api/src/main.ts b/api/apps/api/src/main.ts index 9fe79b00c8..668aaeb4be 100644 --- a/api/apps/api/src/main.ts +++ b/api/apps/api/src/main.ts @@ -10,7 +10,7 @@ export async function bootstrap() { SwaggerModule.setup('/swagger', app, swaggerDocument); - await app.listen(AppConfig.get('api.port')); + await app.listen(AppConfig.get('api.daemonListenPort')); } bootstrap(); diff --git a/api/apps/geoprocessing/config/custom-environment-variables.json b/api/apps/geoprocessing/config/custom-environment-variables.json index 8a6e87bb78..514cc70460 100644 --- a/api/apps/geoprocessing/config/custom-environment-variables.json +++ b/api/apps/geoprocessing/config/custom-environment-variables.json @@ -29,7 +29,7 @@ "url": "API_SERVICE_URL" }, "geo": { - "port": "GEO_SERVICE_PORT" + "daemonListenPort": "GEO_DAEMON_LISTEN_PORT" }, "storage": { "sharedFileStorage": { diff --git a/api/apps/geoprocessing/config/default.json b/api/apps/geoprocessing/config/default.json index d67ee2c851..310f4dbbc0 100644 --- a/api/apps/geoprocessing/config/default.json +++ b/api/apps/geoprocessing/config/default.json @@ -10,7 +10,7 @@ "url": "http://api:3000" }, "geo": { - "port": 3000 + "daemonListenPort": 3000 }, "storage": { "sharedFileStorage": { diff --git a/api/apps/geoprocessing/src/main.ts b/api/apps/geoprocessing/src/main.ts index 718774a78d..b461d1d7b4 100644 --- a/api/apps/geoprocessing/src/main.ts +++ b/api/apps/geoprocessing/src/main.ts @@ -15,6 +15,6 @@ async function bootstrap() { }), ); app.useGlobalFilters(new AllExceptionsFilter()); - await app.listen(AppConfig.get('geo.port')); + await app.listen(AppConfig.get('geo.daemonListenPort')); } bootstrap();