Skip to content

Commit 714967d

Browse files
committed
feat: Implement agent creation command with interactive prompts
feat: Add backends sync command for identity synchronization feat: Create health check controller and module for application health monitoring feat: Integrate health check functionalities with NestJS Terminus feat: Develop keyrings command for creating keyrings with token generation feat: Initialize Sentry for error tracking and monitoring feat: Add identities command for updating fingerprints of identities chore: Configure Supervisor for NestJS application management chore: Set up Supervisor for Nuxt.js web application chore: Establish Supervisor configuration for process management
1 parent 451a1bb commit 714967d

32 files changed

+802
-148
lines changed

Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,28 @@ ARG NODE_ENV=production
1818
ENV NODE_ENV=${NODE_ENV}
1919
ENV ALLOW_RUNTIME_BUILD=true
2020
ENV DO_NOT_TRACK=1
21+
ENV PYTHONWARNINGS=ignore::UserWarning
2122

2223
WORKDIR /data
2324

24-
ADD ecosystem.config.cjs .
2525
ADD package.json .
2626
ADD *.lock .
2727
ADD ./apps/api/package.json ./apps/api/package.json
2828
ADD ./apps/web/package.json ./apps/web/package.json
2929

30+
31+
COPY ./etc /etc
32+
3033
RUN apk add --no-cache \
34+
supervisor \
3135
openssl \
3236
git \
3337
jq \
3438
bash \
3539
nano
3640

41+
RUN mkdir -p /var/log/supervisor
42+
3743
RUN ARCH=$(uname -m) && \
3844
if [ "$ARCH" = "x86_64" ]; then \
3945
npm i -g @css-inline/css-inline-linux-x64-musl; \
@@ -49,8 +55,6 @@ RUN yarn install \
4955
--non-interactive \
5056
--production=false
5157

52-
RUN yarn global add pm2
53-
5458
COPY --from=builder /data/apps/api/dist ./apps/api/dist
5559
COPY --from=builder /data/apps/web/.output ./apps/web/.output
5660
COPY --from=builder /data/apps/web/nuxt.config.ts ./apps/web/nuxt.config.ts
@@ -61,4 +65,4 @@ COPY --from=builder /data/apps/web/scripts/checkinstall.sh ./apps/web/scripts/ch
6165

6266
EXPOSE 4000 3000
6367

64-
CMD ["pm2-runtime", "ecosystem.config.cjs"]
68+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ IMG_NAME = "ghcr.io/libertech-fr/sesame-orchestrator"
1212
BASE_NAME = "sesame"
1313
APP_NAME = "sesame-orchestrator"
1414
PLATFORM = "linux/amd64"
15+
1516
include .env
1617

1718
CERT_DIR = ./certificates
1819
COMMON_NAME = localhost
1920
DAYS_VALID = 365
2021

22+
SESAME_SENTRY_DSN ?= ""
23+
2124
$(shell mkdir -p $(CERT_DIR))
2225

2326

@@ -38,18 +41,21 @@ simulation: ## Start production environment in simulation mode
3841
--platform $(PLATFORM) \
3942
--network dev \
4043
--name $(APP_NAME) \
44+
-e SESAME_SENTRY_DSN=$(SESAME_SENTRY_DSN) \
4145
-p $(APP_WEB_PORT):3000 \
4246
-p $(APP_WEB_PORT_SECURE):3443 \
4347
-p $(APP_API_PORT):4000 \
4448
-p $(APP_API_PORT_SECURE):4443 \
4549
-v $(CURDIR)/apps/api/storage:/data/apps/api/storage \
4650
-v $(CURDIR)/.env:/data/.env \
51+
-v $(CURDIR)/etc/supervisor:/etc/supervisor \
4752
-v $(CURDIR)/apps/api/.env:/data/apps/api/.env \
4853
-v $(CURDIR)/apps/web/.env:/data/apps/web/.env \
4954
-v $(CURDIR)/certificates:/data/certificates \
5055
-v $(CURDIR)/apps/api/configs:/data/apps/api/configs \
56+
-v $(CURDIR)/apps/api/defaults:/data/apps/api/defaults \
5157
-v $(CURDIR)/apps/web/config:/data/apps/web/config \
52-
$(IMG_NAME)
58+
$(IMG_NAME) /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
5359

