mirror of
https://github.com/kossakovsky/n8n-install.git
synced 2026-03-07 22:33:11 +00:00
95 lines
3.2 KiB
Python
95 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
start_services.py
|
|
|
|
This script starts the Supabase stack first, waits for it to initialize, and then starts
|
|
the local AI stack. Both stacks use the same Docker Compose project name ("localai")
|
|
so they appear together in Docker Desktop.
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
import shutil
|
|
import time
|
|
import argparse
|
|
|
|
def run_command(cmd, cwd=None):
|
|
"""Run a shell command and print it."""
|
|
print("Running:", " ".join(cmd))
|
|
subprocess.run(cmd, cwd=cwd, check=True)
|
|
|
|
def clone_supabase_repo():
|
|
"""Clone the Supabase repository using sparse checkout if not already present."""
|
|
if not os.path.exists("supabase"):
|
|
print("Cloning the Supabase repository...")
|
|
run_command([
|
|
"git", "clone", "--filter=blob:none", "--no-checkout",
|
|
"https://github.com/supabase/supabase.git"
|
|
])
|
|
os.chdir("supabase")
|
|
run_command(["git", "sparse-checkout", "init", "--cone"])
|
|
run_command(["git", "sparse-checkout", "set", "docker"])
|
|
run_command(["git", "checkout", "master"])
|
|
os.chdir("..")
|
|
else:
|
|
print("Supabase repository already exists, updating...")
|
|
os.chdir("supabase")
|
|
run_command(["git", "pull"])
|
|
os.chdir("..")
|
|
|
|
def prepare_supabase_env():
|
|
"""Copy .env to .env in supabase/docker."""
|
|
env_path = os.path.join("supabase", "docker", ".env")
|
|
env_example_path = os.path.join(".env")
|
|
print("Copying .env in root to .env in supabase/docker...")
|
|
shutil.copyfile(env_example_path, env_path)
|
|
|
|
def stop_existing_containers():
|
|
"""Stop and remove existing containers for our unified project ('localai')."""
|
|
print("Stopping and removing existing containers for the unified project 'localai'...")
|
|
run_command([
|
|
"docker", "compose",
|
|
"-p", "localai",
|
|
"-f", "docker-compose.yml",
|
|
"-f", "supabase/docker/docker-compose.yml",
|
|
"down"
|
|
])
|
|
|
|
def start_supabase():
|
|
"""Start the Supabase services (using its compose file)."""
|
|
print("Starting Supabase services...")
|
|
run_command([
|
|
"docker", "compose", "-p", "localai", "-f", "supabase/docker/docker-compose.yml", "up", "-d"
|
|
])
|
|
|
|
def start_local_ai(profile=None):
|
|
"""Start the local AI services (using its compose file)."""
|
|
print("Starting local AI services...")
|
|
cmd = ["docker", "compose", "-p", "localai"]
|
|
if profile and profile != "none":
|
|
cmd.extend(["--profile", profile])
|
|
cmd.extend(["-f", "docker-compose.yml", "up", "-d"])
|
|
run_command(cmd)
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='Start the local AI and Supabase services.')
|
|
parser.add_argument('--profile', choices=['cpu', 'gpu-nvidia', 'gpu-amd', 'none'], default='cpu',
|
|
help='Profile to use for Docker Compose (default: cpu)')
|
|
args = parser.parse_args()
|
|
|
|
clone_supabase_repo()
|
|
prepare_supabase_env()
|
|
stop_existing_containers()
|
|
|
|
# Start Supabase first
|
|
start_supabase()
|
|
|
|
# Give Supabase some time to initialize
|
|
print("Waiting for Supabase to initialize...")
|
|
time.sleep(10)
|
|
|
|
# Then start the local AI services
|
|
start_local_ai(args.profile)
|
|
|
|
if __name__ == "__main__":
|
|
main() |