-
Notifications
You must be signed in to change notification settings - Fork 1
/
postgress_docker.sh
executable file
·79 lines (63 loc) · 1.79 KB
/
postgress_docker.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
echo $1
container_name=scrum-poker-local
volume_name=scrum-poker-local-volume
docker_image='postgres:16.1'
env_file='.env.docker'
set_environment () {
if [ ! -f "$env_file" ]; then
echo -e "\e[33mWARNING: "$env_file not found, creating from template" \e[0m"
cp "$env_file.template" $env_file
fi
# Read docker.env file and add its content to environment
export $(cat $env_file | xargs)
echo -e ' ----- ENVIRONMENT ----- '
cat $env_file
echo -e $"\n ----------------------- "
}
set_volume () {
volume_exists=$(docker volume list --quiet --filter name=$volume_name)
if [[ -z $volume_exists || "$volume_exists" = "" ]]; then
docker volume create $volume_name
fi
}
stop () {
docker container stop $container_name
docker container rm $container_name
}
start () {
docker pull $docker_image
set_environment
set_volume
docker run \
--name $container_name \
--publish $POSTGRES_PORT:5432 \
--env POSTGRES_PASSWORD=$POSTGRES_PASSWORD \
--env POSTGRES_USER=$POSTGRES_USER \
--env POSTGRES_DB=$POSTGRES_DATABASE \
--volume "$volume_name:/var/lib/postgresql/data" \
--network host \
--detach \
$docker_image
secs=$((10))
while [ $secs -gt 0 ]; do
echo -ne "$secs, "
sleep 1
: $((secs--))
done
docker exec $container_name \
psql -U $POSTGRES_USER -c "CREATE DATABASE \"$POSTGRES_DATABASE\";"
docker container list --filter name=$container_name --format '{{.Names}}'
docker container list --filter name=$container_name --format '{{.Status}}'
docker container logs --follow $container_name
}
if [[ $1 == "stop" ]]; then
stop
fi
if [[ $1 == "start" ]]; then
stop
start
fi
if [ -z $1 ] || [ $1 == "" ] ; then
echo "User [start] or [stop]"
fi