Skip to content

Commit b703725

Browse files
committed
feat: docker build added for backend
1 parent ee53ec3 commit b703725

File tree

12 files changed

+82
-13
lines changed

12 files changed

+82
-13
lines changed

api_gateway/.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
.git
3+
.gitignore
4+
*.md
5+
dist
6+
Dockerfile
7+
README.md

api_gateway/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:20.15.0-alpine3.19 AS base
2+
ENV PNPM_HOME="/pnpm"
3+
ENV PATH="$PNPM_HOME:$PATH"
4+
RUN corepack enable
5+
COPY . /app
6+
WORKDIR /app
7+
8+
FROM base AS prod-deps
9+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
10+
11+
FROM base AS build
12+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
13+
RUN npx prisma generate
14+
RUN pnpm run build
15+
16+
FROM base
17+
LABEL author="Azraf Al Monzim"
18+
LABEL maintainer="Azraf Al Monzim"
19+
20+
COPY --from=prod-deps /app/node_modules /app/node_modules
21+
COPY --from=build /app/node_modules/.prisma/client /app/node_modules/@prisma/client
22+
COPY --from=build /app/dist /app/dist
23+
24+
EXPOSE 3000
25+
CMD [ "pnpm", "start:prod" ]

api_gateway/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
generator client {
22
provider = "prisma-client-js"
3+
output = "../node_modules/.prisma/client"
34
}
45

56
datasource db {

api_gateway/test/app.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Test, TestingModule } from '@nestjs/testing';
21
import { INestApplication } from '@nestjs/common';
2+
import { Test, TestingModule } from '@nestjs/testing';
3+
import { AppModule } from 'src/app.module';
34
import * as request from 'supertest';
4-
import { AppModule } from '../src/app.module';
55

66
describe('AppController (e2e)', () => {
77
let app: INestApplication;

sync_service/.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
.git
3+
.gitignore
4+
*.md
5+
dist
6+
Dockerfile
7+
README.md

sync_service/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RABBITMQ_QUEUE=""
2+
RABBITMQ_URL=""
3+
DATABASE_URL=""
4+
DATABASE_URL_DRIZZLE=""

sync_service/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM node:20.15.0-alpine3.19 AS base
2+
ENV PNPM_HOME="/pnpm"
3+
ENV PATH="$PNPM_HOME:$PATH"
4+
RUN corepack enable
5+
COPY . /app
6+
WORKDIR /app
7+
8+
FROM base AS prod-deps
9+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
10+
11+
FROM base AS build
12+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
13+
RUN npx prisma generate
14+
RUN pnpm run build
15+
16+
FROM base
17+
LABEL author="Azraf Al Monzim"
18+
LABEL maintainer="Azraf Al Monzim"
19+
20+
COPY --from=prod-deps /app/node_modules /app/node_modules
21+
COPY --from=build /app/node_modules/.prisma/client /app/node_modules/@prisma/client
22+
COPY --from=build /app/dist /app/dist
23+
24+
EXPOSE 3000
25+
CMD [ "pnpm", "start:prod" ]

sync_service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start": "nest start",
1212
"start:dev": "nest start --watch",
1313
"start:debug": "nest start --debug --watch",
14-
"start:prod": "node dist/main",
14+
"start:prod": "node dist/src/main",
1515
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
1616
"test": "jest",
1717
"test:watch": "jest --watch",

sync_service/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
generator client {
22
provider = "prisma-client-js"
3+
output = "../node_modules/.prisma/client"
34
}
45

56
datasource db {

sync_service/src/main.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { AppModule } from './app.module';
55
async function bootstrap() {
66
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
77
AppModule,
8-
{
9-
transport: Transport.RMQ,
10-
options: {
11-
urls: [process.env.RABBITMQ_URL],
12-
queue: process.env.RABBITMQ_QUEUE,
13-
},
14-
},
8+
// {
9+
// transport: Transport.RMQ,
10+
// options: {
11+
// urls: [process.env.RABBITMQ_URL],
12+
// queue: process.env.RABBITMQ_QUEUE,
13+
// },
14+
// },
1515
);
1616

1717
await app.listen();

0 commit comments

Comments
 (0)