diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 3461a35..301e91a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -27,6 +27,12 @@ jobs: docker build -f apps/api/Dockerfile --target production -t crypitor/crypitor-api:master . docker push crypitor/crypitor-api:master + - name: Build and push Polling block Docker image + run: | + cd app + docker build -f apps/polling-block/Dockerfile --target production -t crypitor/crypitor-polling-block:master . + docker push crypitor/crypitor-polling-block:master + - name: Build and push Monitor Docker image run: | cd app diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b45138..16c2288 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,6 +29,14 @@ jobs: docker push crypitor/crypitor-api:${VERSION} docker push crypitor/crypitor-api:latest + - name: Build and push Api Docker image + run: | + cd app + VERSION=$(jq -r '.version' package.json) + docker build -f apps/polling-block/Dockerfile --target production -t crypitor/crypitor-polling-block:${VERSION} -t crypitor/crypitor-polling-block:latest . + docker push crypitor/crypitor-polling-block:${VERSION} + docker push crypitor/crypitor-polling-block:latest + - name: Build and push Monitor Docker image run: | cd app diff --git a/app/Makefile b/app/Makefile index a8bd253..7561c0c 100644 --- a/app/Makefile +++ b/app/Makefile @@ -59,7 +59,7 @@ stop-dev: .PHONY: shell shell: - @docker exec -ti api /bin/sh + @docker compose exec -ti api /bin/sh .PHONY: shell-db shell-db: diff --git a/app/apps/api/src/api.module.ts b/app/apps/api/src/api.module.ts index d8559d8..b4a7e21 100644 --- a/app/apps/api/src/api.module.ts +++ b/app/apps/api/src/api.module.ts @@ -4,7 +4,6 @@ import { ApiService } from './api.service'; import { ConfigModule } from '@nestjs/config'; import { MonitorApiModule } from './modules/monitor/monitor.api.module'; import { MonitorAddressApiModule } from './modules/address/address.module'; -import { PollingBlockModule } from './modules/polling.block/polling.block.module'; import { EventHistoryApiModule } from './modules/event_history/event_history.module'; import { DeliveryApiModule } from './modules/delivery/delivery.api.module'; import { GlobalModule } from 'libs'; @@ -21,7 +20,6 @@ import { GlobalModule } from 'libs'; MonitorAddressApiModule, EventHistoryApiModule, DeliveryApiModule, - PollingBlockModule, ], controllers: [ApiController], providers: [ApiService], diff --git a/app/apps/polling-block/Dockerfile b/app/apps/polling-block/Dockerfile new file mode 100644 index 0000000..2e3a70e --- /dev/null +++ b/app/apps/polling-block/Dockerfile @@ -0,0 +1,26 @@ +FROM node:18-alpine As development + +WORKDIR /usr/src/app + +COPY package.json yarn.lock ./ + +RUN yarn + +COPY . . + +CMD yarn start:dev polling-block + +FROM node:18-alpine as production + +ARG NODE_ENV=production +ENV NODE_ENV=${NODE_ENV} + +WORKDIR /usr/src/app + +COPY package*.json yarn.lock ./ + +RUN yarn install --production + +COPY ./dist/apps/polling-block ./dist/apps/polling-block + +CMD ["node", "dist/apps/polling-block/main.js"] \ No newline at end of file diff --git a/app/apps/api/src/modules/polling.block/avax.polling.block.service.ts b/app/apps/polling-block/src/evm/avax.polling.block.service.ts similarity index 100% rename from app/apps/api/src/modules/polling.block/avax.polling.block.service.ts rename to app/apps/polling-block/src/evm/avax.polling.block.service.ts diff --git a/app/apps/api/src/modules/polling.block/bsc.polling.block.service.ts b/app/apps/polling-block/src/evm/bsc.polling.block.service.ts similarity index 100% rename from app/apps/api/src/modules/polling.block/bsc.polling.block.service.ts rename to app/apps/polling-block/src/evm/bsc.polling.block.service.ts diff --git a/app/apps/api/src/modules/polling.block/ethereum.polling.block.service.ts b/app/apps/polling-block/src/evm/ethereum.polling.block.service.ts similarity index 100% rename from app/apps/api/src/modules/polling.block/ethereum.polling.block.service.ts rename to app/apps/polling-block/src/evm/ethereum.polling.block.service.ts diff --git a/app/apps/api/src/modules/polling.block/mantle.polling.block.service.ts b/app/apps/polling-block/src/evm/mantle.polling.block.service.ts similarity index 100% rename from app/apps/api/src/modules/polling.block/mantle.polling.block.service.ts rename to app/apps/polling-block/src/evm/mantle.polling.block.service.ts diff --git a/app/apps/api/src/modules/polling.block/polygon.polling.block.service.ts b/app/apps/polling-block/src/evm/polygon.polling.block.service.ts similarity index 100% rename from app/apps/api/src/modules/polling.block/polygon.polling.block.service.ts rename to app/apps/polling-block/src/evm/polygon.polling.block.service.ts diff --git a/app/apps/polling-block/src/main.ts b/app/apps/polling-block/src/main.ts new file mode 100644 index 0000000..96f3ad6 --- /dev/null +++ b/app/apps/polling-block/src/main.ts @@ -0,0 +1,11 @@ +import { NestFactory } from '@nestjs/core'; +import { PollingBlockModule } from './polling-block.module'; +import { MicroserviceOptions } from '@nestjs/microservices'; + +async function bootstrap() { + const app = await NestFactory.createMicroservice( + PollingBlockModule, + ); + await app.listen(); +} +bootstrap(); diff --git a/app/apps/api/src/modules/polling.block/polling.block.module.ts b/app/apps/polling-block/src/polling-block.module.ts similarity index 73% rename from app/apps/api/src/modules/polling.block/polling.block.module.ts rename to app/apps/polling-block/src/polling-block.module.ts index 054afd6..0feedb8 100644 --- a/app/apps/api/src/modules/polling.block/polling.block.module.ts +++ b/app/apps/polling-block/src/polling-block.module.ts @@ -2,14 +2,20 @@ import { Module } from '@nestjs/common'; import { ClientsModule, Transport } from '@nestjs/microservices'; import { ScheduleModule } from '@nestjs/schedule'; import { BlockSyncModelModule } from 'libs'; -import { AvaxPollingBlockService } from './avax.polling.block.service'; -import { BscPollingBlockService } from './bsc.polling.block.service'; -import { EthereumPollingBlockService } from './ethereum.polling.block.service'; -import { MantlePollingBlockService } from './mantle.polling.block.service'; -import { PolygonPollingBlockService } from './polygon.polling.block.service'; +import { EthereumPollingBlockService } from './evm/ethereum.polling.block.service'; +import { PolygonPollingBlockService } from './evm/polygon.polling.block.service'; +import { AvaxPollingBlockService } from './evm/avax.polling.block.service'; +import { MantlePollingBlockService } from './evm/mantle.polling.block.service'; +import { BscPollingBlockService } from './evm/bsc.polling.block.service'; +import { ConfigModule } from '@nestjs/config'; @Module({ imports: [ + ConfigModule.forRoot({ + isGlobal: true, + envFilePath: [`${process.env.NODE_ENV}.env`, '.env'], + expandVariables: true, + }), ClientsModule.registerAsync([ { name: 'WORKER_CLIENT_SERVICE', diff --git a/app/apps/polling-block/tsconfig.app.json b/app/apps/polling-block/tsconfig.app.json new file mode 100644 index 0000000..5b2667b --- /dev/null +++ b/app/apps/polling-block/tsconfig.app.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": false, + "outDir": "../../dist/apps/polling-block" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] +} diff --git a/app/docker-compose-dev.yml b/app/docker-compose-dev.yml index 68b21ee..72d86d6 100644 --- a/app/docker-compose-dev.yml +++ b/app/docker-compose-dev.yml @@ -25,6 +25,19 @@ services: condition: service_healthy kafka: condition: service_healthy + polling-block: + container_name: polling-block + build: + context: . + target: ${TARGET:-development} + dockerfile: ./apps/polling-block/Dockerfile + volumes: + - .:/usr/src/app + - /usr/src/app/node_modules + env_file: + - .env.docker + networks: + crypitor-network: monitor: container_name: monitor build: diff --git a/app/docker/docker-compose.yml b/app/docker/docker-compose.yml index 551fddc..5f9423f 100644 --- a/app/docker/docker-compose.yml +++ b/app/docker/docker-compose.yml @@ -18,6 +18,21 @@ services: condition: service_healthy extra_hosts: - 'host.docker.internal:host-gateway' + polling-block: + image: crypitor/crypitor-polling-block:${VERSION:-latest} + env_file: + - .env + networks: + crypitor-network: + aliases: + - polling-block + depends_on: + mongo: + condition: service_healthy + kafka: + condition: service_healthy + extra_hosts: + - 'host.docker.internal:host-gateway' monitor: image: crypitor/crypitor-monitor:${VERSION:-latest} env_file: diff --git a/app/nest-cli.json b/app/nest-cli.json index 12130c5..f45d4de 100644 --- a/app/nest-cli.json +++ b/app/nest-cli.json @@ -71,6 +71,15 @@ "compilerOptions": { "tsConfigPath": "libs/shared_modules/tsconfig.lib.json" } + }, + "polling-block": { + "type": "application", + "root": "apps/polling-block", + "entryFile": "main", + "sourceRoot": "apps/polling-block/src", + "compilerOptions": { + "tsConfigPath": "apps/polling-block/tsconfig.app.json" + } } } -} +} \ No newline at end of file diff --git a/app/package.json b/app/package.json index 0a98fa1..66facfd 100644 --- a/app/package.json +++ b/app/package.json @@ -7,8 +7,9 @@ "license": "MIT", "scripts": { "prebuild": "rimraf dist", - "build": "yarn build:app && yarn build:worker && yarn build:monitor", + "build": "yarn build:app && yarn build:polling && yarn build:worker && yarn build:monitor", "build:app": "npx nest build api", + "build:polling": "npx nest build polling-block", "build:worker": "npx nest build worker-service", "build:monitor": "npx nest build monitor-service", "format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"", @@ -16,6 +17,7 @@ "start:dev": "npx nest start --watch", "start:debug": "npx nest start --debug 0.0.0.0:9229 --watch", "start:prod": "node dist/apps/api/main", + "start:prod:polling": "node dist/apps/polling-block/main", "start:prod:monitor": "node dist/apps/monitor-service/main", "start:prod:worker": "node dist/apps/worker-service/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", @@ -136,4 +138,4 @@ "url": "https://github.com/crypitor/blockchain-webhook/issues" }, "homepage": "https://github.com/crypitor/blockchain-webhook#readme" -} +} \ No newline at end of file