From f22dfcdf349dded9ffc8d12a44382c8eda7c3906 Mon Sep 17 00:00:00 2001 From: Tejas Mehta Date: Tue, 24 Oct 2023 01:01:40 -0400 Subject: [PATCH 1/3] fix missing dep in gateway --- packages/api-gateway/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/api-gateway/package.json b/packages/api-gateway/package.json index 66f98732..1dce342d 100644 --- a/packages/api-gateway/package.json +++ b/packages/api-gateway/package.json @@ -21,6 +21,7 @@ "tsc": "tsc" }, "dependencies": { + "@grpc/grpc-js": "^1.9.7", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.1.1", "@nestjs/core": "^10.0.0", From 314e0966a74d3fd486d0c644ed5700ea7a117d91 Mon Sep 17 00:00:00 2001 From: Tejas Mehta Date: Tue, 24 Oct 2023 01:02:12 -0400 Subject: [PATCH 2/3] rewrite dockerfile to place node_modules one directory above volume dir --- packages/api-gateway/Dockerfile.dev | 14 ++++++++++---- packages/auth-service/Dockerfile.dev | 12 +++++++++--- packages/db-service/.dockerignore | 1 + packages/db-service/Dockerfile.dev | 22 +++++++++++++++++++--- packages/db-service/entrypoint.sh | 4 +--- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/packages/api-gateway/Dockerfile.dev b/packages/api-gateway/Dockerfile.dev index 8815058c..d662ae0f 100644 --- a/packages/api-gateway/Dockerfile.dev +++ b/packages/api-gateway/Dockerfile.dev @@ -1,10 +1,12 @@ -FROM node:18 as deps +FROM node:18-alpine as deps WORKDIR /app -COPY package.json yarn.lock +RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/* -RUN yarn install --frozen-lockfile +COPY package.json ./ + +RUN yarn install FROM node:18 as dev @@ -12,6 +14,10 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules/ +ENV PATH=/app/node_modules/.bin:$PATH + +WORKDIR /app/src + COPY . . -EXPOSE 3000 +EXPOSE 3000 diff --git a/packages/auth-service/Dockerfile.dev b/packages/auth-service/Dockerfile.dev index a0df8d90..e9cd57da 100644 --- a/packages/auth-service/Dockerfile.dev +++ b/packages/auth-service/Dockerfile.dev @@ -1,10 +1,12 @@ -FROM node:18 as deps +FROM node:18-alpine as deps WORKDIR /app -COPY package.json yarn.lock +RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/* -RUN yarn install --frozen-lockfile +COPY package.json ./ + +RUN yarn install FROM node:18 as dev @@ -12,6 +14,10 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules/ +ENV PATH=/app/node_modules/.bin:$PATH + +WORKDIR /app/src + COPY . . EXPOSE 50052 diff --git a/packages/db-service/.dockerignore b/packages/db-service/.dockerignore index cf709889..97cc2e3a 100644 --- a/packages/db-service/.dockerignore +++ b/packages/db-service/.dockerignore @@ -1 +1,2 @@ **/node_modules +!prisma/ diff --git a/packages/db-service/Dockerfile.dev b/packages/db-service/Dockerfile.dev index 704bb47d..18b26aea 100644 --- a/packages/db-service/Dockerfile.dev +++ b/packages/db-service/Dockerfile.dev @@ -1,17 +1,33 @@ -FROM node:18 as deps +FROM node:18-alpine as deps WORKDIR /app -COPY package.json yarn.lock +RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/* -RUN yarn install --frozen-lockfile +RUN yarn global add node-gyp prisma + +COPY package.json ./ + +RUN mkdir prisma + +RUN yarn install FROM node:18 as dev +RUN yarn global add nest prisma + WORKDIR /app COPY --from=deps /app/node_modules ./node_modules/ +ENV PATH=/app/node_modules/.bin:$PATH + +COPY ./prisma/ ./prisma/ + +RUN prisma generate + +WORKDIR /app/src + COPY . . EXPOSE 50053 diff --git a/packages/db-service/entrypoint.sh b/packages/db-service/entrypoint.sh index f7c0d99b..5f24a8d5 100755 --- a/packages/db-service/entrypoint.sh +++ b/packages/db-service/entrypoint.sh @@ -1,7 +1,5 @@ #!/bin/bash -yarn prisma migrate deploy - -yarn prisma generate +prisma migrate dev yarn start:dev From e3d3dd77516e16e182701b2a97a41c1590843840 Mon Sep 17 00:00:00 2001 From: Tejas Mehta Date: Tue, 24 Oct 2023 01:02:34 -0400 Subject: [PATCH 3/3] Rewrite docker-compose-dev to use correct contexts and volume locations --- docker-compose-dev.yml | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 8ba5ec4e..aac0ccd2 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -1,11 +1,11 @@ services: gateway: build: - dockerfile: ./packages/api-gateway/Dockerfile.dev + dockerfile: Dockerfile.dev + context: ./packages/api-gateway/ volumes: - - /app/node_modules - - ./packages/api-gateway:/app - - ./packages/proto:/proto + - ./packages/api-gateway:/app/src + - ./packages/proto:/app/proto ports: - '3000:3000' entrypoint: yarn start:dev @@ -19,11 +19,11 @@ services: auth-service: build: - dockerfile: ./packages/auth-service/Dockerfile.dev + dockerfile: Dockerfile.dev + context: ./packages/auth-service volumes: - - /app/node_modules - - ./packages/auth-service:/app - - ./packages/proto:/proto + - ./packages/auth-service:/app/src + - ./packages/proto:/app/proto ports: - '50052:50052' entrypoint: yarn start:dev @@ -37,11 +37,11 @@ services: db-service: build: - dockerfile: ./packages/db-service/Dockerfile.dev + dockerfile: Dockerfile.dev + context: ./packages/db-service volumes: - - /app/node_modules - - ./packages/db-service:/app - - ./packages/proto:/proto + - ./packages/db-service:/app/src + - ./packages/proto:/app/proto ports: - '50053:50053' entrypoint: ./entrypoint.sh @@ -52,7 +52,8 @@ services: networks: - bog-api-net depends_on: - - db + db: + condition: service_healthy db: image: postgres @@ -64,6 +65,11 @@ services: POSTGRES_USER: user networks: - bog-api-net + healthcheck: + test: ['CMD-SHELL', 'pg_isready -U user'] + interval: 5s + timeout: 5s + retries: 5 networks: bog-api-net: