-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·48 lines (38 loc) · 1.58 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
convertsecs() {
((m = (${1} % 3600) / 60))
((s = ${1} % 60))
printf "%02dm %02ds\n" $m $s
}
POSTGRES_PORT=5432
POSTGRES_DB=mattmaxwell
POSTGRES_PASSWORD=password
POSTGRES_CONTAINER_NAME=postgres
REDIS_PORT=6379
REDIS_CONTAINER_NAME=redis
start_time=$(date +%s)
START=1
STEPS=2
echo -e "Initializing Docker containers...\n"
if [ ! "$(docker ps -q -f name=$POSTGRES_CONTAINER_NAME)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$POSTGRES_CONTAINER_NAME)" ]; then
docker rm $POSTGRES_CONTAINER_NAME
fi
docker run -p $POSTGRES_PORT:$POSTGRES_PORT --name $POSTGRES_CONTAINER_NAME -e POSTGRES_USER="$POSTGRES_USER" -e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" -e POSTGRES_DB="$POSTGRES_DB" -d postgres:alpine
echo -e "\t[✔]: Initiated PostgreSQL container named \"$POSTGRES_CONTAINER_NAME\" @ port $POSTGRES_PORT"
else
echo -e "\t[✔]: PostgreSQL container is already running"
fi
if [ ! "$(docker ps -q -f name=$REDIS_CONTAINER_NAME)" ]; then
if [ "$(docker ps -aq -f status=exited -f name=$REDIS_CONTAINER_NAME)" ]; then
docker rm $REDIS_CONTAINER_NAME
fi
docker run -p $REDIS_PORT:$REDIS_PORT --name $REDIS_CONTAINER_NAME -d redis:alpine
echo -e "\t[✔]: Initiated Redis container named \"$REDIS_CONTAINER_NAME\" @ port $REDIS_PORT\n"
else
echo -e "\t[✔]: Redis container is already running\n"
fi
echo -e "[Success]: Initialized Docker containers for application\n"
end_time=$(date +%s)
execution_time=$(expr $end_time - $start_time)
echo -e "Total build and deployment time elapsed: $(convertsecs $execution_time)"