Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health check #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions apps/agri-dex-beckn/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and Deploy

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [main]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
container: node:14

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Build and Publish to Github Packages Registry
uses: elgohr/Publish-Docker-Github-Action@master
# env:
# NEXT_PUBLIC_BACKEND_URL: ${{ secrets.APP_NEXT_PUBLIC_BACKEND_URL }}
# NEXT_PUBLIC_META_API_KEY: ${{ secrets.APP_NEXT_PUBLIC_META_API_KEY }}
# with:
# name: my_github_username/my_repository_name/my_image_name
# registry: ghcr.io
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets. GITHUB_TOKEN }}
# dockerfile: Dockerfile
# buildargs: NEXT_PUBLIC_BACKEND_URL,NEXT_PUBLIC_META_API_KEY
# tags: latest


3 changes: 3 additions & 0 deletions apps/agri-dex-beckn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ WORKDIR /app
COPY package*.json ./
RUN yarn
COPY . .
HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD curl -f http://localhost:3003/health || exit 1
CMD ["yarn","test"]
CMD ["yarn", "start", "agri-dex-beckn"]
7 changes: 6 additions & 1 deletion apps/agri-dex-beckn/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ describe('AppController', () => {
appController = app.get<AppController>(AppController);
});

// describe('root', () => {
// it('should return "Hello World!"', () => {
// expect(appController.getHello()).toBe('Hello World!');
// });
// });
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
expect(appController.checkHealth()).toBe('Hello World!');
});
});
});
31 changes: 29 additions & 2 deletions apps/agri-dex-beckn/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,45 @@ import { Body, Controller, Get, Post, Req, Res } from '@nestjs/common';
import { AppService } from './app.service';
import { Request, Response } from 'express';
import { AppGateway } from './app.gateway';

import {
HealthCheck,
HealthCheckService,
HttpHealthIndicator,
} from '@nestjs/terminus';
import { ConfigService } from '@nestjs/config';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
private readonly appGateway: AppGateway,
) { }
private http: HttpHealthIndicator,
private configService: ConfigService,
private healthCheckService: HealthCheckService,
) {}

@Get()
getHello(): string {
return this.appService.getHello();
}
@Get('/health')
@HealthCheck()
@ApiOperation({ summary: 'Get Health Check Status' })
@ApiResponse({
status: 200,
description: 'Result Report for All the Health Check Services',
})
async checkHealth() {
return this.healthCheckService.check([
async () =>
this.http.pingCheck(
'Basic Check',
`http://localhost:${
this.configService.get<number>('AGRI_DEX_BECKN_PORT') || 3003
}/api`,
),
]);
}

@Post('orders')
getUserOrders(@Body() body: any) {
Expand Down
9 changes: 5 additions & 4 deletions apps/agri-dex-beckn/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SelectModule } from './select/select.module';
import { InitModule } from './init/init.module';
import { ConfirmService } from './confirm/confirm.service';
import { ConfirmModule } from './confirm/confirm.module';
import { HttpModule, HttpService } from '@nestjs/axios';
import { HttpModule } from '@nestjs/axios';
import { AppGateway } from './app.gateway';
import { SearchService } from './search/search.service';
import { InitService } from './init/init.service';
Expand All @@ -17,17 +17,18 @@ import { TrackModule } from './track/track.module';
import { TrackService } from './track/track.service';
import { UpdateService } from './update/update.service';
import { SwaggerModule } from '@nestjs/swagger';

import { TerminusModule } from '@nestjs/terminus';
@Module({
imports: [
SearchModule,
ConfigModule.forRoot({ isGlobal: true }),
SelectModule,
InitModule,
ConfirmModule,
HttpModule,
UpdateModule,
TrackModule,
TerminusModule,
HttpModule,
],
controllers: [AppController],
providers: [
Expand All @@ -41,4 +42,4 @@ import { SwaggerModule } from '@nestjs/swagger';
UpdateService,
],
})
export class AppModule { }
export class AppModule {}
41 changes: 41 additions & 0 deletions apps/bap/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and Deploy

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [main]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
container: node:14

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Build and Publish to Github Packages Registry
uses: elgohr/Publish-Docker-Github-Action@master
# env:
# NEXT_PUBLIC_BACKEND_URL: ${{ secrets.APP_NEXT_PUBLIC_BACKEND_URL }}
# NEXT_PUBLIC_META_API_KEY: ${{ secrets.APP_NEXT_PUBLIC_META_API_KEY }}
# with:
# name: my_github_username/my_repository_name/my_image_name
# registry: ghcr.io
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets. GITHUB_TOKEN }}
# dockerfile: Dockerfile
# buildargs: NEXT_PUBLIC_BACKEND_URL,NEXT_PUBLIC_META_API_KEY
# tags: latest


