Skip to content

Commit b6ae443

Browse files
committed
Docker image
Added Docker file and docker compose file Modification to build and run as docker container.
1 parent b34bc3e commit b6ae443

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

.Dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.git/
2+
.github/
3+
.idea/
4+
.yarn/
5+
coverage/
6+
dist/
7+
node_modules/
8+
test/
9+

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:20 AS build
2+
3+
WORKDIR /usr/src
4+
5+
COPY package.json yarn.lock ./
6+
RUN yarn
7+
8+
COPY . .
9+
RUN yarn build
10+
11+
FROM node:20-alpine
12+
WORKDIR /app
13+
14+
RUN npm install -g pm2
15+
16+
COPY package.json yarn.lock ./
17+
RUN yarn --production
18+
19+
COPY --from=build /usr/src/dist ./
20+
21+
EXPOSE 3000
22+
CMD ["pm2-runtime", "main.js"]

docker-compose.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: '3.8'
2+
3+
services:
4+
mongo:
5+
image: mongo:8
6+
ports:
7+
- "27017:27017"
8+
volumes:
9+
- mongo-data:/data/db
10+
11+
engine:
12+
build: .
13+
ports:
14+
- "3000:3000"
15+
depends_on:
16+
- mongo
17+
environment:
18+
- DB=mongodb://mongo:27017/letsflow
19+
volumes:
20+
- ./scenarios:/app/scenarios:ro
21+
- ./schemas:/app/schemas:ro
22+
23+
volumes:
24+
mongo-data:
25+

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,5 @@
8787
},
8888
"coverageDirectory": "../coverage",
8989
"testEnvironment": "node"
90-
},
91-
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
90+
}
9291
}

src/app.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Injectable, OnModuleInit } from '@nestjs/common';
22
import { ConfigService } from './common/config/config.service';
33
import Ajv from 'ajv';
4+
import * as path from 'path';
5+
import * as fs from 'fs';
46

57
@Injectable()
68
export class AppService implements OnModuleInit {
@@ -22,8 +24,8 @@ export class AppService implements OnModuleInit {
2224
}
2325

2426
private initInfo() {
25-
// eslint-disable-next-line @typescript-eslint/no-var-requires
26-
const packageInfo = require('../package.json');
27+
const packagePath = path.join(process.cwd(), 'package.json');
28+
const packageInfo = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
2729

2830
this.info = {
2931
name: packageInfo.name,

src/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { INestApplication } from '@nestjs/common';
44
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
55
import { ConfigService } from './common/config/config.service';
66
import { NestExpressApplication } from '@nestjs/platform-express';
7+
import * as path from 'path';
8+
import * as fs from 'fs';
79

810
async function swagger(app: INestApplication, config: ConfigService) {
9-
// eslint-disable-next-line @typescript-eslint/no-var-requires
10-
const { description, version } = require('../package.json');
11+
const packagePath = path.join(process.cwd(), 'package.json');
12+
const { description, version } = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
1113

1214
const options = new DocumentBuilder()
1315
.setTitle('LetsFlow')

0 commit comments

Comments
 (0)