-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-pureharm-postgresql-test.sh
executable file
·39 lines (35 loc) · 1.7 KB
/
docker-pureharm-postgresql-test.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
#!/usr/bin/env bash
# Script that setups and runs a postgres 11.0 database inside a docker container.
# You can run this script via terminal using `sh docker-postgresql.sh`
# Running the script for the first time pulls a postgres image from docker repository.
# If a container with the same name already exists, running this script will start/restart the container.
# Postgres default configuration is specified by the parameters below.
# Docker is required in order for this script to work !
# parameters #
POSTGRES_VERSION=12.3-alpine # see https://hub.docker.com/_/postgres
CONTAINER_NAME=postgres_pureharm_test # Name of the docker container used to run postgres
EXPOSED_PORT=20010 # this is the port on the host machine; most likely you want to change this one.
INTERNAL_PORT=5432 # this is the default port on which postgresql starts on within the container.
MAX_CONNECTIONS=500 # default is 115, and since this is only for testing it's OK to just up the number, since we care more about isolation than about performance.
DB_NAME=pureharm_test
DB_USER=pureharmony
DB_PASS=pureharmony
# actual script #
if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then
if [ ! "$(docker ps -aq -f name=$CONTAINER_NAME -f status=exited)" ]; then
echo "Stopping postgres container"
docker stop $CONTAINER_NAME
fi
echo "Starting postgres container"
docker start $CONTAINER_NAME
else
echo "Creating & starting postgres container"
docker run -d \
--name $CONTAINER_NAME \
-p $EXPOSED_PORT:$INTERNAL_PORT \
-e POSTGRES_DB=$DB_NAME \
-e POSTGRES_USER=$DB_USER \
-e POSTGRES_PASSWORD=$DB_PASS \
postgres:$POSTGRES_VERSION \
postgres -N $MAX_CONNECTIONS
fi