forked from comet-ml/opik
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopik.sh
More file actions
executable file
·206 lines (181 loc) · 7.33 KB
/
opik.sh
File metadata and controls
executable file
·206 lines (181 loc) · 7.33 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
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
#!/bin/bash
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REQUIRED_CONTAINERS=("opik-clickhouse-1" "opik-mysql-1" "opik-python-backend-1" "opik-redis-1" "opik-frontend-1" "opik-backend-1" "opik-minio-1")
print_usage() {
echo "Usage: opik.sh [OPTION]"
echo ""
echo "Options:"
echo " --verify Check if all containers are healthy"
echo " --info Display welcome system status, only if all containers are running"
echo " --stop Stop all containers and clean up"
echo " --debug Enable debug mode (verbose output)"
echo " --help Show this help message"
echo ""
echo "If no option is passed, the script will start missing containers and then show the system status."
}
check_docker_status() {
# Ensure Docker is running
if ! docker info >/dev/null 2>&1; then
echo "❌ Docker is not running or not accessible. Please start Docker first."
exit 1
fi
}
check_containers_status() {
local show_output="${1:-false}"
local all_ok=true
check_docker_status
for container in "${REQUIRED_CONTAINERS[@]}"; do
status=$(docker inspect -f '{{.State.Status}}' "$container" 2>/dev/null)
health=$(docker inspect -f '{{.State.Health.Status}}' "$container" 2>/dev/null)
if [[ "$status" != "running" ]]; then
echo "❌ $container is not running (status=$status)"
all_ok=false
elif [[ "$health" != "" && "$health" != "healthy" ]]; then
echo "❌ $container is running but not healthy (health=$health)"
all_ok=false
else
[[ "$show_output" == "true" ]] && echo "✅ $container is running and healthy"
fi
done
$all_ok && return 0 || return 1
}
start_missing_containers() {
check_docker_status
[[ "$DEBUG_MODE" == true ]] && echo "🔍 Checking required containers..."
all_running=true
for container in "${REQUIRED_CONTAINERS[@]}"; do
status=$(docker inspect -f '{{.State.Status}}' "$container" 2>/dev/null)
if [[ "$status" != "running" ]]; then
[[ "$DEBUG_MODE" == true ]] && echo "🔴 $container is not running (status: ${status:-not found})"
all_running=false
else
[[ "$DEBUG_MODE" == true ]] && echo "✅ $container is already running"
fi
done
echo "🔄 Starting missing containers..."
cd "$script_dir/deployment/docker-compose"
docker compose up -d
echo "⏳ Waiting for all containers to be running and healthy..."
max_retries=60
interval=1
for container in "${REQUIRED_CONTAINERS[@]}"; do
retries=0
[[ "$DEBUG_MODE" == true ]] && echo "⏳ Waiting for $container..."
while true; do
status=$(docker inspect -f '{{.State.Status}}' "$container" 2>/dev/null)
health=$(docker inspect -f '{{.State.Health.Status}}' "$container" 2>/dev/null)
if [[ "$status" != "running" ]]; then
echo "❌ $container failed to start (status: $status)"
break
fi
if [[ "$health" == "healthy" ]]; then
[[ "$DEBUG_MODE" == true ]] && echo "✅ $container is now running and healthy!"
break
elif [[ "$health" == "starting" ]]; then
[[ "$DEBUG_MODE" == true ]] && echo "⏳ $container is starting... retrying (${retries}s)"
sleep "$interval"
retries=$((retries + 1))
if [[ $retries -ge $max_retries ]]; then
echo "⚠️ $container is still not healthy after ${max_retries}s"
break
fi
else
echo "❌ $container health state is '$health'"
break
fi
done
done
}
stop_containers() {
check_docker_status
echo "🛑 Stopping all required containers..."
cd "$script_dir/deployment/docker-compose"
docker compose stop
echo "✅ All containers stopped and cleaned up!"
}
print_banner() {
check_docker_status
frontend_port=$(docker inspect -f '{{ (index (index .NetworkSettings.Ports "5173/tcp") 0).HostPort }}' opik-frontend-1 2>/dev/null)
ui_url="http://localhost:${frontend_port:-5173}"
echo ""
echo "╔═════════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ 🚀 OPIK PLATFORM 🚀 ║"
echo "║ ║"
echo "╠═════════════════════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ ✅ All services started successfully! ║"
echo "║ ║"
echo "║ 📊 Access the UI: ║"
echo "║ $ui_url ║"
echo "║ ║"
echo "║ 🛠️ Configure the Python SDK: ║"
echo "║ \$ python --version ║"
echo "║ \$ pip install opik ║"
echo "║ \$ opik configure ║"
echo "║ ║"
echo "║ 📚 Documentation: https://www.comet.com/docs/opik/ ║"
echo "║ ║"
echo "║ 💬 Need help? Join our community: https://chat.comet.com ║"
echo "║ ║"
echo "╚═════════════════════════════════════════════════════════════════╝"
}
# Default: no debug
DEBUG_MODE=false
# Main logic
case "$1" in
--verify)
echo "🔍 Verifying container health..."
check_containers_status "true"
exit $?
;;
--info)
echo "ℹ️ Checking if all containers are up before displaying system status..."
if check_containers_status "true"; then
print_banner
exit 0
else
echo "⚠️ Some containers are not running/healthy. Please run './opik.sh' to start them."
exit 1
fi
;;
--stop)
stop_containers
exit 0
;;
--help)
print_usage
exit 0
;;
--debug)
DEBUG_MODE=true
echo "🐞 Debug mode enabled."
echo "🔍 Checking container status and starting missing ones..."
start_missing_containers
sleep 2
echo "🔄 Re-checking container status..."
if check_containers_status; then
print_banner
else
echo "⚠️ Some containers are still not healthy. Please check manually using './opik.sh --verify'"
exit 1
fi
;;
"")
echo "🔍 Checking container status and starting missing ones..."
start_missing_containers
sleep 2
echo "🔄 Re-checking container status..."
if check_containers_status "true"; then
print_banner
else
echo "⚠️ Some containers are still not healthy. Please check manually using './opik.sh --verify'"
exit 1
fi
;;
*)
echo "❌ Unknown option: $1"
print_usage
exit 1
;;
esac