Skip to content

Commit

Permalink
feat: import Docker files from GHL_Backend commit 296c1b2
Browse files Browse the repository at this point in the history
  • Loading branch information
luckypig3400 committed Mar 26, 2023
1 parent a37eeaa commit e32f325
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
MONGO_IMAGE_VERSION=5.0.8
# 5.0.8是20230318測試過最穩定運行的版本

# 以下設定3個Mongo Container映射到主機端的Port(內部均為27017)
MONGO1_HOST_PORT=27117
MONGO2_HOST_PORT=27217
MONGO3_HOST_PORT=27317

# 以下設定6個Mongo Container映射到主機端的資料存放位置(預設採用此專案的相對路徑)
MONGO1_DATA_STORAGE=./MongoData/mongo1_data
MONGO1_CONFIG_STORAGE=./MongoData/mongo1_config
MONGO2_DATA_STORAGE=./MongoData/mongo2_data
MONGO2_CONFIG_STORAGE=./MongoData/mongo2_config
MONGO3_DATA_STORAGE=./MongoData/mongo3_data
MONGO3_CONFIG_STORAGE=./MongoData/mongo3_config
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MongoData
24 changes: 24 additions & 0 deletions GHL_Backend.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ubuntu:22.04
MAINTAINER luckypig3400

# install app dependencies
RUN apt update
RUN apt install git -y
RUN apt install curl -y
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -
RUN apt install nodejs -y
RUN apt clean

# Set Work Directory
WORKDIR /home

# install app
RUN git clone https://github.com/johnny990628/GHL_Backend.git
WORKDIR /home/GHL_Backend
RUN npm install
RUN npm install bcrypt
# https://stackoverflow.com/questions/15809611/bcrypt-invalid-elf-header-when-running-node-app

# final configuration
EXPOSE 3080
CMD node server.js
68 changes: 68 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
services:
# 啟動3個mongo container用以建置Replica Set
KiwiRS-mongo1:
hostname: KiwiRS-mongo1
image: mongo:${MONGO_IMAGE_VERSION}
expose:
- 27017
ports:
- ${MONGO1_HOST_PORT}:27017
restart: always
command: mongod --replSet my-mongo-set
volumes:
- ${MONGO1_DATA_STORAGE}:/data/db
- ${MONGO1_CONFIG_STORAGE}:/data/configdb
KiwiRS-mongo2:
hostname: KiwiRS-mongo2
image: mongo:${MONGO_IMAGE_VERSION}
expose:
- 27017
ports:
- ${MONGO2_HOST_PORT}:27017
restart: always
command: mongod --replSet my-mongo-set
volumes:
- ${MONGO2_DATA_STORAGE}:/data/db
- ${MONGO2_CONFIG_STORAGE}:/data/configdb
KiwiRS-mongo3:
hostname: KiwiRS-mongo3
image: mongo:${MONGO_IMAGE_VERSION}
expose:
- 27017
ports:
- ${MONGO3_HOST_PORT}:27017
restart: always
command: mongod --replSet my-mongo-set
volumes:
- ${MONGO3_DATA_STORAGE}:/data/db
- ${MONGO3_CONFIG_STORAGE}:/data/configdb

# 初始化Mongo Replica Server
mongoinit:
image: mongo:${MONGO_IMAGE_VERSION}
# 這個Container只會執行一次
# 此Container可能會依據mongo1~3的啟動狀態受到一定程度的影響
# 啟動後記得查看此Container的Log,看到{ "ok" : 1 }才算成功!
restart: "on-failure"
depends_on:
- KiwiRS-mongo1
- KiwiRS-mongo2
- KiwiRS-mongo3
command: >
mongo --host KiwiRS-mongo1:27017 --eval 'config = { "_id" : "my-mongo-set", "members" : [
{
"_id" : 0,
"host" : "KiwiRS-mongo1:27017",
"priority" : 1
},
{
"_id" : 1,
"host" : "KiwiRS-mongo2:27017",
"priority" : 0.5
},
{
"_id" : 2,
"host" : "KiwiRS-mongo3:27017",
"priority" : 0.5
}
] }; rs.initiate(config);'
1 change: 1 addition & 0 deletions run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker compose up -d

0 comments on commit e32f325

Please sign in to comment.