diff --git a/flake.nix b/flake.nix index f3b064d3f5..d001f8d9fc 100644 --- a/flake.nix +++ b/flake.nix @@ -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 + ]; + }; }; } diff --git a/run_with_db.sh b/run_with_db.sh new file mode 100755 index 0000000000..4144e8f485 --- /dev/null +++ b/run_with_db.sh @@ -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