Skip to content

Commit

Permalink
Change dockerfile to build and copy protos in first stage
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthecoder committed Jan 27, 2024
1 parent 8671ea8 commit 0d3bb6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
16 changes: 9 additions & 7 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ WORKDIR /app

COPY . .

RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
RUN apk add --update python3 make g++ protoc bash && rm -rf /var/cache/apk/*

RUN yarn global add node-gyp prisma

RUN chmod +x /app/packages/proto/gen_protos.sh

WORKDIR /app/packages/proto

RUN yarn install --frozen-lockfile
Expand All @@ -30,8 +32,6 @@ RUN yarn install --frozen-lockfile

FROM node:18 as gateway-dev

RUN apt update && apt install -y protobuf-compiler

WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules/
Expand All @@ -40,13 +40,13 @@ COPY --from=deps /app/packages/api-gateway/node_modules ./packages/node_modules/

COPY . .

COPY --from=deps /app/packages/proto/dist ./packages/proto/dist

WORKDIR /app/packages/api-gateway


FROM node:18 as auth-service-dev

RUN apt update && apt install -y protobuf-compiler

WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules/
Expand All @@ -55,13 +55,13 @@ COPY --from=deps /app/packages/auth-service/node_modules ./packages/node_modules

COPY . .

COPY --from=deps /app/packages/proto/dist ./packages/proto/dist

WORKDIR /app/packages/auth-service


FROM node:18 as db-service-dev

RUN apt update && apt install -y protobuf-compiler

WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules/
Expand All @@ -70,6 +70,8 @@ COPY --from=deps /app/packages/db-service/node_modules ./packages/node_modules/

COPY . .

COPY --from=deps /app/packages/proto/dist ./packages/proto/dist

RUN yarn global add prisma

WORKDIR /app/packages/db-service
Expand Down
9 changes: 6 additions & 3 deletions packages/db-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { AppModule } from './app.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { join } from 'path';
import { ConfigModule } from '@nestjs/config';
import { DBSERVICE_USER_PACKAGE_NAME } from 'juno-proto/src/gen/user';
import { DBSERVICE_PROJECT_PACKAGE_NAME } from 'juno-proto/src/gen/project';
import {
UserProtoFile,
ProjectProtoFile,
IdentifiersProtoFile,
UserProto,
ProjectProto,
} from 'juno-proto';

async function bootstrap() {
Expand All @@ -20,7 +20,10 @@ async function bootstrap() {
{
transport: Transport.GRPC,
options: {
package: [DBSERVICE_USER_PACKAGE_NAME, DBSERVICE_PROJECT_PACKAGE_NAME],
package: [
UserProto.DBSERVICE_USER_PACKAGE_NAME,
ProjectProto.DBSERVICE_PROJECT_PACKAGE_NAME,
],
protoPath: [UserProtoFile, ProjectProtoFile, IdentifiersProtoFile],
url: process.env.DB_SERVICE_ADDR,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/proto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "dist/main.js",
"license": "MIT",
"scripts": {
"build": "yarn gen-proto && yarn format && tsc && ncp ./definitions ./dist/definitions",
"build": "ls && yarn gen-proto && yarn format && tsc && ncp ./definitions ./dist/definitions",
"format": "prettier --write \"src/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
Expand All @@ -13,7 +13,7 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"tsc": "tsc && cp -r ./definitions ./dist/",
"gen-proto": "./gen_protos.sh"
"gen-proto": "bash ./gen_protos.sh"
},
"dependencies": {
"@nestjs/common": "^10.3.0",
Expand Down

0 comments on commit 0d3bb6f

Please sign in to comment.