Got sharkey with isolated db running.

This commit is contained in:
Werner Kroneman 2024-12-07 08:57:00 +01:00
parent 75d6ae66aa
commit 50f154af57
2 changed files with 61 additions and 0 deletions

View file

@ -9,5 +9,18 @@
packages."x86_64-linux".default = self.packages."x86_64-linux".sharkey;
# Default dev shell with all of sharkey's dependencies + redis and postgresql
devShells."x86_64-linux".default = nixpkgs.legacyPackages."x86_64-linux".mkShell {
inputsFrom = [
self.packages."x86_64-linux".sharkey
];
nativeBuildInputs = with nixpkgs.legacyPackages."x86_64-linux"; [
redis
postgresql
yq
];
};
};
}

48
run_with_db.sh Executable file
View file

@ -0,0 +1,48 @@
# Set up a postgresql database and a redis server for the integration tests.
# Create a unique temporary directory for the unix socket and data:
export PGDATA=$(mktemp -d)
# Initialize the PostgreSQL data directory
initdb -D $PGDATA -U postgres
# Start PostgreSQL and Redis using unix sockets
pg_ctl -D $PGDATA -l $PGDATA/logfile start -o "-k $PGDATA --listen-addresses=''"
until pg_isready -h $PGDATA; do sleep 1; done
echo "PostgreSQL started with unix socket at $PGDATA"
# Create a "sharkey" user and database
psql -h $PGDATA -c "CREATE USER sharkey" -U postgres
psql -h $PGDATA -c "CREATE DATABASE sharkey OWNER sharkey" -U postgres
# Grab an empty TCP port:
function random_unused_port {
local port=$(shuf -i 2000-65000 -n 1)
netstat -lat | grep $port > /dev/null
if [[ $? == 1 ]] ; then
echo $port
else
random_unused_port
fi
}
export REDIS_PORT=$(random_unused_port)
redis-server --port $REDIS_PORT --loglevel warning &
until redis-cli -p $REDIS_PORT ping; do sleep 1; done
echo "Redis started with unix socket at $REDISSOCK"
cp .config/example.yml .config/default.yml
yq -i -Y '.db.host = "'$PGDATA'"' .config/default.yml
yq -i -Y '.redis.port = "'$REDIS_PORT'"' .config/default.yml
#export MISSKEY_CONFIG_YML=.config/default.yml
pnpm run migrateandstart
# Open Firefox
# Stop PostgreSQL and Redis
cleanup() {
pg_ctl -D $PGDATA stop
redis-cli -s $REDISSOCK shutdown
}
trap cleanup EXIT