Skip to content

Commit

Permalink
Fixes #13, Update to Environment Variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JolanThomassin committed Sep 13, 2023
1 parent dc31e13 commit 8ba5038
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions bin/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ check_environment_variables_defined () {
done

if [ $variable_not_set -eq 1 ]; then
echo "One or more variables are not defined, the program cannot continue"
exit 1
fi
}
Expand Down
32 changes: 18 additions & 14 deletions bin/postgres.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
#!/bin/bash
DIRNAME=$(dirname "$(realpath "$0")")
. "$DIRNAME"/lib.sh

DIRNAME=$(dirname `realpath $0`)
. $DIRNAME/lib.sh

PGDATA=$HOME/pgdata

if [ ! -d $PGDATA ]; then
mkdir -p $PGDATA
if [ -z "${!PGDATA}" ]; then
PGDATA=$HOME/pgdata
fi

STATUS=`docker inspect louis-db-server -f '{{.State.Status}}'`
if [ ! -d "$PGDATA" ]; then
mkdir -p "$PGDATA"
echo "PGDATA $PGDATA directory does not exist, creating it"
fi

check_environment_variables_defined DB_SERVER_CONTAINER_NAME PGPASSWORD

STATUS=$(docker inspect "$DB_SERVER_CONTAINER_NAME" -f '{{.State.Status}}')

if [ "$STATUS" = "exited" ]; then
echo "container $DB_SERVER_CONTAINER_NAME exist but has exited, restarting"
docker start louis-db-server
docker start "$DB_SERVER_CONTAINER_NAME"

elif [ "$STATUS" != "running" ]; then
echo container does not exist, creating
docker run --name louis-db-server \
-e POSTGRES_PASSWORD=$PGPASSWORD \

echo "container $DB_SERVER_CONTAINER_NAME does not exist, creating"

docker run --name "$DB_SERVER_CONTAINER_NAME" \
-e POSTGRES_PASSWORD="$PGPASSWORD" \
--network louis_network \
--mount type=bind,src=$PGDATA,target=/var/lib/postgresql/data \
--mount type=bind,src="$PGDATA",target=/var/lib/postgresql/data \
--publish 5432:5432 \
--user "$(id -u):$(id -g)" -v /etc/passwd:/etc/passwd:ro \
-d louis-postgres
-d "louis-postgres"
else
echo "Postgres is already running"
fi
11 changes: 5 additions & 6 deletions bin/setup-db-docker.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
DIRNAME=`dirname $0`
#!/bin/bash
DIRNAME=$(dirname "$0")
. $DIRNAME/lib.sh

if [ -z "$PGBASE" ]; then
echo "PGBASE is not set"
exit 1
fi
DOCKER_EXEC="docker exec -it louis-db-server"
check_environment_variables_defined PGBASE DB_SERVER_CONTAINER_NAME PSQL_ADMIN

DOCKER_EXEC="docker exec -it $DB_SERVER_CONTAINER_NAME"
$DOCKER_EXEC createdb -E utf-8 -U postgres $PGBASE
$DOCKER_EXEC $PSQL_ADMIN -c "CREATE USER $USER; ALTER USER $USER WITH SUPERUSER;"
$DOCKER_EXEC pip install pgxnclient
Expand Down

0 comments on commit 8ba5038

Please sign in to comment.