5460
prod: ## Start production environment
5561
@docker run --rm -it \
@@ -59,6 +65,7 @@ prod: ## Start production environment
5965
--platform $(PLATFORM) \
6066
--network dev \
6167
--name $(APP_NAME) \
68+
-e SESAME_SENTRY_DSN=$(SESAME_SENTRY_DSN) \
6269
-p $(APP_WEB_PORT):3000 \
6370
-p $(APP_WEB_PORT_SECURE):3443 \
6471
-p $(APP_API_PORT):4000 \
@@ -74,11 +81,13 @@ dev: ## Start development environment
7481
--platform $(PLATFORM) \
7582
--network dev \
7683
--name $(APP_NAME) \
84+
-e SESAME_SENTRY_DSN=$(SESAME_SENTRY_DSN) \
7785
-p $(APP_WEB_PORT):3000 \
7886
-p $(APP_WEB_PORT_SECURE):3443 \
7987
-p $(APP_API_PORT):4000 \
8088
-p $(APP_API_PORT_SECURE):4443 \
8189
-v $(CURDIR):/data \
90+
-v $(CURDIR)/etc/supervisor:/etc/supervisor \
8291
$(IMG_NAME) yarn start:dev
8392

8493
debug: ## Start debug environment
@@ -89,6 +98,7 @@ debug: ## Start debug environment
8998
--platform $(PLATFORM) \
9099
--network dev \
91100
--name $(APP_NAME) \
101+
-e SESAME_SENTRY_DSN=$(SESAME_SENTRY_DSN) \
92102
-p $(APP_WEB_PORT):3000 \
93103
-p $(APP_WEB_PORT_SECURE):3443 \
94104
-p $(APP_API_PORT):4000 \
@@ -115,6 +125,7 @@ exec: ## Run a shell in the container
115125
--add-host host.docker.internal:host-gateway \
116126
--platform $(PLATFORM) \
117127
--network dev \
128+
-e SESAME_SENTRY_DSN=$(SESAME_SENTRY_DSN) \
118129
-v $(CURDIR):/data \
119130
$(IMG_NAME) bash
120131

apps/api/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"@nestjs/platform-express": "^10.4.8",
3131
"@nestjs/schedule": "^6.0.0",
3232
"@nestjs/swagger": "^8.0.7",
33+
"@nestjs/terminus": "^11.0.0",
34+
"@sentry/nestjs": "^10.25.0",
3335
"ajv": "^8.16.0",
3436
"ajv-errors": "^3.0.0",
3537
"ajv-formats": "^3.0.1",

apps/api/src/_common/factorydrive/factorydrive/abstract.storage.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export default abstract class AbstractStorage {
1212
}
1313

1414
public onStorageInit(): void | Promise<void> {
15-
console.log('onStorageInita')
1615
return Promise.resolve()
1716
}
1817

apps/api/src/_common/filters/all-exception.filter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { ArgumentsHost, Catch, ExceptionFilter, Logger } from '@nestjs/common';
2-
import { Response } from 'express';
1+
import { ArgumentsHost, Catch, ExceptionFilter, Logger } from '@nestjs/common'
2+
import { SentryExceptionCaptured } from '@sentry/nestjs'
3+
import { Response } from 'express'
4+
35
@Catch()
46
export class AllExceptionFilter implements ExceptionFilter {
7+
@SentryExceptionCaptured()
58
catch(exception: unknown, host: ArgumentsHost) {
69
Logger.debug(exception['message'], 'AllExceptionFilter');
710

apps/api/src/app.controller.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ export class AppController extends AbstractController {
7979
},
8080
});
8181
}
82+
83+
@Get("/debug-sentry")
84+
getError() {
85+
throw new Error("My first Sentry error!");
86+
}
8287
}

