From 9d337bf4dc7ee65474925712dea90056dd7fe0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Skyler=20M=C3=A4ntysaari?= Date: Tue, 24 Jan 2023 06:18:35 +0200 Subject: [PATCH] feat(server/machine-learning): Configurable port (#1386) * feat(server/machine-learning): Configurable port * feat(server/machine-learning): Address PR comments. * feat(server/machine-learning): Simplify Co-authored-by: Alex --- machine-learning/src/main.ts | 4 +++- server/apps/immich/src/main.ts | 8 ++++++-- server/apps/microservices/src/main.ts | 8 ++++++-- server/libs/common/src/config/app.config.ts | 3 +++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/machine-learning/src/main.ts b/machine-learning/src/main.ts index 5199e4b719..dbe0e393b1 100644 --- a/machine-learning/src/main.ts +++ b/machine-learning/src/main.ts @@ -5,7 +5,9 @@ import { Logger } from '@nestjs/common'; async function bootstrap() { const app = await NestFactory.create(AppModule); - await app.listen(3003, () => { + const port = Number(process.env.MACHINE_LEARNING_PORT) || 3003; + + await app.listen(port, () => { if (process.env.NODE_ENV == 'development') { Logger.log( 'Running Immich Machine Learning in DEVELOPMENT environment', diff --git a/server/apps/immich/src/main.ts b/server/apps/immich/src/main.ts index 79eed0854d..d1d3ed1d0b 100644 --- a/server/apps/immich/src/main.ts +++ b/server/apps/immich/src/main.ts @@ -27,6 +27,8 @@ async function bootstrap() { app.enableCors(); } + const serverPort = Number(process.env.SERVER_PORT) || 3001; + const redisIoAdapter = new RedisIoAdapter(app); await redisIoAdapter.connectToRedis(); app.useWebSocketAdapter(redisIoAdapter); @@ -59,7 +61,7 @@ async function bootstrap() { customSiteTitle: 'Immich API Documentation', }); - await app.listen(3001, () => { + await app.listen(serverPort, () => { if (process.env.NODE_ENV == 'development') { // Generate API Documentation only in development mode const outputPath = path.resolve(process.cwd(), 'immich-openapi-specs.json'); @@ -67,7 +69,9 @@ async function bootstrap() { } const envName = (process.env.NODE_ENV || 'development').toUpperCase(); - logger.log(`Running Immich Server in ${envName} environment - version ${SERVER_VERSION}`); + logger.log( + `Running Immich Server in ${envName} environment - version ${SERVER_VERSION} - Listening on port: ${serverPort}`, + ); }); logger.warn(`Machine learning is ${MACHINE_LEARNING_ENABLED ? 'enabled' : 'disabled'}`); diff --git a/server/apps/microservices/src/main.ts b/server/apps/microservices/src/main.ts index c512e5c0e7..f8292ce791 100644 --- a/server/apps/microservices/src/main.ts +++ b/server/apps/microservices/src/main.ts @@ -12,13 +12,17 @@ async function bootstrap() { logger: getLogLevels(), }); + const listeningPort = Number(process.env.MACHINE_LEARNING_PORT) || 3002; + const redisIoAdapter = new RedisIoAdapter(app); await redisIoAdapter.connectToRedis(); app.useWebSocketAdapter(redisIoAdapter); - await app.listen(3002, () => { + await app.listen(listeningPort, () => { const envName = (process.env.NODE_ENV || 'development').toUpperCase(); - logger.log(`Running Immich Microservices in ${envName} environment - version ${SERVER_VERSION}`); + logger.log( + `Running Immich Microservices in ${envName} environment - version ${SERVER_VERSION} - Listening on port: ${listeningPort}`, + ); }); } bootstrap(); diff --git a/server/libs/common/src/config/app.config.ts b/server/libs/common/src/config/app.config.ts index 7f2ab30459..71a47b0b18 100644 --- a/server/libs/common/src/config/app.config.ts +++ b/server/libs/common/src/config/app.config.ts @@ -35,5 +35,8 @@ export const immichAppConfig: ConfigModuleOptions = { DISABLE_REVERSE_GEOCODING: Joi.boolean().optional().valid(true, false).default(false), REVERSE_GEOCODING_PRECISION: Joi.number().optional().valid(0, 1, 2, 3).default(3), LOG_LEVEL: Joi.string().optional().valid('simple', 'verbose', 'debug', 'log', 'warn', 'error').default('log'), + MACHINE_LEARNING_PORT: Joi.number().optional(), + MICROSERVICES_PORT: Joi.number().optional(), + SERVER_PORT: Joi.number().optional(), }), };