persistent data for local federation setup

This commit is contained in:
Felix Ableitner 2024-02-09 11:30:44 +01:00
parent 36995bfcc7
commit 773e19b38b
4 changed files with 29 additions and 16 deletions

View File

@ -8,14 +8,29 @@ set -e
# #
# Then run this script and open http://ibis-alpha:8070/, http://ibis-beta:8080/ in your browser. # Then run this script and open http://ibis-alpha:8070/, http://ibis-beta:8080/ in your browser.
function cleanup {
echo "stop postgres"
./scripts/stop_dev_db.sh $ALPHA_DB_PATH
./scripts/stop_dev_db.sh $BETA_DB_PATH
}
trap cleanup EXIT
DB_FOLDER="$(pwd)/target/federation_db" DB_FOLDER="$(pwd)/target/federation_db"
mkdir -p "$DB_FOLDER/" mkdir -p "$DB_FOLDER/"
ALPHA_DB_PATH="$DB_FOLDER/alpha" ALPHA_DB_PATH="$DB_FOLDER/alpha"
BETA_DB_PATH="$DB_FOLDER/beta" BETA_DB_PATH="$DB_FOLDER/beta"
# TODO: shouldnt wipe/recreate data if folder already exists # create db folders if they dont exist
./tests/scripts/start_dev_db.sh $ALPHA_DB_PATH if [ ! -d $ALPHA_DB_PATH ]; then
./tests/scripts/start_dev_db.sh $BETA_DB_PATH ./scripts/start_dev_db.sh $ALPHA_DB_PATH
else
pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$ALPHA_DB_PATH" -D "$ALPHA_DB_PATH/dev_pgdata"
fi
if [ ! -d $BETA_DB_PATH ]; then
./scripts/start_dev_db.sh $BETA_DB_PATH
else
pg_ctl start --options="-c listen_addresses= -c unix_socket_directories=$BETA_DB_PATH" -D "$BETA_DB_PATH/dev_pgdata"
fi
ALPHA_DB_URL="postgresql://ibis:password@/ibis?host=$ALPHA_DB_PATH" ALPHA_DB_URL="postgresql://ibis:password@/ibis?host=$ALPHA_DB_PATH"
BETA_DB_URL="postgresql://ibis:password@/ibis?host=$BETA_DB_PATH" BETA_DB_URL="postgresql://ibis:password@/ibis?host=$BETA_DB_PATH"
@ -25,12 +40,11 @@ killall ibis || true
CARGO_TARGET_DIR=target/frontend trunk build CARGO_TARGET_DIR=target/frontend trunk build
# launch a couple of local instances to test federation # launch a couple of local instances to test federation, then wait for processes to finish
# sometimes ctrl+c doesnt work properly, so you have to kill trunk, cargo-watch and ibis manually IBIS__BIND=127.0.0.1:8070 IBIS__FEDERATION__DOMAIN=ibis-alpha:8070 IBIS__DATABASE_URL=$ALPHA_DB_URL cargo run &
(trap 'kill 0' SIGINT; PID_ALPHA=($!)
sh -c "IBIS__BIND=127.0.0.1:8070 IBIS__FEDERATION__DOMAIN=ibis-alpha:8070 IBIS__DATABASE_URL=$ALPHA_DB_URL cargo run" & IBIS__BIND=127.0.0.1:8080 IBIS__FEDERATION__DOMAIN=ibis-beta:8080 IBIS__DATABASE_URL=$BETA_DB_URL cargo run &
sh -c "IBIS__BIND=127.0.0.1:8080 IBIS__FEDERATION__DOMAIN=ibis-beta:8080 IBIS__DATABASE_URL=$BETA_DB_URL cargo run" & PID_BETA=($!)
)
./tests/scripts/stop_dev_db.sh $ALPHA_DB_PATH wait $PID_ALPHA
./tests/scripts/stop_dev_db.sh $BETA_DB_PATH wait $PID_BETA

View File

@ -6,4 +6,3 @@ export PGDATA="$1/dev_pgdata"
echo $PGHOST echo $PGHOST
pg_ctl stop pg_ctl stop
rm -rf $1

View File

@ -95,10 +95,10 @@ impl IbisInstance {
// remove old db // remove old db
remove_dir_all(&db_path).unwrap(); remove_dir_all(&db_path).unwrap();
spawn(move || { spawn(move || {
Command::new("./tests/scripts/start_dev_db.sh") Command::new("./scripts/start_dev_db.sh")
.arg(&db_path) .arg(&db_path)
.stdout(Stdio::inherit()) .stdout(Stdio::null())
.stderr(Stdio::inherit()) .stderr(Stdio::null())
.output() .output()
.unwrap(); .unwrap();
}) })
@ -144,7 +144,7 @@ impl IbisInstance {
fn stop_internal(db_path: String) -> std::thread::JoinHandle<()> { fn stop_internal(db_path: String) -> std::thread::JoinHandle<()> {
spawn(move || { spawn(move || {
Command::new("./tests/scripts/stop_dev_db.sh") Command::new("./scripts/stop_dev_db.sh")
.arg(db_path) .arg(db_path)
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::null()) .stderr(Stdio::null())