apps/api/src/app.module.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ import { ShutdownObserver } from './_common/observers/shutdown.observer';
2626
import { ScheduleModule } from '@nestjs/schedule';
2727
import { HttpModule } from '@nestjs/axios';
2828
import { ExtensionsModule } from './extensions/extensions.module';
29+
import { SentryModule, SentryGlobalFilter } from '@sentry/nestjs/setup';
2930

3031
@Module({
3132
imports: [
33+
SentryModule.forRoot(),
34+
3235
ConfigModule.forRoot({
3336
isGlobal: true,
3437
load: [config],
3538
}),
3639
EventEmitterModule.forRoot({
3740
wildcard: false,
3841
delimiter: '.',
39-
maxListeners: 25,
42+
maxListeners: 99,
4043
verboseMemoryLeak: true,
4144
ignoreErrors: false,
4245
}),
@@ -150,6 +153,10 @@ import { ExtensionsModule } from './extensions/extensions.module';
150153
// provide: APP_FILTER,
151154
// useClass: AllExceptionFilter,
152155
// },
156+
{
157+
provide: APP_FILTER,
158+
useClass: SentryGlobalFilter,
159+
},
153160
{
154161
provide: APP_FILTER,
155162
useClass: MongooseValidationFilter,

apps/api/src/app.service.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BadRequestException, Injectable, OnApplicationBootstrap } from '@nestjs/common';
1+
import { BadRequestException, Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common';
22
import { PackageJson } from 'types-package-json';
33
import { ModuleRef } from '@nestjs/core';
44
import { readFileSync } from 'fs';
@@ -8,6 +8,9 @@ import { HttpService } from '@nestjs/axios';
88
import { LRUCache } from 'lru-cache';
99
import { catchError, firstValueFrom } from 'rxjs';
1010
import { Cron, CronExpression } from '@nestjs/schedule';
11+
import { getLogLevel } from './_common/functions/get-log-level';
12+
import { ConfigService } from '@nestjs/config';
13+
import { isConsoleEntrypoint } from './_common/functions/is-cli';
1114

1215
export enum ProjectsList {
1316
SESAME_ORCHESTRATOR = 'sesame-orchestrator',
@@ -74,6 +77,7 @@ export class AppService extends AbstractService implements OnApplicationBootstra
7477
public constructor(
7578
protected moduleRef: ModuleRef,
7679
private readonly httpService: HttpService,
80+
private readonly config: ConfigService<any>,
7781
) {
7882
super({ moduleRef });
7983
this.package = JSON.parse(readFileSync('package.json', 'utf-8'));
@@ -100,6 +104,12 @@ export class AppService extends AbstractService implements OnApplicationBootstra
100104
}
101105

102106
this.logger.log('Application service bootstrap completed.');
107+
108+
if (isConsoleEntrypoint) {
109+
this.logger.localInstance.setLogLevels(
110+
getLogLevel(this.config.get('application.logLevel', 'verbose'))
111+
);
112+
}
103113
}
104114

105115
/**

apps/api/src/cli/cli.module.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

apps/api/src/console.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { CommandFactory } from 'nest-commander';
22
import configInstance from '~/config';
33
import { getLogLevel } from './_common/functions/get-log-level';
4-
import { CliModule } from './cli/cli.module';
54
import { InternalLogger } from './core/logger/internal.logger';
5+
import { AppModule } from './app.module';
66

77
(async () => {
88
try {
99
const cfg = configInstance();
1010
const logger = new InternalLogger({
11-
logLevel: getLogLevel(cfg?.application?.logLevel),
11+
logLevel: ['error'],
12+
// logLevel: getLogLevel(cfg?.application?.logLevel),
1213
mongoose: cfg?.mongoose,
1314
});
1415
logger.log(`Starting CLI with log level <${cfg?.application?.logLevel || 'info'}>`);
15-
const app = await CommandFactory.runWithoutClosing(CliModule, {
16+
const app = await CommandFactory.runWithoutClosing(AppModule, {
1617
logger,
1718
errorHandler: (err) => {
1819
console.error(err);

0 commit comments

Comments
 (0)