-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
142 lines (114 loc) · 4.85 KB
/
Copy pathdeploy.py
File metadata and controls
142 lines (114 loc) · 4.85 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""
deploy.py
This script deploys the w7-ragKB AI Agent stack with different configurations:
- Local: Integrates with existing AI stack (no Caddy, uses overrides for existing Caddy)
- Cloud: Standalone deployment with its own Caddy reverse proxy
Usage:
python deploy.py --type local --project localai # Join existing AI stack
python deploy.py --type cloud # Standalone cloud deployment
python deploy.py --down --type local --project localai # Stop services
"""
import argparse
import subprocess
import sys
import os
def run_command(cmd, cwd=None):
"""Run a shell command and print it."""
print("Running:", " ".join(cmd))
try:
subprocess.run(cmd, cwd=cwd, check=True)
except subprocess.CalledProcessError as e:
print(f"Command failed with exit code {e.returncode}")
sys.exit(1)
def validate_environment():
"""Check that required files exist."""
required_files = ["docker-compose.yml"]
for file in required_files:
if not os.path.exists(file):
print(f"Error: Required file '{file}' not found in current directory")
sys.exit(1)
def deploy_agent_stack(deployment_type, project_name, action="up"):
"""Deploy or stop the agent stack based on deployment type."""
# Build base command
cmd = ["docker", "compose", "-p", project_name, "-f", "docker-compose.yml"]
# Add deployment-specific compose files
if deployment_type == "cloud":
if not os.path.exists("docker-compose.caddy.yml"):
print("Error: docker-compose.caddy.yml not found for cloud deployment")
sys.exit(1)
cmd.extend(["-f", "docker-compose.caddy.yml"])
print(f"Cloud deployment: Including Caddy service")
elif deployment_type == "local":
print(f"Local deployment: Deploying agent services to join AI stack network")
else:
print(f"Error: Invalid deployment type '{deployment_type}'")
sys.exit(1)
# Add action (up/down)
if action == "up":
cmd.extend(["up", "-d", "--build"])
print(f"Starting {deployment_type} deployment with project name '{project_name}' (rebuilding containers)...")
elif action == "down":
cmd.extend(["down"])
print(f"Stopping {deployment_type} deployment with project name '{project_name}'...")
# Execute command
run_command(cmd)
if action == "up":
print(f"\n✅ {deployment_type.title()} deployment completed successfully!")
if deployment_type == "local":
print("\n📝 Local Deployment Notes:")
print("- Agent services joined your existing AI stack network")
print("- To enable reverse proxy routes in your Local AI Package:")
print(" 1. Copy caddy-addon.conf to your Local AI Package's caddy-addon folder")
print(" 2. Edit lines 2 and 21 in caddy-addon.conf to set your subdomains")
print(" 3. Restart Caddy: docker compose -p localai restart caddy")
print(f"- Services running under project: {project_name}")
elif deployment_type == "cloud":
print("\n📝 Cloud Deployment Notes:")
print("- Standalone deployment with integrated Caddy")
print("- Configure AGENT_API_HOSTNAME and FRONTEND_HOSTNAME in .env")
print("- Caddy will automatically provision SSL certificates")
print("- Services accessible via configured hostnames")
else:
print(f"\n✅ {deployment_type.title()} deployment stopped successfully!")
def main():
parser = argparse.ArgumentParser(
description='Deploy the w7-ragKB AI Agent stack',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Local deployment (join existing AI stack)
python deploy.py --type local --project localai
# Cloud deployment (standalone with Caddy)
python deploy.py --type cloud
# Stop local deployment
python deploy.py --down --type local --project localai
# Stop cloud deployment
python deploy.py --down --type cloud
"""
)
parser.add_argument(
'--type',
choices=['local', 'cloud'],
required=True,
help='Deployment type: local (join AI stack) or cloud (standalone)'
)
parser.add_argument(
'--project',
default='w7ragkb-agent',
help='Docker Compose project name (default: w7ragkb-agent)'
)
parser.add_argument(
'--down',
action='store_true',
help='Stop and remove containers instead of starting them'
)
args = parser.parse_args()
# Validate environment
validate_environment()
# Determine action
action = "down" if args.down else "up"
# Deploy
deploy_agent_stack(args.type, args.project, action)
if __name__ == "__main__":
main()