From 10a4b3a03af411888e9e5ebca66ed382e9621d5d Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Mon, 20 Jan 2025 00:54:28 +0800 Subject: [PATCH] chore: update run local server script (#1180) --- script/init_database.sh | 63 -------------------------------------- script/init_gotrue.sh | 16 ---------- script/init_redis.sh | 19 ------------ script/run_local_server.sh | 12 ++++++++ 4 files changed, 12 insertions(+), 98 deletions(-) delete mode 100755 script/init_database.sh delete mode 100755 script/init_gotrue.sh delete mode 100755 script/init_redis.sh diff --git a/script/init_database.sh b/script/init_database.sh deleted file mode 100755 index f7eaedcb..00000000 --- a/script/init_database.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -set -x -set -eo pipefail - -if ! [ -x "$(command -v psql)" ]; then - echo >&2 "Error: `psql` is not installed." - echo >&2 "install using brew: brew install libpq." - echo >&2 "link to /usr/local/bin: brew link --force libpq ail" - - exit 1 -fi - -if ! [ -x "$(command -v sqlx)" ]; then - echo >&2 "Error: `sqlx` is not installed." - echo >&2 "Use:" - echo >&2 "cargo install sqlx-cli --no-default-features --features native-tls,postgres" - echo >&2 "to install it." - exit 1 -fi - -DB_USER="${POSTGRES_USER:=postgres}" -DB_PASSWORD="${POSTGRES_PASSWORD:=password}" -DB_PORT="${POSTGRES_PORT:=5432}" -DB_HOST="${POSTGRES_HOST:=localhost}" -DB_NAME="${POSTGRES_DB:=appflowy}" - -if [[ -z "${SKIP_DOCKER}" ]] -then - RUNNING_POSTGRES_CONTAINER=$(docker ps --filter 'name=postgres' --format '{{.ID}}') - if [[ -n $RUNNING_POSTGRES_CONTAINER ]]; then - echo >&2 "there is a postgres container already running, kill it with" - echo >&2 " docker kill ${RUNNING_POSTGRES_CONTAINER}" - exit 1 - fi - - docker build -t postgres_with_pgjwt -f ./docker/Dockerfile_postgres . - - docker run \ - -e POSTGRES_USER=${DB_USER} \ - -e POSTGRES_PASSWORD=${DB_PASSWORD} \ - -e POSTGRES_DB="${DB_NAME}" \ - -p "${DB_PORT}":5432 \ - -d \ - --name "postgres_$(date '+%s')" \ - postgres:14 -N 1000 -fi - - -# Keep pinging Postgres until it's ready to accept commands -until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do - - >&2 echo "Postgres is still unavailable - sleeping" - sleep 1 -done - ->&2 echo "Postgres is up and running on port ${DB_PORT} - running migrations now!" - -export DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME} -sqlx database create -sqlx migrate run - ->&2 echo "Postgres has been migrated, ready to go!" - diff --git a/script/init_gotrue.sh b/script/init_gotrue.sh deleted file mode 100755 index 99461654..00000000 --- a/script/init_gotrue.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -cd "$(dirname "$0")" -set -e - -git clone https://github.com/supabase/gotrue.git -cp gotrue.env.docker gotrue/.env.docker -cd gotrue - -make dev & - -while true; do - curl localhost:9999/health && break - echo "waiting for gotrue to be ready..." - sleep 1 -done diff --git a/script/init_redis.sh b/script/init_redis.sh deleted file mode 100755 index d33a8cb1..00000000 --- a/script/init_redis.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -set -x -set -eo pipefail - -RUNNING_CONTAINER=$(docker ps --filter 'name=appflowy_redis' --format '{{.ID}}') -if [[ -n $RUNNING_CONTAINER ]]; then - echo >&2 "there is a redis container already running, kill it with" - echo >&2 " docker kill ${RUNNING_CONTAINER}" - exit 1 -fi - -# Launch Redis using Docker -docker run \ - -p "6379:6379" \ - -d \ - --name "appflowy_redis_$(date '+%s')" \ - redis:7 - ->&2 echo "Redis is ready to go!" \ No newline at end of file diff --git a/script/run_local_server.sh b/script/run_local_server.sh index 10a87c5e..4ab84b41 100755 --- a/script/run_local_server.sh +++ b/script/run_local_server.sh @@ -9,6 +9,11 @@ DB_PASSWORD="${POSTGRES_PASSWORD:=password}" DB_PORT="${POSTGRES_PORT:=5432}" DB_HOST="${POSTGRES_HOST:=localhost}" +if [ ! -f .env ]; then + echo ".env file not found in the current directory. Try: cp dev.env .env" + exit 1 +fi + # Stop and remove any existing containers to avoid conflicts docker compose --file ./docker-compose-dev.yml down @@ -47,13 +52,20 @@ done # To generate the .sqlx files, we need to run the following command # After the .sqlx files are generated, we build in SQLX_OFFLINE=true # where we don't need to connect to the database +# for example: SQLX_OFFLINE=true ./script/run_local_server.sh cargo sqlx database create && cargo sqlx migrate run if [[ -z "${SKIP_SQLX_PREPARE+x}" ]] then cargo sqlx prepare --workspace fi + +# To skip this step, set SKIP_APPFLOWY_CLOUD=true before running the script, like this:” +# SKIP_APPFLOWY_CLOUD=true ./script/run_local_server.sh. By default, this step is not skipped. +if [[ -z "${SKIP_APPFLOWY_CLOUD+x}" ]] +then cargo run --package xtask +fi # revert to require signup email verification export GOTRUE_MAILER_AUTOCONFIRM=false