diff --git a/cli/src/statbus.cr b/cli/src/statbus.cr index 4b5b7b753..9812af3e5 100644 --- a/cli/src/statbus.cr +++ b/cli/src/statbus.cr @@ -224,7 +224,7 @@ class StatBus private def import_common(import_file_name, sql_field_required_list, sql_field_optional_list, upload_view_name) # Find .env and load required secrets - Dir.cd("../supabase_docker") do + Dir.cd("..") do ini_data = File.read(".env") vars = INI.parse ini_data # The variables are all in the global scope, as an ".env" file is not really an ini file, diff --git a/devops/manage-statbus.sh b/devops/manage-statbus.sh index 28b51511e..6105aa5eb 100755 --- a/devops/manage-statbus.sh +++ b/devops/manage-statbus.sh @@ -219,7 +219,7 @@ EOS SUPABASE_BIND_ADDRESS="127.0.0.1:$(( 3000+$DEPLOYMENT_SLOT_PORT_OFFSET*10+1 ))" ./devops/dotenv --file .env set SUPABASE_BIND_ADDRESS=$SUPABASE_BIND_ADDRESS - DB_PUBLIC_LOCALHOST_PORT="127.0.0.1:$(( 3000+$DEPLOYMENT_SLOT_PORT_OFFSET*10+2 ))" + DB_PUBLIC_LOCALHOST_PORT="$(( 3000+$DEPLOYMENT_SLOT_PORT_OFFSET*10+2 ))" ./devops/dotenv --file .env set DB_PUBLIC_LOCALHOST_PORT=$DB_PUBLIC_LOCALHOST_PORT echo "Setting Supabase Container Configuration" @@ -277,11 +277,8 @@ EOF ;; 'postgres-variables' ) - DB_PUBLIC_LOCALHOST_PORT=$(./devops/dotenv --file .env get DB_PUBLIC_LOCALHOST_PORT) - # Extract the host part (before the colon) and set it to PGHOST - PGHOST=$(echo $DB_PUBLIC_LOCALHOST_PORT | cut -d':' -f1) - # Extract the port part (after the colon) and set it to PGPORT - PGPORT=$(echo $DB_PUBLIC_LOCALHOST_PORT | cut -d':' -f2) + PGHOST=127.0.0.1 + PGPORT=$(./devops/dotenv --file .env get DB_PUBLIC_LOCALHOST_PORT) PGDATABASE=$(./devops/dotenv --file .env get POSTGRES_DB) PGUSER=postgres PGPASSWORD=$(./devops/dotenv --file .env get POSTGRES_PASSWORD) @@ -290,15 +287,8 @@ export PGHOST=$PGHOST PGPORT=$PGPORT PGDATABASE=$PGDATABASE PGUSER=$PGUSER PGPAS EOS ;; 'psql' ) - DB_PUBLIC_LOCALHOST_PORT=$(./devops/dotenv --file .env get DB_PUBLIC_LOCALHOST_PORT) - # Extract the host part (before the colon) and set it to PGHOST - export PGHOST=$(echo $DB_PUBLIC_LOCALHOST_PORT | cut -d':' -f1) - # Extract the port part (after the colon) and set it to PGPORT - export PGPORT=$(echo $DB_PUBLIC_LOCALHOST_PORT | cut -d':' -f2) - export PGDATABASE=$(./devops/dotenv --file .env get POSTGRES_DB) - export PGUSER=postgres - export PGPASSWORD=$(./devops/dotenv --file .env get POSTGRES_PASSWORD) - if $(which psql > /dev/null); then + eval $(./devops/manage-statbus.sh postgres-variables) + if $(which psql > /dev/null && false); then psql "$@" else # When using scripted input, such as "< some.sql" then interactive TTY is required. @@ -308,7 +298,8 @@ EOS # as required for an interactive psql promp args="-ti" fi - docker exec $args $(docker ps | awk '/statbus-db/{print $1}') psql -U $PGUSER $PGDATABASE "$@" + COMPOSE_INSTANCE_NAME=$(./devops/dotenv --file .env get COMPOSE_INSTANCE_NAME) + docker exec $args -e PGPASSWORD=$PGPASSWORD $(docker ps | awk "/$COMPOSE_INSTANCE_NAME-db/{print \$1}") psql -U $PGUSER $PGDATABASE "$@" fi ;; 'generate-types' ) diff --git a/docker-compose.supabase_docker.customise.yml b/docker-compose.supabase_docker.customise.yml index cffca102f..43e975ca5 100644 --- a/docker-compose.supabase_docker.customise.yml +++ b/docker-compose.supabase_docker.customise.yml @@ -19,4 +19,4 @@ services: # Prevent the database from using too much memory. shm_size: 1g ports: - - ${DB_PUBLIC_LOCALHOST_PORT}:5432 + - 127.0.0.1:${DB_PUBLIC_LOCALHOST_PORT}:5432 diff --git a/samples/norway/brreg-samples.sh b/samples/norway/brreg-samples.sh index 3c5890554..565aa7c24 100755 --- a/samples/norway/brreg-samples.sh +++ b/samples/norway/brreg-samples.sh @@ -10,14 +10,8 @@ WORKSPACE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd ../.. && pwd )" pushd $WORKSPACE -source supabase_docker/.env -export PGHOST=localhost -export PGPORT=$DB_PUBLIC_LOCALHOST_PORT -export PGDATABASE=$POSTGRES_DB -export PGUSER=postgres -export PGPASSWORD="$POSTGRES_PASSWORD" echo "Setting up Statbus for Norway" -psql < samples/norway/setup.sql +./devops/manage-statbus.sh psql < samples/norway/setup.sql pushd cli echo "Loading legal_units" diff --git a/samples/norway/history/load.sh b/samples/norway/history/load.sh index c3aaf87f8..11a558df0 100755 --- a/samples/norway/history/load.sh +++ b/samples/norway/history/load.sh @@ -12,14 +12,8 @@ WORKSPACE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd ../../.. && pwd )" pushd $WORKSPACE -source supabase_docker/.env -export PGHOST=localhost -export PGPORT=$DB_PUBLIC_LOCALHOST_PORT -export PGDATABASE=$POSTGRES_DB -export PGUSER=postgres -export PGPASSWORD="$POSTGRES_PASSWORD" echo "Setting up Statbus for Norway" -psql < samples/norway/setup.sql +./devops/manage-statbus.sh psql < samples/norway/setup.sql echo "Adding tags for insert into right part of history"