Skip to content

Commit

Permalink
refactor!: port env (#9559)
Browse files Browse the repository at this point in the history
refactor: port env
  • Loading branch information
jrasm91 authored May 17, 2024
1 parent c03981a commit d614188
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
11 changes: 4 additions & 7 deletions docs/docs/install/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion e2e/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
8 changes: 4 additions & 4 deletions machine-learning/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion server/src/workers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NestExpressApplication>(ApiModule, { bufferLogs: true });
const logger = await app.resolve(ILoggerRepository);

Expand Down
7 changes: 2 additions & 5 deletions server/src/workers/microservices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ 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');
logger.setContext('ImmichMicroservices');
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) {
Expand Down

0 comments on commit d614188

Please sign in to comment.