From af75e8a2c00d9f8f2dd444bb50c30dd5ba490e3d Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Tue, 30 Apr 2024 19:37:52 +0800 Subject: [PATCH] chore: update configuration for ai docker (#512) * chore: update configuration for ai docker * chore: add script to test ci docker * chore: update docs * chore: update docs --- .github/workflows/integration_test.yml | 2 +- build/run_ci_server.sh | 33 ++++++++++++++++++++++++++ deploy.env | 7 +++--- dev.env | 12 ++++++---- docker-compose-ci.yml | 10 ++++---- docker-compose-dev.yml | 7 +++--- docker-compose.yml | 10 ++++---- src/application.rs | 3 ++- src/config/config.rs | 18 +++++++++++--- 9 files changed, 74 insertions(+), 28 deletions(-) create mode 100755 build/run_ci_server.sh diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index a9833134..bafac13e 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -47,7 +47,7 @@ jobs: sed -i 's/GOTRUE_RATE_LIMIT_EMAIL_SENT=100/GOTRUE_RATE_LIMIT_EMAIL_SENT=1000/' .env sed -i 's/APPFLOWY_MAILER_SMTP_USERNAME=.*/APPFLOWY_MAILER_SMTP_USERNAME=${{ secrets.CI_GOTRUE_SMTP_USER }}/' .env sed -i 's/APPFLOWY_MAILER_SMTP_PASSWORD=.*/APPFLOWY_MAILER_SMTP_PASSWORD=${{ secrets.CI_GOTRUE_SMTP_PASS }}/' .env - sed -i 's/OPENAI_API_KEY=.*/OPENAI_API_KEY=${{ secrets.CI_OPENAI_API_KEY }}/' .env + sed -i 's/APPFLOWY_AI_OPENAI_API_KEY=.*/APPFLOWY_AI_OPENAI_API_KEY=${{ secrets.CI_OPENAI_API_KEY }}/' .env - name: Update Nginx Configuration run: | diff --git a/build/run_ci_server.sh b/build/run_ci_server.sh new file mode 100755 index 00000000..d36a56b0 --- /dev/null +++ b/build/run_ci_server.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -x +set -eo pipefail + +cd "$(dirname "$0")/.." + +# This script simulates the continuous integration (CI) environment on a local machine. It +# requires a `.env` file to be located in the project's root directory. The values in the `.env` +# file must be updated to reflect the specifications of the CI environment. +# Check if .env file exists in the current directory + +if [ -f ".env" ]; then + echo ".env file exists" +else + echo ".env file does not exist. Copying deploy.env to .env and update the values" + exit 1 # Exit with an error code to indicate failure +fi + +# Make sure to update the test client configuration in libs/client-api-test-util/src/client.rs +# export LOCALHOST_URL="http://localhost" +# export LOCALHOST_WS_URL="ws://localhost/ws" +# export LOCALHOST_GOTRUE_URL="http://localhost:gotrue" + +docker compose down +docker compose -f docker-compose-ci.yml pull + +# SKIP_BUILD_APPFLOWY_CLOUD=true. +if [[ -z "${SKIP_BUILD_APPFLOWY_CLOUD+x}" ]] +then + docker build -t appflowy_cloud . +fi + +docker compose -f docker-compose-ci.yml up -d \ No newline at end of file diff --git a/deploy.env b/deploy.env index 465e2431..8b0a2e13 100644 --- a/deploy.env +++ b/deploy.env @@ -105,10 +105,9 @@ CLOUDFLARE_TUNNEL_TOKEN= # APPFLOWY_DATABASE_URL=postgres://POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:5432/$POSTGRES_DB # AppFlowy AI -OPENAI_API_KEY= -APPFLOWY_AI_URL=http://appflowy_ai:5001 -# The SERVER_NAME is environment variable for AppFlowy AI server. By default, it is localhost:5001 -APPFLOWY_AI_SERVER_NAME=appflowy_ai:5001 +APPFLOWY_AI_OPENAI_API_KEY= +APPFLOWY_AI_SERVER_HOST=appflowy_ai +APPFLOWY_AI_SERVER_PORT=5001 # AppFlowy History APPFLOWY_HISTORY_URL=http://history:50051 diff --git a/dev.env b/dev.env index bea90e6e..e18e7a02 100644 --- a/dev.env +++ b/dev.env @@ -97,9 +97,11 @@ GF_SECURITY_ADMIN_PASSWORD=password CLOUDFLARE_TUNNEL_TOKEN= # AppFlowy AI -OPENAI_API_KEY= -APPFLOWY_AI_URL=http://localhost:5001 -# The SERVER_NAME is environment variable for AppFlowy AI server. By default, it is localhost:5001 -APPFLOWY_AI_SERVER_NAME=localhost:5001 +APPFLOWY_AI_OPENAI_API_KEY= +APPFLOWY_AI_SERVER_HOST=localhost +APPFLOWY_AI_SERVER_PORT=5001 -APPFLOWY_HISTORY_DATABASE_URL=postgres://postgres:password@localhost:5432/postgres +# AppFlowy History +APPFLOWY_HISTORY_URL=http://history:50051 +APPFLOWY_HISTORY_REDIS_URL=redis://redis:6379 +APPFLOWY_HISTORY_DATABASE_URL=postgres://postgres:password@postgres:5432/postgres diff --git a/docker-compose-ci.yml b/docker-compose-ci.yml index 78261095..6b53b247 100644 --- a/docker-compose-ci.yml +++ b/docker-compose-ci.yml @@ -112,7 +112,8 @@ services: - APPFLOWY_S3_BUCKET=${APPFLOWY_S3_BUCKET} - APPFLOWY_S3_REGION=${APPFLOWY_S3_REGION} - APPFLOWY_ACCESS_CONTROL=${APPFLOWY_ACCESS_CONTROL} - - APPFLOWY_AI_URL=${APPFLOWY_AI_URL} + - APPFLOWY_AI_SERVER_HOST=${APPFLOWY_AI_SERVER_HOST} + - APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT} build: context: . dockerfile: Dockerfile @@ -137,10 +138,9 @@ services: ports: - "5001:5001" environment: - - FLASK_DEBUG=false - - FLASK_SKIP_DOTENV=true - - OPENAI_API_KEY=${OPENAI_API_KEY} - - SERVER_NAME=${APPFLOWY_AI_SERVER_NAME} + - OPENAI_API_KEY=${APPFLOWY_AI_OPENAI_API_KEY} + - APPFLOWY_AI_SERVER_HOST=${APPFLOWY_AI_SERVER_HOST} + - APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT} appflowy_history: restart: on-failure diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index b3f30383..1e13fc74 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -107,10 +107,9 @@ services: ports: - 5001:5001 environment: - - FLASK_DEBUG=false - - FLASK_SKIP_DOTENV=true - - OPENAI_API_KEY=${OPENAI_API_KEY} - - SERVER_NAME=${APPFLOWY_AI_SERVER_NAME} + - OPENAI_API_KEY=${APPFLOWY_AI_OPENAI_API_KEY} + - APPFLOWY_AI_SERVER_HOST=${APPFLOWY_AI_SERVER_HOST} + - APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT} volumes: postgres_data: diff --git a/docker-compose.yml b/docker-compose.yml index 4d2f465d..a995fc78 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -108,7 +108,8 @@ services: - APPFLOWY_S3_BUCKET=${APPFLOWY_S3_BUCKET} - APPFLOWY_S3_REGION=${APPFLOWY_S3_REGION} - APPFLOWY_ACCESS_CONTROL=${APPFLOWY_ACCESS_CONTROL} - - APPFLOWY_AI_URL=${APPFLOWY_AI_URL} + - APPFLOWY_AI_SERVER_HOST=${APPFLOWY_AI_SERVER_HOST} + - APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT} build: context: . dockerfile: Dockerfile @@ -134,10 +135,9 @@ services: ports: - "5001:5001" environment: - - FLASK_DEBUG=false - - FLASK_SKIP_DOTENV=true - - OPENAI_API_KEY=${OPENAI_API_KEY} - - SERVER_NAME=${APPFLOWY_AI_SERVER_NAME} + - OPENAI_API_KEY=${APPFLOWY_AI_OPENAI_API_KEY} + - APPFLOWY_AI_SERVER_HOST=${APPFLOWY_AI_SERVER_HOST} + - APPFLOWY_AI_SERVER_PORT=${APPFLOWY_AI_SERVER_PORT} volumes: postgres_data: diff --git a/src/application.rs b/src/application.rs index 8a04a07a..d86837de 100644 --- a/src/application.rs +++ b/src/application.rs @@ -187,7 +187,8 @@ pub async fn init_state(config: &Config, rt_cmd_tx: RTCommandSender) -> Result, + pub port: Secret, + pub host: Secret, +} + +impl AppFlowyAISetting { + pub fn url(&self) -> String { + format!( + "http://{}:{}", + self.host.expose_secret(), + self.port.expose_secret() + ) + } } // We are using 127.0.0.1 as our host in address, we are instructing our @@ -165,7 +176,8 @@ pub fn get_configuration() -> Result { region: get_env_var("APPFLOWY_S3_REGION", ""), }, appflowy_ai: AppFlowyAISetting { - url: get_env_var("APPFLOWY_AI_URL", "http://localhost:5001").into(), + port: get_env_var("APPFLOWY_AI_SERVER_PORT", "5001").into(), + host: get_env_var("APPFLOWY_AI_SERVER_HOST", "localhost").into(), }, grpc_history: GrpcHistorySetting { addrs: get_env_var("APPFLOWY_GRPC_HISTORY_ADDRS", "http://localhost:50051"),