Skip to content

Commit a9039df

Browse files
committed
Configure dockerization
1 parent 38d01ce commit a9039df

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-0
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.eslintrc
2+
server/secret.js

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PORT=8000

Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM node:8
2+
MAINTAINER Mohammad Samiul Islam <[email protected]>
3+
4+
WORKDIR /home/src
5+
6+
RUN apt update
7+
8+
RUN apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
9+
10+
RUN curl -sS http://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
11+
RUN echo "deb http://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
12+
RUN apt-get update && apt-get install yarn
13+
14+
RUN yarn global add forever
15+
16+
COPY node_modules .
17+
COPY package.json .
18+
RUN yarn install
19+
20+
RUN yarn global add nodemon
21+
22+
RUN wget https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64.deb
23+
RUN dpkg -i dumb-init_*.deb
24+
25+
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
26+
27+
ADD . .
28+
29+
EXPOSE 8002
30+
EXPOSE 3050

deploy.sh

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
3+
BOLD='\e[1;31m' # Bold Red
4+
REV='\e[1;32m' # Bold Green
5+
OFF='\e[0m'
6+
7+
TYPE=""
8+
HELP="false"
9+
10+
#Help function
11+
function HELP_DETAILS {
12+
echo -e "${REV}TYPE${OFF}: Can be one of dev, prod, beta, init, mongo or mongo-express"
13+
exit 1
14+
}
15+
16+
while getopts hp:t: FLAG; do
17+
case $FLAG in
18+
h) HELP="true" ;;
19+
t) TYPE=$OPTARG ;;
20+
*) echo "Unexpected option" && HELP_DETAILS && exit 1 ;;
21+
esac
22+
done
23+
24+
if [[ $HELP = "true" ]] ; then
25+
HELP_DETAILS
26+
exit 1
27+
fi
28+
29+
if [[ $TYPE = "" ]] ; then
30+
echo -e "${BOLD}Error${OFF}: Type flag is required."
31+
HELP_DETAILS
32+
exit 1
33+
fi
34+
35+
# Check if secret.js file exists
36+
if [[ ! -f server/secret.js ]] ; then
37+
echo -e "${BOLD}File missing${OFF}: server/secret.js (Please read README.md)"
38+
exit 0
39+
fi
40+
41+
if [[ $TYPE = "prod" || $TYPE = "beta" ]] ; then
42+
docker-compose down
43+
docker rmi $(docker images -f "dangling=true" -q)
44+
git pull origin
45+
if [[ $TYPE = "prod" ]] ; then
46+
git checkout master
47+
else
48+
git checkout release
49+
fi
50+
docker-compose build
51+
docker-compose up &
52+
sleep 5s
53+
docker cp server/secret.js cpps2_app_1:/home/src/server/
54+
docker exec -itd cpps2_app_1 /bin/bash -c "forever start server/index.js"
55+
docker exec -itd cpps2_app_1 forever start server/node_modules/queue/worker.js
56+
elif [[ $TYPE = "dev" ]] ; then
57+
docker-compose down
58+
docker rmi $(docker images -f "dangling=true" -q)
59+
docker-compose build
60+
docker-compose up &
61+
sleep 5s
62+
docker cp server/secret.js cpps2_app_1:/home/src/server/
63+
docker exec -itd cpps2_app_1 /bin/bash -c "cd /root/src && node server/node_modules/queue/worker.js"
64+
docker exec -it cpps2_app_1 /bin/bash -c "cd /root/src && yarn install && nodemon server/index.js"
65+
elif [[ $TYPE = "mongo" ]] ; then
66+
docker exec -it cpps2_db_1 mongo
67+
elif [[ $TYPE = "mongo-express" ]] ; then
68+
docker run -it --rm \
69+
--name mongo-express \
70+
--network cpps2_ntw \
71+
--link cpps2_db_1:mongo \
72+
-p 8081:8081 \
73+
-e ME_CONFIG_OPTIONS_EDITORTHEME="ambiance" \
74+
mongo-express
75+
elif [[ $TYPE = "init" ]] ; then
76+
docker exec -it cpps2_app_1 node server/scripts/dbInit.js
77+
elif [[ $TYPE = "mongo-backup" ]]; then
78+
# Create backup and copy it out from docker
79+
# Run this from root folder
80+
docker exec -it cpps2_db_1 mongodump --db cpps2 --out /root/volumes/cpps2_db/`date +"%m-%d-%y"`
81+
docker cp cpps2_db_1:/root/volumes/cpps2_db ./backup/
82+
docker exec -it cpps2_db_1 rm -r /root/volumes/cpps2_db/`date +"%m-%d-%y"`
83+
elif [[ $TYPE = "mongo-restore" ]]; then
84+
# Copy the backup file to docker into path /root/volumes/cpps2_db/restore/cpps2
85+
# docker cp <your_folder> cpps2_db_1:/root/volumes/cpps2_db/restore
86+
# Then run this command
87+
docker exec cpps2_db_1 rm -rf /root/volumes/cpps2_db/restore
88+
docker cp ./backup/restore cpps2_db_1:/root/volumes/cpps2_db/restore
89+
docker exec -it cpps2_db_1 mongorestore --db cpps2 --drop /root/volumes/cpps2_db/restore/cpps2/
90+
elif [[ $TYPE = "kuejs" ]] ; then
91+
docker exec -it cpps2_app_1 node_modules/kue/bin/kue-dashboard -p 3050 -r redis://cpps2_redis_1:6379
92+
elif [[ $TYPE = "redis-clean" ]] ; then
93+
docker exec -it cpps2_redis_1 redis-cli flushall
94+
elif [[ $TYPE = "worker" ]] ; then
95+
docker exec -it cpps2_app_1 /bin/bash -c "cd /root/src && node server/node_modules/queue/worker.js"
96+
elif [[ $TYPE = "stop" ]] ; then
97+
docker-compose down
98+
docker rmi $(docker images -f "dangling=true" -q)
99+
else
100+
echo -e "${BOLD}Unknown Type${OFF}: $TYPE"
101+
fi

docker-compose.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '2'
2+
3+
services:
4+
redis:
5+
image: redis
6+
networks:
7+
- ntw
8+
volumes:
9+
- redis_db:/data
10+
db:
11+
image: mongo:3.4
12+
networks:
13+
- ntw
14+
volumes:
15+
- db:/root/volumes/cpps_db
16+
- db_data:/data/db
17+
restart: always
18+
app:
19+
build: .
20+
image: cpps
21+
depends_on:
22+
- db
23+
- redis
24+
ports:
25+
- "${PORT}:8002"
26+
- "3050:3050"
27+
networks:
28+
- ntw
29+
volumes:
30+
- app:/home/volumes/cpps_app
31+
- logs:/home/src/logs
32+
- ./:/root/src/
33+
command: tail -f /dev/null
34+
35+
networks:
36+
ntw:
37+
38+
volumes:
39+
db_data:
40+
db:
41+
app:
42+
logs:
43+
redis_db:
File renamed without changes.

0 commit comments

Comments
 (0)