-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: update docker for api gateway service
Add `docker-compose.prod.yml` for the containerization of production application.
- Loading branch information
Showing
6 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
FROM node:alpine As development | ||
|
||
ARG service | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
WORKDIR /usr/src/app/apps/${service} | ||
|
||
COPY apps/${service}/package*.json ./ | ||
|
||
WORKDIR /usr/src/app | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
|
||
RUN npm run build:${service} | ||
|
||
|
||
FROM node:alpine as production | ||
|
||
ARG service | ||
ARG NODE_ENV=production | ||
ENV NODE_ENV=${NODE_ENV} | ||
ENV SERVICE ${service} | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
WORKDIR /usr/src/app/apps/${service} | ||
|
||
COPY apps/${service}/package*.json ./ | ||
|
||
WORKDIR /usr/src/app | ||
|
||
RUN npm install --omit=dev | ||
# RUN echo ${service} | ||
|
||
# COPY . . | ||
|
||
COPY --from=development /usr/src/app/dist ./dist | ||
|
||
CMD node dist/apps/$SERVICE/server.js | ||
|
||
# docker build --build-arg="service=apigateway" -f ./apps/Dockerfile.apigateway . -t libraryapp-apigateway | ||
# docker run -p 8080:8080 libraryapp/apigateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# NOTE: The ports of internal services (eg. book, customer, payment, borrowing) are not exposed in production | ||
|
||
services: | ||
# app services | ||
book: | ||
build: | ||
context: . | ||
dockerfile: ./apps/Dockerfile.service | ||
target: production | ||
args: | ||
service: book | ||
env_file: | ||
- ./apps/book/.env | ||
environment: | ||
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-book | ||
- RABBIT_MQ_URI=amqp://rabbitmq:5672 | ||
depends_on: | ||
- mongodb | ||
- rabbitmq | ||
# ports: | ||
# - '8001:8001' | ||
networks: | ||
- node-network | ||
links: | ||
- mongodb | ||
- rabbitmq | ||
customer: | ||
build: | ||
context: . | ||
dockerfile: ./apps/Dockerfile.service | ||
target: production | ||
args: | ||
service: customer | ||
env_file: | ||
- ./apps/customer/.env | ||
environment: | ||
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-customer | ||
depends_on: | ||
- mongodb | ||
# ports: | ||
# - '8002:8002' | ||
networks: | ||
- node-network | ||
links: | ||
- mongodb | ||
borrowing: | ||
build: | ||
context: . | ||
dockerfile: ./apps/Dockerfile.service | ||
target: production | ||
args: | ||
service: borrowing | ||
env_file: | ||
- ./apps/borrowing/.env | ||
environment: | ||
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-borrowing | ||
- RABBIT_MQ_URI=amqp://rabbitmq:5672 | ||
depends_on: | ||
- mongodb | ||
- rabbitmq | ||
# ports: | ||
# - '8003:8003' | ||
networks: | ||
- node-network | ||
links: | ||
- mongodb | ||
- rabbitmq | ||
payment: | ||
build: | ||
context: . | ||
dockerfile: ./apps/Dockerfile.service | ||
target: production | ||
args: | ||
service: payment | ||
env_file: | ||
- ./apps/payment/.env | ||
environment: | ||
- MONGODB_URI=mongodb://mongodb:27017/libraryapp-payment | ||
- RABBIT_MQ_URI=amqp://rabbitmq:5672 | ||
depends_on: | ||
- mongodb | ||
- rabbitmq | ||
# ports: | ||
# - '8004:8004' | ||
networks: | ||
- node-network | ||
links: | ||
- mongodb | ||
- rabbitmq | ||
notification: | ||
build: | ||
context: . | ||
dockerfile: ./apps/Dockerfile.service | ||
target: production | ||
args: | ||
service: notification | ||
env_file: | ||
- ./apps/notification/.env | ||
environment: | ||
- RABBIT_MQ_URI=amqp://rabbitmq:5672 | ||
depends_on: | ||
- rabbitmq | ||
# ports: | ||
# - '8005:8005' | ||
networks: | ||
- node-network | ||
links: | ||
- rabbitmq | ||
view: | ||
build: | ||
context: . | ||
dockerfile: ./apps/Dockerfile.view | ||
args: | ||
service: view | ||
env_file: | ||
- ./apps/view/.env | ||
depends_on: | ||
- book | ||
- customer | ||
- borrowing | ||
- payment | ||
- notification | ||
ports: | ||
- '8000:8000' | ||
networks: | ||
- node-network | ||
apigateway: | ||
build: | ||
context: . | ||
dockerfile: ./apps/Dockerfile.apigateway | ||
target: production | ||
args: | ||
service: apigateway | ||
env_file: | ||
- ./apps/apigateway/.env | ||
depends_on: | ||
- view | ||
ports: | ||
- '8080:8080' | ||
networks: | ||
- node-network | ||
links: | ||
- book | ||
- customer | ||
- borrowing | ||
- payment | ||
environment: | ||
- BASEURL_BOOK=http://book:8001 | ||
- BASEURL_CUSTOMER=http://customer:8002 | ||
- BASEURL_BORROWING=http://borrowing:8003 | ||
- BASEURL_PAYMENT=http://payment:8004 | ||
|
||
# Dependencies | ||
rabbitmq: | ||
image: rabbitmq | ||
ports: | ||
- '5672:5672' | ||
networks: | ||
- node-network | ||
mongodb: | ||
image: mongo:6 | ||
volumes: | ||
- mongodb_data_container:/data/db | ||
ports: | ||
- '27017:27017' | ||
networks: | ||
- node-network | ||
|
||
volumes: | ||
mongodb_data_container: | ||
networks: | ||
node-network: | ||
driver: bridge | ||
# docker compose -f docker-compose.prod.yml up -d | ||
# docker compose -f docker-compose.prod.yml up -d --build | ||
# docker compose -f docker-compose.prod.yml down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters