-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install postgresql in the docker container (#95)
- Loading branch information
Showing
14 changed files
with
184 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
source /etc/environment | ||
"$(dirname $(realpath $0))/pgsql/setup.sh" | ||
source /etc/environment | ||
|
||
python3 -u "$(dirname $(dirname $(realpath $0)))/main.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
apt-get update | ||
apt-get install -y --no-install-recommends vim git pciutils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
apt-get update | ||
apt-get install -y software-properties-common | ||
add-apt-repository -y ppa:deadsnakes/ppa | ||
apt-get update | ||
apt-get install -y --no-install-recommends python3.11 python3.11-venv python3-pip vim git pciutils | ||
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Define the PostgreSQL data directory | ||
BASE_DIR="${APP_PERSISTENT_STORAGE:-persistent_storage}/vector_db_data" | ||
DATA_DIR="${BASE_DIR}/pgsql" | ||
|
||
PG_VERSION=17 | ||
PG_BIN="/usr/lib/postgresql/${PG_VERSION}/bin" | ||
PG_SQL="/usr/lib/postgresql/${PG_VERSION}/bin/psql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
# Stolen from https://github.com/cloud-py-api/flow | ||
|
||
set -e | ||
|
||
# Environment variables | ||
source "$(dirname $(realpath $0))/env" | ||
|
||
apt-get update | ||
apt-get install -y curl sudo | ||
|
||
# Check if PostgreSQL is installed by checking for the existence of binary files | ||
if [ -d "$PG_BIN" ]; then | ||
echo "PostgreSQL binaries found." | ||
else | ||
echo "PostgreSQL binaries not found." | ||
echo "Adding the PostgreSQL APT repository..." | ||
VERSION="$(awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release)" | ||
echo "deb http://apt.postgresql.org/pub/repos/apt ${VERSION}-pgdg main" >/etc/apt/sources.list.d/pgdg.list | ||
curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor --output /etc/apt/trusted.gpg.d/postgresql.gpg | ||
echo "Installing PostgreSQL..." | ||
apt-get update && apt-get install -y postgresql-$PG_VERSION postgresql-$PG_VERSION-pgvector | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
|
||
# Stolen from https://github.com/cloud-py-api/flow | ||
|
||
set -e | ||
|
||
# Environment variables | ||
source "$(dirname $(realpath $0))/env" | ||
|
||
# Check if EXTERNAL_DB is set | ||
if [ -n "${EXTERNAL_DB}" ]; then | ||
CCB_DB_URL="${EXTERNAL_DB}" | ||
echo "Using EXTERNAL_DB, CCB_DB_URL is set to: $CCB_DB_URL" | ||
|
||
if [[ "$CCB_DB_URL" != "postgresql+psycopg://"* ]]; then | ||
echo "CCB_DB_URL must be a PostgreSQL URL and start with 'postgresql+psycopg://'" | ||
exit 1 | ||
fi | ||
|
||
if ! grep -q "^export EXTERNAL_DB=" /etc/environment; then | ||
echo "export EXTERNAL_DB=\"$EXTERNAL_DB\"" >> /etc/environment | ||
fi | ||
exit 0 | ||
fi | ||
|
||
# Ensure the directory exists and has the correct permissions | ||
mkdir -p "$DATA_DIR" | ||
chown -R postgres:postgres "$DATA_DIR" | ||
|
||
if [ ! -d "$DATA_DIR/base" ]; then | ||
echo "Initializing the PostgreSQL database..." | ||
sudo -u postgres ${PG_BIN}/initdb -D "$DATA_DIR" -E UTF8 | ||
fi | ||
|
||
echo "Starting PostgreSQL..." | ||
sudo -u postgres ${PG_BIN}/pg_ctl -D "$DATA_DIR" -l "${DATA_DIR}/logfile" start | ||
|
||
echo "Waiting for PostgreSQL to start..." | ||
until sudo -u postgres ${PG_SQL} -c "SELECT 1" > /dev/null 2>&1; do | ||
sleep 1 | ||
echo -n "." | ||
done | ||
echo "PostgreSQL is up and running." | ||
|
||
if [ -n "${CCB_DB_URL}" ]; then | ||
echo "CCB_DB_URL is already set. Skipping database setup." | ||
exit 0 | ||
fi | ||
|
||
# Check if the user exists and create if not | ||
sudo -u postgres $PG_SQL -c "SELECT 1 FROM pg_user WHERE usename = '$CCB_DB_USER'" | grep -q 1 || \ | ||
sudo -u postgres $PG_SQL -c "CREATE USER $CCB_DB_USER WITH PASSWORD '$CCB_DB_PASS';" && \ | ||
sudo -u postgres $PG_SQL -c "ALTER USER $CCB_DB_USER WITH SUPERUSER;" | ||
|
||
# Check if the database exists and create if not | ||
sudo -u postgres $PG_SQL -c "SELECT 1 FROM pg_database WHERE datname = '$CCB_DB_NAME'" | grep -q 1 || \ | ||
sudo -u postgres $PG_SQL -c "CREATE DATABASE $CCB_DB_NAME OWNER $CCB_DB_USER;" | ||
|
||
# Check or create the vector extension | ||
sudo -u postgres $PG_SQL -c "CREATE EXTENSION IF NOT EXISTS vector" | ||
|
||
if ! grep -q "^export CCB_DB_URL=" /etc/environment; then | ||
echo "export CCB_DB_URL=\"postgresql+psycopg://$CCB_DB_USER:$CCB_DB_PASS@localhost:5432/$CCB_DB_NAME\"" >> /etc/environment | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.