Skip to content

Commit dd8bda9

Browse files
update
1 parent b5b18c7 commit dd8bda9

1 file changed

Lines changed: 287 additions & 0 deletions

File tree

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
#!/bin/bash
2+
3+
# Główny skrypt do zarządzania kontenerem llm-orchestrator-min
4+
# Autor: Tom
5+
# Data: 2025-05-13
6+
7+
set -e
8+
9+
# Kolory do lepszej czytelności
10+
RED='\033[0;31m'
11+
GREEN='\033[0;32m'
12+
YELLOW='\033[0;33m'
13+
BLUE='\033[0;34m'
14+
NC='\033[0m' # No Color
15+
16+
# Funkcja do wyświetlania komunikatów
17+
log() {
18+
local level=$1
19+
local message=$2
20+
21+
case $level in
22+
"INFO")
23+
echo -e "${GREEN}[INFO]${NC} $message"
24+
;;
25+
"WARN")
26+
echo -e "${YELLOW}[WARN]${NC} $message"
27+
;;
28+
"ERROR")
29+
echo -e "${RED}[ERROR]${NC} $message"
30+
;;
31+
*)
32+
echo -e "${BLUE}[DEBUG]${NC} $message"
33+
;;
34+
esac
35+
}
36+
37+
# Funkcja do budowania kontenera z optymalizacjami
38+
build_container() {
39+
log "INFO" "Budowanie kontenera llm-orchestrator-min z optymalizacjami cache..."
40+
41+
# Sprawdzenie czy BuildKit jest dostępny
42+
if docker buildx version &>/dev/null; then
43+
log "INFO" "Używam BuildKit do budowania kontenera"
44+
export DOCKER_BUILDKIT=1
45+
46+
# Tworzenie wolumenów cache jeśli nie istnieją
47+
docker volume create coboarding-pip-cache &>/dev/null || true
48+
docker volume create coboarding-wheel-cache &>/dev/null || true
49+
50+
# Budowanie z wykorzystaniem BuildKit i cache
51+
cd /home/tom/github/coboarding/python
52+
docker buildx build \
53+
--build-arg BUILDKIT_INLINE_CACHE=1 \
54+
--cache-from llm-orchestrator-min:latest \
55+
--tag llm-orchestrator-min:latest \
56+
--file containers/llm-orchestrator-min/Dockerfile \
57+
.
58+
else
59+
log "WARN" "BuildKit nie jest dostępny, używam standardowego buildera Docker"
60+
cd /home/tom/github/coboarding/python
61+
docker build \
62+
-t llm-orchestrator-min:latest \
63+
-f containers/llm-orchestrator-min/Dockerfile \
64+
.
65+
fi
66+
67+
log "INFO" "Kontener zbudowany pomyślnie"
68+
}
69+
70+
# Funkcja do uruchamiania kontenera
71+
run_container() {
72+
local port=${1:-5000}
73+
74+
log "INFO" "Uruchamianie kontenera llm-orchestrator-min na porcie $port..."
75+
76+
# Zatrzymanie istniejącego kontenera jeśli istnieje
77+
docker rm -f llm-orchestrator-min 2>/dev/null || true
78+
79+
# Utworzenie wolumenu dla modeli jeśli nie istnieje
80+
docker volume create coboarding-models-cache &>/dev/null || true
81+
82+
# Uruchomienie kontenera z wolumenem dla modeli
83+
docker run -d \
84+
--name llm-orchestrator-min \
85+
-p $port:5000 \
86+
-e API_PORT=5000 \
87+
-e USE_INT8=true \
88+
-v coboarding-models-cache:/app/models \
89+
llm-orchestrator-min:latest
90+
91+
log "INFO" "Kontener uruchomiony, czekam na inicjalizację API..."
92+
93+
# Czekanie na uruchomienie API
94+
local max_attempts=30
95+
local attempt=0
96+
97+
while [ $attempt -lt $max_attempts ]; do
98+
attempt=$((attempt+1))
99+
100+
if curl -s http://localhost:$port/api/health &>/dev/null; then
101+
log "INFO" "API jest dostępne pod adresem: http://localhost:$port"
102+
log "INFO" "Możesz przetestować API używając: curl -X POST -H 'Content-Type: application/json' -d '{\"prompt\":\"Hello\",\"max_length\":50}' http://localhost:$port/api/generate"
103+
return 0
104+
fi
105+
106+
echo -n "."
107+
sleep 1
108+
done
109+
110+
log "ERROR" "API nie uruchomiło się w oczekiwanym czasie"
111+
log "INFO" "Sprawdź logi kontenera: docker logs llm-orchestrator-min"
112+
return 1
113+
}
114+
115+
# Funkcja do diagnostyki kontenera
116+
diagnose_container() {
117+
log "INFO" "Diagnostyka kontenera llm-orchestrator-min..."
118+
119+
# Sprawdzenie czy kontener istnieje
120+
if ! docker ps -a | grep -q llm-orchestrator-min; then
121+
log "ERROR" "Kontener llm-orchestrator-min nie istnieje"
122+
return 1
123+
fi
124+
125+
# Sprawdzenie czy kontener działa
126+
if ! docker ps | grep -q llm-orchestrator-min; then
127+
log "WARN" "Kontener llm-orchestrator-min nie jest uruchomiony"
128+
129+
# Sprawdzenie logów
130+
log "INFO" "Ostatnie logi kontenera:"
131+
docker logs --tail 20 llm-orchestrator-min
132+
133+
# Próba uruchomienia
134+
log "INFO" "Próba uruchomienia kontenera..."
135+
docker start llm-orchestrator-min
136+
sleep 5
137+
138+
if docker ps | grep -q llm-orchestrator-min; then
139+
log "INFO" "Kontener został uruchomiony"
140+
else
141+
log "ERROR" "Nie udało się uruchomić kontenera"
142+
return 1
143+
fi
144+
fi
145+
146+
# Uruchomienie skryptu diagnostycznego w kontenerze
147+
log "INFO" "Uruchamianie diagnostyki wewnątrz kontenera..."
148+
docker exec llm-orchestrator-min /app/scripts/diagnose_api.sh || {
149+
log "WARN" "Nie można uruchomić skryptu diagnostycznego w kontenerze"
150+
log "INFO" "Kopiuję skrypt diagnostyczny do kontenera..."
151+
docker cp /home/tom/github/coboarding/python/containers/llm-orchestrator-min/scripts/diagnose_api.sh llm-orchestrator-min:/app/scripts/
152+
docker exec llm-orchestrator-min chmod +x /app/scripts/diagnose_api.sh
153+
docker exec llm-orchestrator-min /app/scripts/diagnose_api.sh
154+
}
155+
156+
return 0
157+
}
158+
159+
# Funkcja do naprawy kontenera
160+
fix_container() {
161+
log "INFO" "Naprawa kontenera llm-orchestrator-min..."
162+
163+
# Sprawdzenie czy kontener istnieje
164+
if ! docker ps -a | grep -q llm-orchestrator-min; then
165+
log "ERROR" "Kontener llm-orchestrator-min nie istnieje, najpierw go zbuduj i uruchom"
166+
return 1
167+
fi
168+
169+
# Uruchomienie skryptu naprawczego w kontenerze
170+
log "INFO" "Uruchamianie skryptu naprawczego wewnątrz kontenera..."
171+
docker exec llm-orchestrator-min /app/scripts/fix_common_issues.sh || {
172+
log "WARN" "Nie można uruchomić skryptu naprawczego w kontenerze"
173+
log "INFO" "Kopiuję skrypt naprawczy do kontenera..."
174+
docker cp /home/tom/github/coboarding/python/containers/llm-orchestrator-min/scripts/fix_common_issues.sh llm-orchestrator-min:/app/scripts/
175+
docker exec llm-orchestrator-min chmod +x /app/scripts/fix_common_issues.sh
176+
docker exec llm-orchestrator-min /app/scripts/fix_common_issues.sh
177+
}
178+
179+
# Restart kontenera
180+
log "INFO" "Restart kontenera..."
181+
docker restart llm-orchestrator-min
182+
183+
# Czekanie na uruchomienie API
184+
log "INFO" "Czekam na uruchomienie API..."
185+
local max_attempts=30
186+
local attempt=0
187+
188+
while [ $attempt -lt $max_attempts ]; do
189+
attempt=$((attempt+1))
190+
191+
if curl -s http://localhost:5000/api/health &>/dev/null; then
192+
log "INFO" "API jest dostępne pod adresem: http://localhost:5000"
193+
return 0
194+
fi
195+
196+
echo -n "."
197+
sleep 1
198+
done
199+
200+
log "ERROR" "API nie uruchomiło się po naprawie"
201+
return 1
202+
}
203+
204+
# Funkcja do testowania API
205+
test_api() {
206+
log "INFO" "Testowanie API llm-orchestrator-min..."
207+
208+
# Sprawdzenie czy kontener działa
209+
if ! docker ps | grep -q llm-orchestrator-min; then
210+
log "ERROR" "Kontener llm-orchestrator-min nie jest uruchomiony"
211+
return 1
212+
fi
213+
214+
# Uruchomienie skryptu testowego w kontenerze
215+
log "INFO" "Uruchamianie testów API..."
216+
docker exec llm-orchestrator-min /app/scripts/test_api.sh || {
217+
log "WARN" "Nie można uruchomić skryptu testowego w kontenerze"
218+
log "INFO" "Kopiuję skrypt testowy do kontenera..."
219+
docker cp /home/tom/github/coboarding/python/containers/llm-orchestrator-min/scripts/test_api.sh llm-orchestrator-min:/app/scripts/
220+
docker exec llm-orchestrator-min chmod +x /app/scripts/test_api.sh
221+
docker exec llm-orchestrator-min /app/scripts/test_api.sh
222+
}
223+
224+
return 0
225+
}
226+
227+
# Funkcja do zarządzania cache
228+
manage_cache() {
229+
log "INFO" "Zarządzanie cache Docker..."
230+
231+
# Uruchomienie skryptu zarządzania cache
232+
/home/tom/github/coboarding/python/containers/llm-orchestrator-min/scripts/manage_cache.sh "$1"
233+
234+
return 0
235+
}
236+
237+
# Funkcja pomocy
238+
show_help() {
239+
echo -e "${BLUE}=== Zarządzanie kontenerem llm-orchestrator-min ===${NC}"
240+
echo ""
241+
echo "Użycie: $0 [opcja]"
242+
echo ""
243+
echo "Opcje:"
244+
echo " build - Buduje kontener z optymalizacjami cache"
245+
echo " run [port] - Uruchamia kontener (domyślny port: 5000)"
246+
echo " diagnose - Diagnostyka kontenera i API"
247+
echo " fix - Naprawa typowych problemów"
248+
echo " test - Testowanie API"
249+
echo " cache - Zarządzanie cache Docker"
250+
echo " help - Wyświetla tę pomoc"
251+
echo ""
252+
echo "Przykłady:"
253+
echo " $0 build # Buduje kontener"
254+
echo " $0 run 5001 # Uruchamia kontener na porcie 5001"
255+
echo " $0 diagnose # Diagnostyka kontenera"
256+
echo ""
257+
}
258+
259+
# Główna logika skryptu
260+
case "$1" in
261+
build)
262+
build_container
263+
;;
264+
run)
265+
run_container "$2"
266+
;;
267+
diagnose)
268+
diagnose_container
269+
;;
270+
fix)
271+
fix_container
272+
;;
273+
test)
274+
test_api
275+
;;
276+
cache)
277+
manage_cache "$2"
278+
;;
279+
help|--help|-h)
280+
show_help
281+
;;
282+
*)
283+
show_help
284+
;;
285+
esac
286+
287+
exit 0

0 commit comments

Comments
 (0)