From d61418886f647c8dbcdd929a7eaf24a11dd2d672 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 17 May 2024 12:59:05 -0400 Subject: [PATCH] refactor!: port env (#9559) refactor: port env --- docs/docs/install/environment-variables.md | 11 ++++------- e2e/src/setup.ts | 2 +- machine-learning/start.sh | 8 ++++---- server/src/config.ts | 3 +-- server/src/workers/api.ts | 2 +- server/src/workers/microservices.ts | 7 ++----- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/docs/docs/install/environment-variables.md b/docs/docs/install/environment-variables.md index d4b5664fbc..4c163ac226 100644 --- a/docs/docs/install/environment-variables.md +++ b/docs/docs/install/environment-variables.md @@ -59,13 +59,10 @@ It only need to be set if the Immich deployment method is changing. ## Ports -| Variable | Description | Default | Services | -| :---------------------- | :-------------------- | :-------: | :-------------------- | -| `HOST` | Host | `0.0.0.0` | server, microservices | -| `SERVER_PORT` | Server Port | `3001` | server | -| `MICROSERVICES_PORT` | Microservices Port | `3002` | microservices | -| `MACHINE_LEARNING_HOST` | Machine Learning Host | `0.0.0.0` | machine learning | -| `MACHINE_LEARNING_PORT` | Machine Learning Port | `3003` | machine learning | +| Variable | Description | Default | +| :------------ | :------------- | :------------------------------------: | +| `IMMICH_HOST` | Listening host | `0.0.0.0` | +| `IMMICH_PORT` | Listening port | 3001 (server), 3003 (machine learning) | ## Database diff --git a/e2e/src/setup.ts b/e2e/src/setup.ts index e9395ddd35..3ae87417a2 100644 --- a/e2e/src/setup.ts +++ b/e2e/src/setup.ts @@ -17,7 +17,7 @@ const setup = async () => { child.stdout.on('data', (data) => { const input = data.toString(); console.log(input); - if (input.includes('Immich Microservices is listening')) { + if (input.includes('Immich Microservices is running')) { _resolve(); } }); diff --git a/machine-learning/start.sh b/machine-learning/start.sh index 7a5cb919a6..9d0a505c0c 100755 --- a/machine-learning/start.sh +++ b/machine-learning/start.sh @@ -2,20 +2,20 @@ lib_path="/usr/lib/$(arch)-linux-gnu/libmimalloc.so.2" # mimalloc seems to increase memory usage dramatically with openvino, need to investigate -if ! [ "$DEVICE" = "openvino" ]; then +if ! [ "$DEVICE" = "openvino" ]; then export LD_PRELOAD="$lib_path" export LD_BIND_NOW=1 fi -: "${MACHINE_LEARNING_HOST:=[::]}" -: "${MACHINE_LEARNING_PORT:=3003}" +: "${IMMICH_HOST:=[::]}" +: "${IMMICH_PORT:=3003}" : "${MACHINE_LEARNING_WORKERS:=1}" : "${MACHINE_LEARNING_WORKER_TIMEOUT:=120}" gunicorn app.main:app \ -k app.config.CustomUvicornWorker \ + -b "$IMMICH_HOST":"$IMMICH_PORT" \ -w "$MACHINE_LEARNING_WORKERS" \ - -b "$MACHINE_LEARNING_HOST":"$MACHINE_LEARNING_PORT" \ -t "$MACHINE_LEARNING_WORKER_TIMEOUT" \ --log-config-json log_conf.json \ --graceful-timeout 0 diff --git a/server/src/config.ts b/server/src/config.ts index 1f4ed9f0eb..3e3a42c760 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -372,8 +372,7 @@ export const immichAppConfig: ConfigModuleOptions = { DB_VECTOR_EXTENSION: Joi.string().optional().valid('pgvector', 'pgvecto.rs').default('pgvecto.rs'), DB_SKIP_MIGRATIONS: Joi.boolean().optional().default(false), - MACHINE_LEARNING_PORT: Joi.number().optional(), - MICROSERVICES_PORT: Joi.number().optional(), + IMMICH_PORT: Joi.number().optional(), IMMICH_METRICS_PORT: Joi.number().optional(), IMMICH_METRICS: Joi.boolean().optional().default(false), diff --git a/server/src/workers/api.ts b/server/src/workers/api.ts index b6ad3a28fd..96f06ffc9c 100644 --- a/server/src/workers/api.ts +++ b/server/src/workers/api.ts @@ -18,7 +18,7 @@ const host = process.env.HOST; async function bootstrap() { otelSDK.start(); - const port = Number(process.env.SERVER_PORT) || 3001; + const port = Number(process.env.IMMICH_PORT) || 3001; const app = await NestFactory.create(ApiModule, { bufferLogs: true }); const logger = await app.resolve(ILoggerRepository); diff --git a/server/src/workers/microservices.ts b/server/src/workers/microservices.ts index 2400e62fc8..de198d2e27 100644 --- a/server/src/workers/microservices.ts +++ b/server/src/workers/microservices.ts @@ -6,12 +6,9 @@ import { ILoggerRepository } from 'src/interfaces/logger.interface'; import { WebSocketAdapter } from 'src/middleware/websocket.adapter'; import { otelSDK } from 'src/utils/instrumentation'; -const host = process.env.HOST; - export async function bootstrap() { otelSDK.start(); - const port = Number(process.env.MICROSERVICES_PORT) || 3002; const app = await NestFactory.create(MicroservicesModule, { bufferLogs: true }); const logger = await app.resolve(ILoggerRepository); logger.setAppName('ImmichMicroservices'); @@ -19,9 +16,9 @@ export async function bootstrap() { app.useLogger(logger); app.useWebSocketAdapter(new WebSocketAdapter(app)); - await (host ? app.listen(port, host) : app.listen(port)); + await app.listen(0); - logger.log(`Immich Microservices is listening on ${await app.getUrl()} [v${serverVersion}] [${envName}] `); + logger.log(`Immich Microservices is running [v${serverVersion}] [${envName}] `); } if (!isMainThread) {