From 545bfd6ec2325a4e6cea118f4b95203f9789be7f Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:14:50 +0200 Subject: [PATCH 01/10] fix: dependencies issues (nestjs, opentelemetry and missing ts-node) --- src/booking/package.json | 29 +++++++++++++++-------------- src/building-blocks/package.json | 28 ++++++++++++++-------------- src/flight/package.json | 29 +++++++++++++++-------------- src/identity/package.json | 29 +++++++++++++++-------------- src/passenger/package.json | 29 +++++++++++++++-------------- 5 files changed, 74 insertions(+), 70 deletions(-) diff --git a/src/booking/package.json b/src/booking/package.json index 2bb566b..db56434 100644 --- a/src/booking/package.json +++ b/src/booking/package.json @@ -17,20 +17,20 @@ "test": "jest" }, "dependencies": { - "@nestjs/cli": "10.2.1", - "@nestjs/config": "^3.1.1", - "@nestjs/core": "10.2.10", - "@nestjs/cqrs": "^10.2.6", + "@nestjs/cli": "^10.2.1", + "@nestjs/config": "^3.2.2", + "@nestjs/core": "^10.2.1", + "@nestjs/cqrs": "^10.2.7", "@nestjs/jwt": "^10.2.0", - "@nestjs/mapped-types": "2.0.4", - "@nestjs/microservices": "^10.2.10", - "@nestjs/passport": "^10.0.2", - "@nestjs/platform-express": "^10.2.10", - "@nestjs/schematics": "10.0.3", - "@nestjs/swagger": "^7.1.16", - "@nestjs/terminus": "^10.1.1", - "@nestjs/testing": "10.2.10", - "@nestjs/typeorm": "^10.0.1", + "@nestjs/mapped-types": "^2.0.5", + "@nestjs/microservices": "^10.3.7", + "@nestjs/passport": "^10.0.3", + "@nestjs/platform-express": "^10.3.7", + "@nestjs/schematics": "^10.1.1", + "@nestjs/swagger": "^7.3.1", + "@nestjs/terminus": "^10.2.3", + "@nestjs/testing": "^10.3.7", + "@nestjs/typeorm": "^10.0.2", "axios": "^1.6.2", "building-blocks": "file:../building-blocks", "class-transformer": "^0.5.1", @@ -40,7 +40,8 @@ "nodemon": "^3.0.2", "pg": "^8.11.3", "testcontainers": "^10.3.2", - "ts-mapper": "^1.2.4" + "ts-mapper": "^1.2.4", + "ts-node": "^10.9.2" }, "devDependencies": { "@faker-js/faker": "^8.3.1", diff --git a/src/building-blocks/package.json b/src/building-blocks/package.json index f84c6e0..afce69b 100644 --- a/src/building-blocks/package.json +++ b/src/building-blocks/package.json @@ -15,22 +15,22 @@ "@nestjs/cli": "10.2.1", "@nestjs/cqrs": "^10.2.6", "@nestjs/passport": "^10.0.2", - "@opentelemetry/api": "^1.7.0", - "@opentelemetry/auto-instrumentations-node": "^0.40.2", - "@opentelemetry/exporter-jaeger": "^1.19.0", - "@opentelemetry/exporter-prometheus": "^0.46.0", - "@opentelemetry/exporter-zipkin": "^1.19.0", - "@opentelemetry/instrumentation-amqplib": "^0.33.4", - "@opentelemetry/instrumentation-express": "^0.34.0", - "@opentelemetry/instrumentation-http": "^0.46.0", - "@opentelemetry/instrumentation-nestjs-core": "^0.33.3", + "@opentelemetry/api": "^1.8.0", + "@opentelemetry/auto-instrumentations-node": "^0.44.0", + "@opentelemetry/exporter-jaeger": "^1.23.0", + "@opentelemetry/exporter-prometheus": "^0.50.0", + "@opentelemetry/exporter-zipkin": "^1.23.0", + "@opentelemetry/instrumentation-amqplib": "^0.36.0", + "@opentelemetry/instrumentation-express": "^0.37.0", + "@opentelemetry/instrumentation-http": "^0.50.0", + "@opentelemetry/instrumentation-nestjs-core": "^0.36.0", "@opentelemetry/metrics": "^0.24.0", "@opentelemetry/node": "^0.24.0", - "@opentelemetry/resources": "^1.19.0", - "@opentelemetry/sdk-node": "^0.46.0", - "@opentelemetry/sdk-trace-base": "^1.19.0", - "@opentelemetry/sdk-trace-node": "^1.19.0", - "@opentelemetry/semantic-conventions": "^1.19.0", + "@opentelemetry/resources": "^1.23.0", + "@opentelemetry/sdk-node": "^0.50.0", + "@opentelemetry/sdk-trace-base": "^1.23.0", + "@opentelemetry/sdk-trace-node": "^1.23.0", + "@opentelemetry/semantic-conventions": "^1.23.0", "@types/amqplib": "^0.10.4", "@types/dotenv": "8.2.0", "@types/express": "4.17.21", diff --git a/src/flight/package.json b/src/flight/package.json index 0a7f273..5943171 100644 --- a/src/flight/package.json +++ b/src/flight/package.json @@ -17,20 +17,20 @@ "test": "jest" }, "dependencies": { - "@nestjs/cli": "10.2.1", - "@nestjs/config": "^3.1.1", - "@nestjs/core": "10.2.10", - "@nestjs/cqrs": "^10.2.6", + "@nestjs/cli": "^10.2.1", + "@nestjs/config": "^3.2.2", + "@nestjs/core": "^10.2.1", + "@nestjs/cqrs": "^10.2.7", "@nestjs/jwt": "^10.2.0", - "@nestjs/mapped-types": "2.0.4", - "@nestjs/microservices": "^10.2.10", - "@nestjs/passport": "^10.0.2", - "@nestjs/platform-express": "^10.2.10", - "@nestjs/schematics": "10.0.3", - "@nestjs/swagger": "^7.1.16", - "@nestjs/terminus": "^10.1.1", - "@nestjs/testing": "10.2.10", - "@nestjs/typeorm": "^10.0.1", + "@nestjs/mapped-types": "^2.0.5", + "@nestjs/microservices": "^10.3.7", + "@nestjs/passport": "^10.0.3", + "@nestjs/platform-express": "^10.3.7", + "@nestjs/schematics": "^10.1.1", + "@nestjs/swagger": "^7.3.1", + "@nestjs/terminus": "^10.2.3", + "@nestjs/testing": "^10.3.7", + "@nestjs/typeorm": "^10.0.2", "building-blocks": "file:../building-blocks", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", @@ -39,7 +39,8 @@ "nodemon": "^3.0.2", "pg": "^8.11.3", "testcontainers": "^10.3.2", - "ts-mapper": "^1.2.4" + "ts-mapper": "^1.2.4", + "ts-node": "^10.9.2" }, "devDependencies": { "@faker-js/faker": "^8.3.1", diff --git a/src/identity/package.json b/src/identity/package.json index e13b93d..19aab59 100644 --- a/src/identity/package.json +++ b/src/identity/package.json @@ -17,20 +17,20 @@ "test": "jest" }, "dependencies": { - "@nestjs/cli": "10.2.1", - "@nestjs/config": "^3.1.1", - "@nestjs/core": "10.2.10", - "@nestjs/cqrs": "^10.2.6", + "@nestjs/cli": "^10.2.1", + "@nestjs/config": "^3.2.2", + "@nestjs/core": "^10.2.1", + "@nestjs/cqrs": "^10.2.7", "@nestjs/jwt": "^10.2.0", - "@nestjs/mapped-types": "2.0.4", - "@nestjs/microservices": "^10.2.10", - "@nestjs/passport": "^10.0.2", - "@nestjs/platform-express": "^10.2.10", - "@nestjs/schematics": "10.0.3", - "@nestjs/swagger": "^7.1.16", - "@nestjs/terminus": "^10.1.1", - "@nestjs/testing": "10.2.10", - "@nestjs/typeorm": "^10.0.1", + "@nestjs/mapped-types": "^2.0.5", + "@nestjs/microservices": "^10.3.7", + "@nestjs/passport": "^10.0.3", + "@nestjs/platform-express": "^10.3.7", + "@nestjs/schematics": "^10.1.1", + "@nestjs/swagger": "^7.3.1", + "@nestjs/terminus": "^10.2.3", + "@nestjs/testing": "^10.3.7", + "@nestjs/typeorm": "^10.0.2", "building-blocks": "file:../building-blocks", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", @@ -39,7 +39,8 @@ "nodemon": "^3.0.2", "pg": "^8.11.3", "testcontainers": "^10.3.2", - "ts-mapper": "^1.2.4" + "ts-mapper": "^1.2.4", + "ts-node": "^10.9.2" }, "devDependencies": { "@faker-js/faker": "^8.3.1", diff --git a/src/passenger/package.json b/src/passenger/package.json index 627b8ea..de2bc02 100644 --- a/src/passenger/package.json +++ b/src/passenger/package.json @@ -17,20 +17,20 @@ "test": "jest" }, "dependencies": { - "@nestjs/cli": "10.2.1", - "@nestjs/config": "^3.1.1", - "@nestjs/core": "10.2.10", - "@nestjs/cqrs": "^10.2.6", + "@nestjs/cli": "^10.2.1", + "@nestjs/config": "^3.2.2", + "@nestjs/core": "^10.2.1", + "@nestjs/cqrs": "^10.2.7", "@nestjs/jwt": "^10.2.0", - "@nestjs/mapped-types": "2.0.4", - "@nestjs/microservices": "^10.2.10", - "@nestjs/passport": "^10.0.2", - "@nestjs/platform-express": "^10.2.10", - "@nestjs/schematics": "10.0.3", - "@nestjs/swagger": "^7.1.16", - "@nestjs/terminus": "^10.1.1", - "@nestjs/testing": "10.2.10", - "@nestjs/typeorm": "^10.0.1", + "@nestjs/mapped-types": "^2.0.5", + "@nestjs/microservices": "^10.3.7", + "@nestjs/passport": "^10.0.3", + "@nestjs/platform-express": "^10.3.7", + "@nestjs/schematics": "^10.1.1", + "@nestjs/swagger": "^7.3.1", + "@nestjs/terminus": "^10.2.3", + "@nestjs/testing": "^10.3.7", + "@nestjs/typeorm": "^10.0.2", "building-blocks": "file:../building-blocks", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", @@ -39,7 +39,8 @@ "nodemon": "^3.0.2", "pg": "^8.11.3", "testcontainers": "^10.3.2", - "ts-mapper": "^1.2.4" + "ts-mapper": "^1.2.4", + "ts-node": "^10.9.2" }, "devDependencies": { "@faker-js/faker": "^8.3.1", From c0c9aff202b03b8c64c01948c68c92a037a87062 Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:18:46 +0200 Subject: [PATCH 02/10] fix: missing openTelemetry module import --- src/building-blocks/openTelemetry/open-telemetry.module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/building-blocks/openTelemetry/open-telemetry.module.ts b/src/building-blocks/openTelemetry/open-telemetry.module.ts index b7d1bd2..b06ccef 100644 --- a/src/building-blocks/openTelemetry/open-telemetry.module.ts +++ b/src/building-blocks/openTelemetry/open-telemetry.module.ts @@ -6,7 +6,7 @@ import { OpenTelemetryOptions, OpenTelemetryTracer} from './open-telemetry-trace provide: 'IOpenTelemetryTracer', useClass: OpenTelemetryTracer }], - exports: ['IOpenTelemetryTracer'] + exports: ['IOpenTelemetryTracer', OpenTelemetryOptions] }) export class OpenTelemetryModule implements OnApplicationShutdown { From 0e24a1d16008897fa1f2b38a6a15a4d6d758ce73 Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:21:25 +0200 Subject: [PATCH 03/10] fix: removed zipkin compatible endpoint port from jaeger (conflict on port 9411) --- deployments/docker-compose/infrastructure.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployments/docker-compose/infrastructure.yaml b/deployments/docker-compose/infrastructure.yaml index cc3eed2..d3c19a3 100644 --- a/deployments/docker-compose/infrastructure.yaml +++ b/deployments/docker-compose/infrastructure.yaml @@ -43,7 +43,8 @@ services: - 5778:5778 - 6831:6831/udp - 6832:6832/udp - - 9411:9411 + # Zipkin compatible endpoint (@see https://www.jaegertracing.io/docs/1.6/getting-started/#migrating-from-zipkin ) + # - 9411:9411 - 14268:14268 - 16686:16686 networks: From e86e7adb586baf34c548fe91acaa2e8a1eeaa70d Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:34:46 +0200 Subject: [PATCH 04/10] refactor: normalizing environment variables --- src/booking/.env.development | 6 +++--- src/building-blocks/configs/configs.js | 8 ++++---- src/building-blocks/configs/configs.ts | 8 ++++---- src/flight/.env.development | 6 +++--- src/identity/.env.development | 8 ++++---- src/identity/.env.test | 4 ++-- src/passenger/.env.development | 6 +++--- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/booking/.env.development b/src/booking/.env.development index ba6f795..7ea2c9b 100644 --- a/src/booking/.env.development +++ b/src/booking/.env.development @@ -17,14 +17,14 @@ POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_USERNAME=postgres POSTGRES_PASSWORD=postgres -POSTGRES_Database=booking -POSTGRES_SYNCHRONIZE =false +POSTGRES_DATABASE=booking +POSTGRES_SYNCHRONIZE=false POSTGRES_ENTITIES=/../**/*.entity.{js,ts} POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} POSTGRES_MIGRATIONS_RUN=true # Rabbitmq -RABBITMQ_Host=localhost +RABBITMQ_HOST=localhost RABBITMQ_PORT=5672 RABBITMQ_USERNAME=guest RABBITMQ_PASSWORD=guest diff --git a/src/building-blocks/configs/configs.js b/src/building-blocks/configs/configs.js index 1a08bef..a79d4a0 100644 --- a/src/building-blocks/configs/configs.js +++ b/src/building-blocks/configs/configs.js @@ -35,7 +35,7 @@ const envVarsSchema = joi_1.default.object() POSTGRES_PASSWORD: joi_1.default.string() .default('postgres') .description('Postgres password'), - POSTGRES_Database: joi_1.default.string() + POSTGRES_DATABASE: joi_1.default.string() .default('default_database') .description('Postgres database name'), POSTGRES_SYNCHRONIZE: joi_1.default.boolean() @@ -52,7 +52,7 @@ const envVarsSchema = joi_1.default.object() POSTGRES_MIGRATIONS_RUN: joi_1.default.boolean() .default(false) .description('Run migrations after running project'), - RABBITMQ_Host: joi_1.default.string() + RABBITMQ_HOST: joi_1.default.string() .default('localhost') .description('Rabbitmq host'), RABBITMQ_PORT: joi_1.default.number().default(5672).description('Rabbitmq port'), @@ -92,7 +92,7 @@ exports.default = { serviceName: envVars.SERVICE_NAME, port: envVars.PORT, rabbitmq: { - host: envVars.RABBITMQ_Host, + host: envVars.RABBITMQ_HOST, port: envVars.RABBITMQ_PORT, username: envVars.RABBITMQ_USERNAME, password: envVars.RABBITMQ_PASSWORD, @@ -103,7 +103,7 @@ exports.default = { port: envVars.POSTGRES_PORT, username: envVars.POSTGRES_USERNAME, password: envVars.POSTGRES_PASSWORD, - database: envVars.POSTGRES_Database, + database: envVars.POSTGRES_DATABASE, synchronize: envVars.POSTGRES_SYNCHRONIZE, autoLoadEntities: envVars.POSTGRES_AUTO_LOAD_ENTITIES, entities: envVars.POSTGRES_ENTITIES, diff --git a/src/building-blocks/configs/configs.ts b/src/building-blocks/configs/configs.ts index 4d28974..c892e5b 100644 --- a/src/building-blocks/configs/configs.ts +++ b/src/building-blocks/configs/configs.ts @@ -35,7 +35,7 @@ const envVarsSchema = Joi.object() POSTGRES_PASSWORD: Joi.string() .default('postgres') .description('Postgres password'), - POSTGRES_Database: Joi.string() + POSTGRES_DATABASE: Joi.string() .default('default_database') .description('Postgres database name'), POSTGRES_SYNCHRONIZE: Joi.boolean() @@ -52,7 +52,7 @@ const envVarsSchema = Joi.object() POSTGRES_MIGRATIONS_RUN: Joi.boolean() .default(false) .description('Run migrations after running project'), - RABBITMQ_Host: Joi.string() + RABBITMQ_HOST: Joi.string() .default('localhost') .description('Rabbitmq host'), RABBITMQ_PORT: Joi.number().default(5672).description('Rabbitmq port'), @@ -95,7 +95,7 @@ export default { serviceName: envVars.SERVICE_NAME, port: envVars.PORT, rabbitmq: { - host: envVars.RABBITMQ_Host, + host: envVars.RABBITMQ_HOST, port: envVars.RABBITMQ_PORT, username: envVars.RABBITMQ_USERNAME, password: envVars.RABBITMQ_PASSWORD, @@ -106,7 +106,7 @@ export default { port: envVars.POSTGRES_PORT, username: envVars.POSTGRES_USERNAME, password: envVars.POSTGRES_PASSWORD, - database: envVars.POSTGRES_Database, + database: envVars.POSTGRES_DATABASE, synchronize: envVars.POSTGRES_SYNCHRONIZE, autoLoadEntities: envVars.POSTGRES_AUTO_LOAD_ENTITIES, entities: envVars.POSTGRES_ENTITIES, diff --git a/src/flight/.env.development b/src/flight/.env.development index a5c7afa..a9a834c 100644 --- a/src/flight/.env.development +++ b/src/flight/.env.development @@ -17,14 +17,14 @@ POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_USERNAME=postgres POSTGRES_PASSWORD=postgres -POSTGRES_Database=flight -POSTGRES_SYNCHRONIZE =false +POSTGRES_DATABASE=flight +POSTGRES_SYNCHRONIZE=false POSTGRES_ENTITIES=/../**/*.entity.{js,ts} POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} POSTGRES_MIGRATIONS_RUN=true # Rabbitmq -RABBITMQ_Host=localhost +RABBITMQ_HOST=localhost RABBITMQ_PORT=5672 RABBITMQ_USERNAME=guest RABBITMQ_PASSWORD=guest diff --git a/src/identity/.env.development b/src/identity/.env.development index 46844bd..08d69fb 100644 --- a/src/identity/.env.development +++ b/src/identity/.env.development @@ -17,14 +17,14 @@ POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_USERNAME=postgres POSTGRES_PASSWORD=postgres -POSTGRES_Database=identity -POSTGRES_SYNCHRONIZE =false +POSTGRES_DATABASE=identity +POSTGRES_SYNCHRONIZE=false POSTGRES_ENTITIES=/../**/*.entity.{js,ts} POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} POSTGRES_MIGRATIONS_RUN=true # Rabbitmq -RABBITMQ_Host=localhost +RABBITMQ_HOST=localhost RABBITMQ_PORT=5672 RABBITMQ_USERNAME=guest RABBITMQ_PASSWORD=guest @@ -38,4 +38,4 @@ RETRY_MAX_TIMEOUT=60000 # Monitoring MONITORING_JAEGER_ENDPOINT=http://localhost:14268/api/traces -MONITORING_ZIPKIN_ENDPOINT=http://zipkin-server:9411/api/v2/spans +MONITORING_ZIPKIN_ENDPOINT=http://zipkin-server:9411/api/v2/spans \ No newline at end of file diff --git a/src/identity/.env.test b/src/identity/.env.test index 45665fa..c3beef9 100644 --- a/src/identity/.env.test +++ b/src/identity/.env.test @@ -17,8 +17,8 @@ POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_USERNAME=postgres POSTGRES_PASSWORD=postgres -POSTGRES_Database=identity_test -POSTGRES_SYNCHRONIZE =true +POSTGRES_DATABASE=identity_test +POSTGRES_SYNCHRONIZE=true POSTGRES_MIGRATIONS_RUN=false # Rabbitmq diff --git a/src/passenger/.env.development b/src/passenger/.env.development index fac56d3..30ba241 100644 --- a/src/passenger/.env.development +++ b/src/passenger/.env.development @@ -17,14 +17,14 @@ POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_USERNAME=postgres POSTGRES_PASSWORD=postgres -POSTGRES_Database=passenger -POSTGRES_SYNCHRONIZE =false +POSTGRES_DATABASE=passenger +POSTGRES_SYNCHRONIZE=false POSTGRES_ENTITIES=/../**/*.entity.{js,ts} POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} POSTGRES_MIGRATIONS_RUN=true # Rabbitmq -RABBITMQ_Host=localhost +RABBITMQ_HOST=localhost RABBITMQ_PORT=5672 RABBITMQ_USERNAME=guest RABBITMQ_PASSWORD=guest From ab4eac1d051c013e7f9f278ddd60e467db0558be Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:45:06 +0200 Subject: [PATCH 05/10] feat: added generic Dockerfile that can be used to build and run every service --- src/Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/Dockerfile diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 0000000..0eefca8 --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,38 @@ +FROM node:21.7-alpine + +# Install NestJS CLI tool +RUN npm install -g @nestjs/cli + +# Switch to non-root user +USER node + +# Get build target +ARG TARGET +ENV BLOCKS=building-blocks + +# Define env variables for workdirs +ENV WORKDIR_BASE=/usr/src/app +ENV WORKDIR_BLOCKS=${WORKDIR_BASE}/${BLOCKS} +ENV WORKDIR_TARGET=${WORKDIR_BASE}/${TARGET} + +# Build utility package +WORKDIR ${WORKDIR_BLOCKS} +COPY --chown=node:node ./src/${BLOCKS}/package*.json . +RUN npm install +COPY --chown=node:node ./src/${BLOCKS} . +RUN npm run build + +# Build target package +WORKDIR ${WORKDIR_TARGET} +COPY --chown=node:node ./src/${TARGET}/package*.json . +RUN npm install +COPY --chown=node:node ./src/${TARGET} . +RUN npm run build + +# Run the app (target) +CMD exec npm run dev + +# ARG NODE_ENV +# ENV NODE_ENV=${NODE_ENV:-dev} +# # start, start:dev, start:debug, start:prod +# # CMD exec yarn start:${NODE_ENV} \ No newline at end of file From 9d9172b310c2fac669a67403971afaea865e7144 Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:46:04 +0200 Subject: [PATCH 06/10] feat: added a name to the docker network, and a reminder that postgresql databases should be created --- deployments/docker-compose/infrastructure.yaml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/deployments/docker-compose/infrastructure.yaml b/deployments/docker-compose/infrastructure.yaml index d3c19a3..1de397a 100644 --- a/deployments/docker-compose/infrastructure.yaml +++ b/deployments/docker-compose/infrastructure.yaml @@ -18,6 +18,14 @@ services: ####################################################### # Postgress ####################################################### + # + # TODO + # psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" + # CREATE DATABASE identity; GRANT ALL PRIVILEGES ON DATABASE identity TO postgres; + # CREATE DATABASE flight; GRANT ALL PRIVILEGES ON DATABASE flight TO postgres; + # CREATE DATABASE booking; GRANT ALL PRIVILEGES ON DATABASE booking TO postgres; + # CREATE DATABASE passenger; GRANT ALL PRIVILEGES ON DATABASE passenger TO postgres; + # postgres: container_name: postgres image: postgres:latest @@ -30,7 +38,6 @@ services: networks: - booking - ####################################################### # Jaeger ####################################################### @@ -64,7 +71,4 @@ services: networks: booking: - - - - + name: bmn_network From 470a474512919086bb5278c2e3a71bc0afd9e58c Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:46:46 +0200 Subject: [PATCH 07/10] feat: added a compose file to build and run all services --- .../docker-compose/compose.services.yaml | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 deployments/docker-compose/compose.services.yaml diff --git a/deployments/docker-compose/compose.services.yaml b/deployments/docker-compose/compose.services.yaml new file mode 100644 index 0000000..d3b2e83 --- /dev/null +++ b/deployments/docker-compose/compose.services.yaml @@ -0,0 +1,83 @@ +version: "3.3" +services: + + ####################################################### + # Identities + ####################################################### + identity: + container_name: bmn-identity + build: + context: ../../ + dockerfile: ./src/Dockerfile + args: + TARGET: identity + restart: unless-stopped + ports: + - 3333:3333 + environment: + # Used to select which .env file should be used + - NODE_ENV=devdocker + networks: + - booking + + ####################################################### + # Passengers + ####################################################### + passenger: + container_name: bmn-passenger + build: + context: ../../ + dockerfile: ./src/Dockerfile + args: + TARGET: passenger + restart: unless-stopped + ports: + - 3355:3355 + environment: + # Used to select which .env file should be used + - NODE_ENV=devdocker + networks: + - booking + + ####################################################### + # Flights + ####################################################### + flight: + container_name: bmn-flight + build: + context: ../../ + dockerfile: ./src/Dockerfile + args: + TARGET: flight + restart: unless-stopped + ports: + - 3344:3344 + environment: + # Used to select which .env file should be used + - NODE_ENV=devdocker + networks: + - booking + + ####################################################### + # Bookings + ####################################################### + booking: + container_name: bmn-booking + build: + context: ../../ + dockerfile: ./src/Dockerfile + args: + TARGET: booking + restart: unless-stopped + ports: + - 3366:3366 + environment: + # Used to select which .env file should be used + - NODE_ENV=devdocker + networks: + - booking + +networks: + booking: + name: bmn_network + external: true From 7d51cfdc962ae3a16aa219763de5c18ae29a5e41 Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:47:17 +0200 Subject: [PATCH 08/10] feat: new env file to use with docker setup (use containers hostnames) --- src/booking/.env.devdocker | 41 ++++++++++++++++++++++++++++++++++++ src/flight/.env.devdocker | 41 ++++++++++++++++++++++++++++++++++++ src/identity/.env.devdocker | 41 ++++++++++++++++++++++++++++++++++++ src/passenger/.env.devdocker | 41 ++++++++++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 src/booking/.env.devdocker create mode 100644 src/flight/.env.devdocker create mode 100644 src/identity/.env.devdocker create mode 100644 src/passenger/.env.devdocker diff --git a/src/booking/.env.devdocker b/src/booking/.env.devdocker new file mode 100644 index 0000000..74901ff --- /dev/null +++ b/src/booking/.env.devdocker @@ -0,0 +1,41 @@ +# Environment +NODE_ENV=devdocker + +# Service +SERVICE_NAME="BOOKING SERVICE - ONLINE" + +# Port number +PORT=3366 + +# JWT +JWT_SECRET=thisisafakesecretchangeit +JWT_ACCESS_EXPIRATION_MINUTES=30 +JWT_REFRESH_EXPIRATION_DAYS=1 + +# Postgress +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_USERNAME=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_DATABASE=booking +POSTGRES_SYNCHRONIZE=false +POSTGRES_ENTITIES=/../**/*.entity.{js,ts} +POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} +POSTGRES_MIGRATIONS_RUN=true + +# Rabbitmq +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_USERNAME=guest +RABBITMQ_PASSWORD=guest +RABBITMQ_EXCHANGE=booking + +# RETRY +RETRY_COUNT=3 +RETRY_FACTOR=2 +RETRY_MIN_TIMEOUT=1000 +RETRY_MAX_TIMEOUT=60000 + +# Monitoring +MONITORING_JAEGER_ENDPOINT=http://jaeger:14268/api/traces +MONITORING_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans diff --git a/src/flight/.env.devdocker b/src/flight/.env.devdocker new file mode 100644 index 0000000..48bb7a9 --- /dev/null +++ b/src/flight/.env.devdocker @@ -0,0 +1,41 @@ +# Environment +NODE_ENV=devdocker + +# Service +SERVICE_NAME="FLIGHT SERVICE - ONLINE" + +# Port number +PORT=3344 + +# JWT +JWT_SECRET=thisisafakesecretchangeit +JWT_ACCESS_EXPIRATION_MINUTES=30 +JWT_REFRESH_EXPIRATION_DAYS=1 + +# Postgress +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_USERNAME=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_DATABASE=flight +POSTGRES_SYNCHRONIZE=false +POSTGRES_ENTITIES=/../**/*.entity.{js,ts} +POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} +POSTGRES_MIGRATIONS_RUN=true + +# Rabbitmq +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_USERNAME=guest +RABBITMQ_PASSWORD=guest +RABBITMQ_EXCHANGE=flight + +# RETRY +RETRY_COUNT=3 +RETRY_FACTOR=2 +RETRY_MIN_TIMEOUT=1000 +RETRY_MAX_TIMEOUT=60000 + +# Monitoring +MONITORING_JAEGER_ENDPOINT=http://jaeger:14268/api/traces +MONITORING_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans diff --git a/src/identity/.env.devdocker b/src/identity/.env.devdocker new file mode 100644 index 0000000..02d5924 --- /dev/null +++ b/src/identity/.env.devdocker @@ -0,0 +1,41 @@ +# Environment +NODE_ENV=devdocker + +# Service +SERVICE_NAME="IDENTITY SERVICE - ONLINE" + +# Port number +PORT=3333 + +# JWT +JWT_SECRET=thisisafakesecretchangeit +JWT_ACCESS_EXPIRATION_MINUTES=30 +JWT_REFRESH_EXPIRATION_DAYS=1 + +# Postgress +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_USERNAME=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_DATABASE=identity +POSTGRES_SYNCHRONIZE=false +POSTGRES_ENTITIES=/../**/*.entity.{js,ts} +POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} +POSTGRES_MIGRATIONS_RUN=true + +# Rabbitmq +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_USERNAME=guest +RABBITMQ_PASSWORD=guest +RABBITMQ_EXCHANGE=identity + +# RETRY +RETRY_COUNT=3 +RETRY_FACTOR=2 +RETRY_MIN_TIMEOUT=1000 +RETRY_MAX_TIMEOUT=60000 + +# Monitoring +MONITORING_JAEGER_ENDPOINT=http://jaeger:14268/api/traces +MONITORING_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans diff --git a/src/passenger/.env.devdocker b/src/passenger/.env.devdocker new file mode 100644 index 0000000..2f620e3 --- /dev/null +++ b/src/passenger/.env.devdocker @@ -0,0 +1,41 @@ +# Environment +NODE_ENV=devdocker + +# Service +SERVICE_NAME="PASSENGER SERVICE - ONLINE" + +# Port number +PORT=3355 + +# JWT +JWT_SECRET=thisisafakesecretchangeit +JWT_ACCESS_EXPIRATION_MINUTES=30 +JWT_REFRESH_EXPIRATION_DAYS=1 + +# Postgress +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_USERNAME=postgres +POSTGRES_PASSWORD=postgres +POSTGRES_DATABASE=passenger +POSTGRES_SYNCHRONIZE=false +POSTGRES_ENTITIES=/../**/*.entity.{js,ts} +POSTGRES_MIGRATIONS=/../**/data/migrations/*.{js,ts} +POSTGRES_MIGRATIONS_RUN=true + +# Rabbitmq +RABBITMQ_HOST=rabbitmq +RABBITMQ_PORT=5672 +RABBITMQ_USERNAME=guest +RABBITMQ_PASSWORD=guest +RABBITMQ_EXCHANGE=passenger + +# RETRY +RETRY_COUNT=3 +RETRY_FACTOR=2 +RETRY_MIN_TIMEOUT=1000 +RETRY_MAX_TIMEOUT=60000 + +# Monitoring +MONITORING_JAEGER_ENDPOINT=http://jaeger:14268/api/traces +MONITORING_ZIPKIN_ENDPOINT=http://zipkin:9411/api/v2/spans From 020471255edca19a7cddead08f728750b280ecde Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:48:50 +0200 Subject: [PATCH 09/10] refactor: renamed infrastructure compose file to be recognized by extensions (VSCode for example) --- .../{infrastructure.yaml => compose.infrastructure.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename deployments/docker-compose/{infrastructure.yaml => compose.infrastructure.yaml} (100%) diff --git a/deployments/docker-compose/infrastructure.yaml b/deployments/docker-compose/compose.infrastructure.yaml similarity index 100% rename from deployments/docker-compose/infrastructure.yaml rename to deployments/docker-compose/compose.infrastructure.yaml From 7cba3350e9b0352e4579a106cf1299b5ee0f9d29 Mon Sep 17 00:00:00 2001 From: Tom-Brian GARCIA Date: Fri, 19 Apr 2024 02:52:43 +0200 Subject: [PATCH 10/10] feat: updated readme to match docker setup modifications --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6e0523b..ed4012d 100644 --- a/README.md +++ b/README.md @@ -162,13 +162,12 @@ npm run migration:run > ### Docker Compose -Use the command below to run our `infrastructure` with `docker` using the [infrastructure.yaml](./deployments/docker-compose/infrastructure.yaml) file at the `root` of the app: +Use the commands below to run both `infrastructure` and `services` with `docker` using the `compose.taml` files located in the [associated directory](./deployments/docker-compose/) : ```bash -docker-compose -f ./deployments/docker-compose/infrastructure.yaml up -d +docker-compose -f ./deployments/docker-compose/compose.infrastructure.yaml up -d +docker-compose -f ./deployments/docker-compose/compose.services.yaml up -d ``` -##### Todo -I will add `docker-compsoe` for up and running whole app here in the next... > ### Build To `build` each microservice, run this command in the root directory of each microservice where the `package.json` file is located: