Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13, Update Server Configuration #14

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
],

// Configure tool-specific properties.
// "customizations": {},
"customizations": {
"vscode":{
"extensions": [
"timonwong.shellcheck",
"GitHub.vscode-pull-request-github",
"charliermarsh.ruff"
]
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
Expand Down
31 changes: 20 additions & 11 deletions bin/lib.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
DIRNAME=$(dirname `realpath $0`)
#!/bin/bash
DIRNAME=$(dirname $(realpath $0))
PARENT_DIR=$DIRNAME/..
PROJECT_DIR=`realpath $PARENT_DIR`
PROJECT_DIR=$(realpath $PARENT_DIR)
ENV_FILE=$PROJECT_DIR/.env

if [ -f "$ENV_FILE" ]; then
. $ENV_FILE
# shellcheck source=lib.sh
. "$ENV_FILE"
else
echo "WARNING: File $ENV_FILE does not exist, relying on environment variables"
fi

REQUIRED_ENVIRONMENT_VARIABLES="LOUIS_DSN PGBASE PGUSER PGPASSWORD PGHOST OPENAI_API_KEY AZURE_OPENAI_SERVICE LOUIS_SCHEMA"
for VARIABLE in $REQUIRED_ENVIRONMENT_VARIABLES; do
if [ -z "${!VARIABLE}" ]; then
echo "Environment variable $VARIABLE is not set"
check_environment_variables_defined () {
variable_not_set=0
for VARIABLE in "$@"; do
if [ -z "${!VARIABLE}" ]; then
echo "Environment variable $VARIABLE is not set"
variable_not_set=1
fi
done

if [ $variable_not_set -eq 1 ]; then
exit 1
rngadam marked this conversation as resolved.
Show resolved Hide resolved
fi
rngadam marked this conversation as resolved.
Show resolved Hide resolved
done
}

export PGOPTIONS="--search_path=$LOUIS_SCHEMA,public"
export PGBASE
Expand All @@ -27,16 +35,17 @@ export PGHOST
export PGPASSFILE
export PGPASSWORD

VERSION15=`psql --version | grep 15.`
VERSION15=$(psql --version | grep 15.)

if [ -z "$VERSION15" ]; then
echo "postgresql-client-15 required"
exit 1
fi

PSQL_ADMIN="psql -v ON_ERROR_STOP=1 --single-transaction -d $PGBASE"
TODAY=`date +%Y-%m-%d`
TODAY=$(date +%Y-%m-%d)

if [ -z "$PGDUMP_FILENAME" ]; then
PGDUMP_FILENAME=$PROJECT_DIR/dumps/$TODAY.$PGBASE.pg_dump
fi

export PSQL_ADMIN="psql -v ON_ERROR_STOP=1 --single-transaction -d $PGBASE"
5 changes: 5 additions & 0 deletions bin/postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ fi

STATUS=`docker inspect louis-db-server -f '{{.State.Status}}'`

check_environment_variables_defined DB_SERVER_CONTAINER_NAME PGPASSWORD

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

elif [ "$STATUS" != "running" ]; then
echo container does not exist, creating
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update here today

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more details in your string, including container name

docker run --name louis-db-server \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be using your environment variable...

-e POSTGRES_PASSWORD=$PGPASSWORD \
--network louis_network \
Expand Down
2 changes: 1 addition & 1 deletion bin/setup-db-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ -z "$PGBASE" ]; then
exit 1
fi
DOCKER_EXEC="docker exec -it louis-db-server"
rngadam marked this conversation as resolved.
Show resolved Hide resolved
$DOCKER_EXEC createdb -E utf-8 $PGBASE
$DOCKER_EXEC createdb -E utf-8 -U postgres $PGBASE
rngadam marked this conversation as resolved.
Show resolved Hide resolved
$DOCKER_EXEC $PSQL_ADMIN -c "CREATE USER $USER; ALTER USER $USER WITH SUPERUSER;"
JolanThomassin marked this conversation as resolved.
Show resolved Hide resolved
$DOCKER_EXEC pip install pgxnclient
$DOCKER_EXEC pgxn install vector
Expand Down