Skip to content

Commit e66ad73

Browse files
author
Md Abdul Munim
committed
Add docker-compose
1 parent 10c089e commit e66ad73

File tree

6 files changed

+128
-1
lines changed

6 files changed

+128
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea/
22
node_modules/
3+
.env

Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ RUN apk add --no-cache bash
77
WORKDIR $SERVICE_HOME
88
COPY . .
99
RUN npm ci --production
10-
CMD ["bash", "startup.sh"]

docker-compose.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: '3.9'
2+
3+
services:
4+
build_image:
5+
build: .
6+
image: services/sns:${VERSION} # use your own image name e.g. rancher/my-app:{VERSION}
7+
app_svc:
8+
container_name: sns-service
9+
image: services/sns:${VERSION}
10+
depends_on: [build_image]
11+
restart: unless-stopped
12+
env_file: .env
13+
environment:
14+
- MONGO_USERNAME=$MONGO_USERNAME
15+
- MONGO_PASSWORD=$MONGO_PASSWORD
16+
- MONGO_HOSTNAME=mongo
17+
- MONGO_PORT=$MONGO_PORT
18+
- MONGO_DB=$MONGO_DB
19+
ports:
20+
- 8282:8282
21+
networks:
22+
- svc-network
23+
command: scripts/wait-for.sh mongo:27017 -- bash scripts/startup.sh
24+
25+
mongo:
26+
container_name: mongo
27+
image: mongo:4.1.8-xenial
28+
restart: always
29+
environment:
30+
- MONGO_INITDB_ROOT_USERNAME=$MONGO_USERNAME
31+
- MONGO_INITDB_ROOT_PASSWORD=$MONGO_PASSWORD
32+
- MONGO_INITDB_DATABASE=$MONGO_DB
33+
ports:
34+
- 27020:27017
35+
volumes:
36+
- dbdata:/data/db
37+
networks:
38+
- svc-network
39+
40+
networks:
41+
svc-network:
42+
driver: bridge
43+
44+
volumes:
45+
dbdata:
File renamed without changes.

scripts/wait-for.sh

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/sh
2+
3+
# original script: https://github.com/eficode/wait-for/blob/master/wait-for
4+
5+
TIMEOUT=15
6+
QUIET=0
7+
8+
echoerr() {
9+
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
10+
}
11+
12+
usage() {
13+
exitcode="$1"
14+
cat << USAGE >&2
15+
Usage:
16+
$cmdname host:port [-t timeout] [-- command args]
17+
-q | --quiet Do not output any status messages
18+
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
19+
-- COMMAND ARGS Execute command with args after the test finishes
20+
USAGE
21+
exit "$exitcode"
22+
}
23+
24+
wait_for() {
25+
for i in `seq $TIMEOUT` ; do
26+
nc -z "$HOST" "$PORT" > /dev/null 2>&1
27+
28+
result=$?
29+
if [ $result -eq 0 ] ; then
30+
if [ $# -gt 0 ] ; then
31+
exec "$@"
32+
fi
33+
exit 0
34+
fi
35+
sleep 1
36+
done
37+
echo "Operation timed out" >&2
38+
exit 1
39+
}
40+
41+
while [ $# -gt 0 ]
42+
do
43+
case "$1" in
44+
*:* )
45+
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
46+
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
47+
shift 1
48+
;;
49+
-q | --quiet)
50+
QUIET=1
51+
shift 1
52+
;;
53+
-t)
54+
TIMEOUT="$2"
55+
if [ "$TIMEOUT" = "" ]; then break; fi
56+
shift 2
57+
;;
58+
--timeout=*)
59+
TIMEOUT="${1#*=}"
60+
shift 1
61+
;;
62+
--)
63+
shift
64+
break
65+
;;
66+
--help)
67+
usage 0
68+
;;
69+
*)
70+
echoerr "Unknown argument: $1"
71+
usage 1
72+
;;
73+
esac
74+
done
75+
76+
if [ "$HOST" = "" -o "$PORT" = "" ]; then
77+
echoerr "Error: you need to provide a host and port to test."
78+
usage 2
79+
fi
80+
81+
wait_for "$@"

server/core/connectionManager.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ async function connectMongoDb() {
1717
reconnectTries: Number.MAX_VALUE,
1818
reconnectInterval: 500,
1919
connectTimeoutMS: 10000,
20+
useUnifiedTopology: true,
2021
};
2122

2223
try {

0 commit comments

Comments
 (0)