Spaces:
Sleeping
Sleeping
File size: 10,245 Bytes
526927a |
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
#!/usr/bin/env python3
"""
Docker ๋ฐฐํฌ ํ
์คํธ ์คํฌ๋ฆฝํธ
Docker ์ปจํ
์ด๋๊ฐ ์ ์์ ์ผ๋ก ์คํ๋๊ณ ์๋์ง ํ์ธ
"""
import requests
import time
import subprocess
import json
import sys
import os
def check_docker_installation():
"""Docker ์ค์น ํ์ธ"""
try:
result = subprocess.run(['docker', '--version'],
capture_output=True, text=True, check=True)
print(f"โ
Docker ์ค์น๋จ: {result.stdout.strip()}")
return True
except subprocess.CalledProcessError:
print("โ Docker๊ฐ ์ค์น๋์ง ์์์ต๋๋ค.")
return False
except FileNotFoundError:
print("โ Docker๊ฐ ์ค์น๋์ง ์์์ต๋๋ค.")
return False
def check_docker_compose_installation():
"""Docker Compose ์ค์น ํ์ธ"""
try:
result = subprocess.run(['docker-compose', '--version'],
capture_output=True, text=True, check=True)
print(f"โ
Docker Compose ์ค์น๋จ: {result.stdout.strip()}")
return True
except subprocess.CalledProcessError:
print("โ Docker Compose๊ฐ ์ค์น๋์ง ์์์ต๋๋ค.")
return False
except FileNotFoundError:
print("โ Docker Compose๊ฐ ์ค์น๋์ง ์์์ต๋๋ค.")
return False
def check_dockerfile():
"""Dockerfile ์กด์ฌ ํ์ธ"""
if os.path.exists('Dockerfile'):
print("โ
Dockerfile ์กด์ฌ")
return True
else:
print("โ Dockerfile์ด ์กด์ฌํ์ง ์์ต๋๋ค.")
return False
def check_docker_compose_file():
"""docker-compose.yml ์กด์ฌ ํ์ธ"""
if os.path.exists('docker-compose.yml'):
print("โ
docker-compose.yml ์กด์ฌ")
return True
else:
print("โ docker-compose.yml์ด ์กด์ฌํ์ง ์์ต๋๋ค.")
return False
def build_docker_image():
"""Docker ์ด๋ฏธ์ง ๋น๋"""
try:
print("๐จ Docker ์ด๋ฏธ์ง ๋น๋ ์ค...")
result = subprocess.run(['docker-compose', 'build'],
capture_output=True, text=True, check=True)
print("โ
Docker ์ด๋ฏธ์ง ๋น๋ ์ฑ๊ณต")
return True
except subprocess.CalledProcessError as e:
print(f"โ Docker ์ด๋ฏธ์ง ๋น๋ ์คํจ: {e.stderr}")
return False
def start_services():
"""์๋น์ค ์์"""
try:
print("๐ ์๋น์ค ์์ ์ค...")
result = subprocess.run(['docker-compose', 'up', '-d'],
capture_output=True, text=True, check=True)
print("โ
์๋น์ค ์์ ์ฑ๊ณต")
return True
except subprocess.CalledProcessError as e:
print(f"โ ์๋น์ค ์์ ์คํจ: {e.stderr}")
return False
def check_service_status():
"""์๋น์ค ์ํ ํ์ธ"""
try:
result = subprocess.run(['docker-compose', 'ps'],
capture_output=True, text=True, check=True)
print("๐ ์๋น์ค ์ํ:")
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"โ ์๋น์ค ์ํ ํ์ธ ์คํจ: {e.stderr}")
return False
def wait_for_api_ready(max_wait=60):
"""API ์ค๋น ๋๊ธฐ"""
print("โณ API ์ค๋น ๋๊ธฐ ์ค...")
for i in range(max_wait):
try:
response = requests.get('http://localhost:8001/health', timeout=5)
if response.status_code == 200:
print(f"โ
API ์ค๋น ์๋ฃ ({i+1}์ด)")
return True
except requests.exceptions.RequestException:
pass
time.sleep(1)
print("โ API ์ค๋น ์๊ฐ ์ด๊ณผ")
return False
def test_api_endpoints():
"""API ์๋ํฌ์ธํธ ํ
์คํธ"""
endpoints = [
('/health', 'GET'),
('/models', 'GET'),
('/generate', 'POST')
]
print("๐งช API ์๋ํฌ์ธํธ ํ
์คํธ:")
for endpoint, method in endpoints:
try:
if method == 'GET':
response = requests.get(f'http://localhost:8001{endpoint}', timeout=10)
elif method == 'POST' and endpoint == '/generate':
# ๊ฐ๋จํ ์์ฑ ํ
์คํธ
data = {
'prompt': '์๋
ํ์ธ์',
'model_id': 'polyglot-ko-1.3b-chat',
'max_length': 50,
'temperature': 0.7
}
response = requests.post(f'http://localhost:8001{endpoint}',
data=data, timeout=30)
else:
continue
if response.status_code in [200, 201]:
print(f"โ
{endpoint} - {response.status_code}")
else:
print(f"โ ๏ธ {endpoint} - {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"โ {endpoint} - ์ค๋ฅ: {e}")
def test_redis_connection():
"""Redis ์ฐ๊ฒฐ ํ
์คํธ"""
try:
result = subprocess.run(['docker-compose', 'exec', '-T', 'redis', 'redis-cli', 'ping'],
capture_output=True, text=True, check=True)
if 'PONG' in result.stdout:
print("โ
Redis ์ฐ๊ฒฐ ์ฑ๊ณต")
return True
else:
print("โ Redis ์ฐ๊ฒฐ ์คํจ")
return False
except subprocess.CalledProcessError:
print("โ Redis ์ฐ๊ฒฐ ์คํจ")
return False
def test_celery_worker():
"""Celery Worker ํ
์คํธ"""
try:
result = subprocess.run(['docker-compose', 'exec', '-T', 'celery-worker', 'celery', '-A', 'lily_llm_core.celery_app', 'inspect', 'active'],
capture_output=True, text=True, check=True)
print("โ
Celery Worker ์ ์")
return True
except subprocess.CalledProcessError:
print("โ ๏ธ Celery Worker ํ์ธ ์คํจ (์ ์์ผ ์ ์์)")
return True
def check_flower_monitoring():
"""Flower ๋ชจ๋ํฐ๋ง ํ์ธ"""
try:
response = requests.get('http://localhost:5555', timeout=5)
if response.status_code == 200:
print("โ
Flower ๋ชจ๋ํฐ๋ง ์ ๊ทผ ๊ฐ๋ฅ")
return True
else:
print("โ ๏ธ Flower ๋ชจ๋ํฐ๋ง ์ ๊ทผ ๋ถ๊ฐ")
return False
except requests.exceptions.RequestException:
print("โ ๏ธ Flower ๋ชจ๋ํฐ๋ง ์ ๊ทผ ๋ถ๊ฐ")
return False
def stop_services():
"""์๋น์ค ์ค์ง"""
try:
print("๐ ์๋น์ค ์ค์ง ์ค...")
subprocess.run(['docker-compose', 'down'],
capture_output=True, text=True, check=True)
print("โ
์๋น์ค ์ค์ง ์๋ฃ")
return True
except subprocess.CalledProcessError as e:
print(f"โ ์๋น์ค ์ค์ง ์คํจ: {e.stderr}")
return False
def cleanup():
"""์ ๋ฆฌ"""
try:
print("๐งน ์ ๋ฆฌ ์ค...")
subprocess.run(['docker-compose', 'down', '-v'],
capture_output=True, text=True, check=True)
subprocess.run(['docker', 'system', 'prune', '-f'],
capture_output=True, text=True, check=True)
print("โ
์ ๋ฆฌ ์๋ฃ")
return True
except subprocess.CalledProcessError as e:
print(f"โ ์ ๋ฆฌ ์คํจ: {e.stderr}")
return False
def main():
"""๋ฉ์ธ ํ
์คํธ ํจ์"""
print("๐ณ Docker ๋ฐฐํฌ ํ
์คํธ ์์")
print("=" * 50)
# 1. ์ฌ์ ์๊ตฌ์ฌํญ ํ์ธ
print("\n๐ ์ฌ์ ์๊ตฌ์ฌํญ ํ์ธ")
print("-" * 30)
if not check_docker_installation():
return False
if not check_docker_compose_installation():
return False
if not check_dockerfile():
return False
if not check_docker_compose_file():
return False
# 2. Docker ์ด๋ฏธ์ง ๋น๋
print("\n๐จ Docker ์ด๋ฏธ์ง ๋น๋")
print("-" * 30)
if not build_docker_image():
return False
# 3. ์๋น์ค ์์
print("\n๐ ์๋น์ค ์์")
print("-" * 30)
if not start_services():
return False
# 4. ์๋น์ค ์ํ ํ์ธ
print("\n๐ ์๋น์ค ์ํ ํ์ธ")
print("-" * 30)
check_service_status()
# 5. API ์ค๋น ๋๊ธฐ
print("\nโณ API ์ค๋น ๋๊ธฐ")
print("-" * 30)
if not wait_for_api_ready():
print("โ API ์ค๋น ์คํจ")
stop_services()
return False
# 6. API ์๋ํฌ์ธํธ ํ
์คํธ
print("\n๐งช API ์๋ํฌ์ธํธ ํ
์คํธ")
print("-" * 30)
test_api_endpoints()
# 7. Redis ์ฐ๊ฒฐ ํ
์คํธ
print("\n๐ด Redis ์ฐ๊ฒฐ ํ
์คํธ")
print("-" * 30)
test_redis_connection()
# 8. Celery Worker ํ
์คํธ
print("\n๐ฟ Celery Worker ํ
์คํธ")
print("-" * 30)
test_celery_worker()
# 9. Flower ๋ชจ๋ํฐ๋ง ํ์ธ
print("\n๐ธ Flower ๋ชจ๋ํฐ๋ง ํ์ธ")
print("-" * 30)
check_flower_monitoring()
# 10. ๊ฒฐ๊ณผ ์์ฝ
print("\n๐ ํ
์คํธ ๊ฒฐ๊ณผ ์์ฝ")
print("-" * 30)
print("โ
Docker ๋ฐฐํฌ ํ
์คํธ ์๋ฃ!")
print("\n๐ ์ ๊ทผ ๊ฐ๋ฅํ ์๋น์ค:")
print(" - API Server: http://localhost:8001")
print(" - Health Check: http://localhost:8001/health")
print(" - Flower Monitor: http://localhost:5555")
print("\n๐ ์ ์ฉํ ๋ช
๋ น์ด:")
print(" - ๋ก๊ทธ ํ์ธ: docker-compose logs")
print(" - ์๋น์ค ์ํ: docker-compose ps")
print(" - ์๋น์ค ์ค์ง: docker-compose down")
print(" - ์ ๋ฆฌ: docker-compose down -v && docker system prune -f")
return True
if __name__ == "__main__":
try:
success = main()
if not success:
print("\nโ Docker ๋ฐฐํฌ ํ
์คํธ ์คํจ")
sys.exit(1)
else:
print("\n๐ Docker ๋ฐฐํฌ ํ
์คํธ ์ฑ๊ณต!")
except KeyboardInterrupt:
print("\nโ ๏ธ ์ฌ์ฉ์์ ์ํด ์ค๋จ๋จ")
stop_services()
sys.exit(1)
except Exception as e:
print(f"\nโ ์์์น ๋ชปํ ์ค๋ฅ: {e}")
stop_services()
sys.exit(1) |