3 changes: 3 additions & 0 deletions apps/bap/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ WORKDIR /app
COPY package*.json ./
RUN yarn
COPY . .
HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD curl -f http://localhost:3010/health || exit 1
CMD ["yarn","test"]
CMD ["yarn", "start", "bap"]
34 changes: 31 additions & 3 deletions apps/bap/src/bap.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
import { Body, Controller, Get, Post, Req, Res } from '@nestjs/common';
import { Request, Response } from 'express';
import { BapService } from './bap.service';

import {
HealthCheck,
HealthCheckService,
HttpHealthIndicator,
} from '@nestjs/terminus';
import { ConfigService } from '@nestjs/config';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
@Controller()
export class BapController {
constructor(private readonly bapService: BapService) { }
constructor(
private readonly bapService: BapService,
private http: HttpHealthIndicator,
private configService: ConfigService,
private healthCheckService: HealthCheckService,
) {}

@Get()
getHello(): string {
return this.bapService.getHello();
}

@Get('/health')
@HealthCheck()
@ApiOperation({ summary: 'Get Health Check Status' })
@ApiResponse({
status: 200,
description: 'Result Report for All the Health Check Services',
})
async checkHealth() {
return this.healthCheckService.check([
async () =>
this.http.pingCheck(
'Basic Check',
`http://localhost:${
this.configService.get<number>('BAP_PORT') || 3010
}/api`,
),
]);
}
@Post()
async handleInitialRequest(
@Req() req: Request,
Expand Down
5 changes: 3 additions & 2 deletions apps/bap/src/bap.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OnConfirmModule } from './on-confirm/on-confirm.module';
import { HttpModule } from '@nestjs/axios';
import { OnUpdateModule } from './on-update/on-update.module';
import { OnTrackModule } from './on-track/on-track.module';

import { TerminusModule } from '@nestjs/terminus';
@Module({
imports: [
SearchModule,
Expand All @@ -20,8 +20,9 @@ import { OnTrackModule } from './on-track/on-track.module';
HttpModule,
OnUpdateModule,
OnTrackModule,
TerminusModule,
],
controllers: [BapController],
providers: [BapService],
})
export class BapModule { }
export class BapModule {}
41 changes: 41 additions & 0 deletions apps/bg/.github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and Deploy

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
push:
branches: [main]
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
container: node:14

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Build and Publish to Github Packages Registry
uses: elgohr/Publish-Docker-Github-Action@master
# env:
# NEXT_PUBLIC_BACKEND_URL: ${{ secrets.APP_NEXT_PUBLIC_BACKEND_URL }}
# NEXT_PUBLIC_META_API_KEY: ${{ secrets.APP_NEXT_PUBLIC_META_API_KEY }}
# with:
# name: my_github_username/my_repository_name/my_image_name
# registry: ghcr.io
# username: ${{ secrets.USERNAME }}
# password: ${{ secrets. GITHUB_TOKEN }}
# dockerfile: Dockerfile
# buildargs: NEXT_PUBLIC_BACKEND_URL,NEXT_PUBLIC_META_API_KEY
# tags: latest


3 changes: 3 additions & 0 deletions apps/bg/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ WORKDIR /app
COPY package*.json ./
RUN yarn
COPY . .
HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD curl -f http://localhost:3001/health || exit 1
CMD ["yarn","test"]
CMD ["yarn", "start", "bg"]
33 changes: 31 additions & 2 deletions apps/bg/src/bg.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
import { Controller, Get } from '@nestjs/common';
import { BgService } from './bg.service';

import {
HealthCheck,
HealthCheckService,
HttpHealthIndicator,
} from '@nestjs/terminus';
import { ConfigService } from '@nestjs/config';
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
@Controller()
export class BgController {
constructor(private readonly bgService: BgService) {}
constructor(
private readonly bgService: BgService,
private http: HttpHealthIndicator,
private configService: ConfigService,
private healthCheckService: HealthCheckService,
) {}

@Get()
getHello(): string {
return this.bgService.getHello();
}
@Get('/health')
@HealthCheck()
@ApiOperation({ summary: 'Get Health Check Status' })
@ApiResponse({
status: 200,
description: 'Result Report for All the Health Check Services',
})
async checkHealth() {
return this.healthCheckService.check([
async () =>
this.http.pingCheck(
'Basic Check',
`http://localhost:${
this.configService.get<number>('BG_PORT') || 3001
}/api`,
),
]);
}
}
7 changes: 5 additions & 2 deletions apps/bg/src/bg.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { BgService } from './bg.service';
import { SearchModule } from './search/search.module';
import { OnSearchModule } from './on_search/on_search.module';
import { ConfigModule } from '@nestjs/config';

import { TerminusModule } from '@nestjs/terminus';
import { HttpModule } from '@nestjs/axios';
@Module({
imports: [
SearchModule,
OnSearchModule,
ConfigModule.forRoot({
isGlobal: true,
}),
TerminusModule,
HttpModule,
],
controllers: [BgController],
providers: [BgService],
})
export class BgModule { }
export class BgModule {}
Loading