-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathstart_services.py
95 lines (81 loc) · 3.16 KB
/
start_services.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/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()