Skip to content

Commit

Permalink
fix docker build stages & proto copy stages
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthecoder committed Jan 31, 2024
1 parent ab764bd commit 3d30c14
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 37 deletions.
30 changes: 8 additions & 22 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COPY . .

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

RUN yarn global add node-gyp prisma
RUN yarn global add node-gyp

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

Expand All @@ -16,21 +16,11 @@ RUN yarn install --frozen-lockfile

RUN yarn build

RUN yarn install --frozen-lockfile

WORKDIR /app/packages/api-gateway

RUN yarn install --frozen-lockfile

WORKDIR /app/packages/auth-service

RUN yarn install --frozen-lockfile

WORKDIR /app/packages/db-service
WORKDIR /app

RUN yarn install --frozen-lockfile
RUN yarn install --frozen-lockfile --ignore-scripts

FROM node:18 as gateway-dev
FROM node:18 as api-gateway-dev

WORKDIR /app

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

COPY . .

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

WORKDIR /app/packages/api-gateway


FROM node:18 as auth-service-dev

WORKDIR /app
Expand All @@ -55,11 +44,10 @@ COPY --from=deps /app/packages/auth-service/node_modules ./packages/node_modules

COPY . .

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

WORKDIR /app/packages/auth-service


FROM node:18 as db-service-dev

WORKDIR /app
Expand All @@ -70,10 +58,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
COPY --from=deps /app/packages/proto/ ./packages/proto/

WORKDIR /app/packages/db-service

RUN prisma generate
RUN yarn prisma generate
13 changes: 2 additions & 11 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
services:
gateway:
api-gateway:
build:
dockerfile: Dockerfile.dev
target: gateway-dev
target: api-gateway-dev
context: .
volumes:
- ./packages/api-gateway:/app/packages/api-gateway
- ./packages/proto:/app/packages/juno-proto
ports:
- '3000:3000'
entrypoint: yarn ${GATEWAY_COMMAND-start:dev}
Expand All @@ -23,9 +20,6 @@ services:
dockerfile: Dockerfile.dev
target: auth-service-dev
context: .
volumes:
- ./packages/auth-service:/app/packages/auth-service
- ./packages/proto:/app/packages/juno-proto
ports:
- '50052:50052'
entrypoint: yarn ${AUTH_COMMAND-start:dev}
Expand All @@ -42,9 +36,6 @@ services:
dockerfile: Dockerfile.dev
target: db-service-dev
context: .
volumes:
- ./packages/db-service:/app/packages/db-service
- ./packages/proto:/app/packages/juno-proto
ports:
- '50053:50053'
entrypoint: /bin/sh -c "DB_COMMAND=${DB_COMMAND-start:dev} RUN_MODE=${RUN_MODE-dev} ./entrypoint.sh"
Expand Down
29 changes: 29 additions & 0 deletions docker/docker-compose-live-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
api-gateway:
extends:
file: docker-compose-dev.yml
service: api-gateway
volumes:
- ./packages/api-gateway:/app/packages/api-gateway
- /app/packages/api-gateway/node_modules

auth-service:
extends:
file: docker-compose-dev.yml
service: auth-service
volumes:
- ./packages/auth-service:/app/packages/auth-service
- /app/packages/auth-service/node_modules

db-service:
extends:
file: docker-compose-dev.yml
service: db-service
volumes:
- ./packages/db-service:/app/packages/db-service
- /app/packages/db-service/node_modules

db:
extends:
file: docker-compose-dev.yml
service: db
29 changes: 29 additions & 0 deletions docker/docker-compose-live-proto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
api-gateway:
extends:
file: docker-compose-dev.yml
service: api-gateway
volumes:
- ./packages/proto:/app/packages/proto
- ./packages/proto:/app/packages/node_modules/juno-proto

auth-service:
extends:
file: docker-compose-dev.yml
service: auth-service
volumes:
- ./packages/proto:/app/packages/proto
- ./packages/proto:/app/packages/node_modules/juno-proto

db-service:
extends:
file: docker-compose-dev.yml
service: db-service
volumes:
- ./packages/proto:/app/packages/proto
- ./packages/proto:/app/packages/node_modules/juno-proto

db:
extends:
file: docker-compose-dev.yml
service: db
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"packages/*"
],
"scripts": {
"api-gateway": "yarn workspace api-gateway start",
"start:dev": "docker-compose -f docker-compose-dev.yml up",
"start:dev:live-packages": "docker-compose -f docker-compose-dev.yml -f docker/docker-compose-live-packages.yml up",
"start:dev:live-proto": "docker-compose -f docker-compose-dev.yml -f docker/docker-compose-live-proto.yml up",
"start:dev:live-all": "docker-compose -f docker-compose-dev.yml -f docker/docker-compose-live-proto.yml -f docker/docker-compose-live-packages.yml up",
"format:check": "yarn prettier --check .",
"format:write": "yarn prettier --write .",
"tsc": "nx run-many --target=tsc",
"lint": "nx run-many --target=lint",
"gen-proto": "yarn workspace juno-proto install && yarn workspace juno-proto build",
"preinstall": "yarn gen-proto",
"test:e2e:api-gateway": "GATEWAY_COMMAND=test:e2e RUN_MODE=test docker-compose -f docker-compose-dev.yml up --exit-code-from gateway",
"test:e2e:api-gateway": "GATEWAY_COMMAND=test:e2e RUN_MODE=test docker-compose -f docker-compose-dev.yml up --exit-code-from api-gateway",
"test:e2e:auth-service": "AUTH_COMMAND=test:e2e RUN_MODE=test docker-compose -f docker-compose-dev.yml up --exit-code-from auth-service",
"test:e2e:db-service": "DB_COMMAND=test:e2e RUN_MODE=test docker-compose -f docker-compose-dev.yml up --exit-code-from db-service"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/db-service/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

if [[ ${RUN_MODE} == *"test"* ]]; then
echo "Resetting database for test..."
prisma migrate reset --force
yarn prisma migrate reset --force
fi

prisma migrate dev
yarn prisma migrate dev

yarn ${DB_COMMAND-start:dev}

0 comments on commit 3d30c14

Please sign in to comment.