diff --git a/.env.example b/.env.example index 9bd751f..4550137 100644 --- a/.env.example +++ b/.env.example @@ -27,6 +27,13 @@ N8N_RUNNERS_AUTH_TOKEN=change_me_to_a_long_super-secret-key # Specific JWT secret. By default, n8n generates one on start N8N_USER_MANAGEMENT_JWT_SECRET=change_me_to_a_longer_even-more-secret +############ +# [required] +# PostgreSQL database user password +############ + +POSTGRES_PASSWORD=your-super-secret-postgres-password + ############ # [required] # Supabase Secrets @@ -41,7 +48,6 @@ N8N_USER_MANAGEMENT_JWT_SECRET=change_me_to_a_longer_even-more-secret # If you use special symbols in your Postgres password, you must remember to percent-encode your password later if using the Postgres connection string, for example, postgresql://postgres.projectref:p%3Dword@aws-0-us-east-1.pooler.supabase.com:6543/postgres ############ -POSTGRES_PASSWORD=your-super-secret-postgres-password JWT_SECRET=your-super-secret-jwt-token-with-at-least-40-characters-long ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q @@ -201,10 +207,10 @@ GOOGLE_PROJECT_NUMBER=GOOGLE_PROJECT_NUMBER # PostgreSQL - You can change these to any PostgreSQL database that has logical replication enabled. ############ -POSTGRES_HOST=db POSTGRES_DB=postgres -POSTGRES_PORT=5432 POSTGRES_USER=postgres +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 ############ # Supavisor -- Database pooler and others that can be left as default values diff --git a/docker-compose.yml b/docker-compose.yml index df27dcb..efba2ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ volumes: opencode_data: open_webui_data: open_webui_pipelines_data: - langfuse_postgres_data: + postgres_data: langfuse_clickhouse_data: langfuse_clickhouse_logs: langfuse_minio_data: @@ -285,19 +285,19 @@ services: image: postgres:${POSTGRES_VERSION:-17} container_name: postgres restart: unless-stopped - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 3s - timeout: 3s - retries: 10 expose: - 5432/tcp environment: - POSTGRES_DB: postgres - POSTGRES_USER: postgres - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} volumes: - - langfuse_postgres_data:/var/lib/postgresql/data + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ['CMD-SHELL', 'pg_isready -h ${POSTGRES_HOST} -U ${POSTGRES_USER} -d ${POSTGRES_DB}'] + interval: 3s + timeout: 3s + retries: 10 qdrant: profiles: ["n8n", "n8n-all", "ai-all"] diff --git a/suite_services.py b/suite_services.py index 15c9b7f..229fa5c 100644 --- a/suite_services.py +++ b/suite_services.py @@ -602,7 +602,49 @@ def set_variable_in_env_file(env_file=None, key=None , value=None, header=None): variable = "".join([header, key]) if header else key dotenv.set_key(env_file, variable, value) -def main() +def update_n8n_database_settings(env_file=None, supabase=False): + """Set POSTGRES_HOST in .env file and n8n database depends_on and + postgres volume in Docker Compose file. + """ + key = "POSTGRES_HOST" + value = "db" if supabase else "postgres" + set_variable_in_env_file(env_file, key, value, None) + + old_vol = "postgres_data" if supabase else "langfuse_postgres_data" + compose_file = os.path.join("docker-compose.yml") + try: + with open(compose_file, 'r') as f: + content = f.read() + regex = r"\b{}\b\:".format(old_vol) + if re.search(regex, content): + new_vol = "langfuse_postgres_data:" if supabase else "postgres_data:" + print(f"Set Postgres volume: from '{old_vol}' to '{new_vol}' in {compose_file}...") + modified_content = re.sub(r"\b{}\b\:".format(old_vol), new_vol, content) + with open(compose_file, 'w') as f: + f.write(modified_content) + + with open(compose_file, 'r+') as f: + updated = False + n8n_found = False + old_db = "postgres:" if supabase else "db:" + new_db = f"{value}:" + lines = f.readlines() + f.seek(0) + f.truncate() + for line in lines: + if not updated: + if line == ' n8n:\n': + n8n_found = True + if n8n_found: + if line == f' {old_db}\n': + line = f" {new_db}\n" + updated = True + print(f"Set n8n database depends_on: from '{old_db}' " \ + f"to '{new_db}' in {compose_file}...") + f.write(line) + except Exception as e: + print(f"Exception: Update n8n database settings in {compose_file}: {e}") + def main(): # Name and version information global name @@ -781,6 +823,11 @@ def main(): args.profile.remove('supabase') if 'supabase' in args.profile else None clone_supabase_repo() convert_supabase_pooler_line_endings() + + if any(profile for profile in args.profile if profile in n8n_all_profiles): + update_n8n_database_settings(env_file, supabase) + + if supabase: prepare_supabase_env() elif 'langfuse' in args.profile: print("""Profile argument 'langfuse' requires Supabase - removing 'langfuse'...'""")