-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-docker-dev.sh
More file actions
executable file
·223 lines (181 loc) · 6.24 KB
/
test-docker-dev.sh
File metadata and controls
executable file
·223 lines (181 loc) · 6.24 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
# Test script for development Docker infrastructure
# Verifies acceptance criteria for Task 117
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Test configuration
BUILD_TIME_TARGET=15
RELOAD_TIME_TARGET=5
IMAGE_SIZE_TARGET_GB=1
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to test build time
test_build_time() {
log_info "Testing build time (target: <${BUILD_TIME_TARGET}s)"
# Clean build test
docker-compose -f docker-compose.dev.yml down > /dev/null 2>&1 || true
docker rmi superego-mcp-dev > /dev/null 2>&1 || true
local start_time=$(date +%s)
docker-compose -f docker-compose.dev.yml build superego-dev --no-cache > /dev/null 2>&1
local end_time=$(date +%s)
local build_time=$((end_time - start_time))
if [ $build_time -le $BUILD_TIME_TARGET ]; then
log_success "Build time: ${build_time}s (target: ≤${BUILD_TIME_TARGET}s) ✓"
return 0
else
log_warning "Build time: ${build_time}s (target: ≤${BUILD_TIME_TARGET}s) - slower than target"
return 1
fi
}
# Function to test image size
test_image_size() {
log_info "Testing image size (target: <${IMAGE_SIZE_TARGET_GB}GB)"
local image_size_mb=$(docker images superego-mcp-dev:latest --format "{{.Size}}" | grep -o '^[0-9.]*' | head -1)
local image_size_gb=$(echo "scale=2; $image_size_mb / 1024" | bc -l 2>/dev/null || echo "unknown")
log_info "Image size: ${image_size_gb}GB"
if [ "$image_size_gb" != "unknown" ] && (( $(echo "$image_size_gb < $IMAGE_SIZE_TARGET_GB" | bc -l) )); then
log_success "Image size: ${image_size_gb}GB (target: <${IMAGE_SIZE_TARGET_GB}GB) ✓"
return 0
else
log_warning "Image size check - manual verification needed"
return 1
fi
}
# Function to test startup time
test_startup_time() {
log_info "Testing container startup time (target: <${BUILD_TIME_TARGET}s)"
local start_time=$(date +%s)
docker-compose -f docker-compose.dev.yml up -d superego-dev > /dev/null 2>&1
# Wait for health check to pass
local health_retries=0
while [ $health_retries -lt 30 ]; do
if curl -sf http://localhost:8000/health > /dev/null 2>&1; then
break
fi
sleep 1
health_retries=$((health_retries + 1))
done
local end_time=$(date +%s)
local startup_time=$((end_time - start_time))
if [ $startup_time -le $BUILD_TIME_TARGET ]; then
log_success "Startup time: ${startup_time}s (target: ≤${BUILD_TIME_TARGET}s) ✓"
return 0
else
log_warning "Startup time: ${startup_time}s (target: ≤${BUILD_TIME_TARGET}s) - slower than target"
return 1
fi
}
# Function to test UV integration
test_uv_integration() {
log_info "Testing UV package manager integration"
# Check UV is installed and working
local uv_version=$(docker-compose -f docker-compose.dev.yml exec -T superego-dev uv --version 2>/dev/null || echo "failed")
if [ "$uv_version" != "failed" ]; then
log_success "UV integration: $uv_version ✓"
return 0
else
log_error "UV integration: failed"
return 1
fi
}
# Function to test debugging support
test_debugging_support() {
log_info "Testing debugging tools installation"
# Check debugpy is available
local debugpy_check=$(docker-compose -f docker-compose.dev.yml exec -T superego-dev uv run python -c "import debugpy; print('debugpy available')" 2>/dev/null || echo "failed")
if [ "$debugpy_check" = "debugpy available" ]; then
log_success "Debugging support: debugpy available ✓"
return 0
else
log_error "Debugging support: debugpy not available"
return 1
fi
}
# Function to test volume mounts
test_volume_mounts() {
log_info "Testing volume mount configuration"
# Test if source code is mounted correctly
local mount_check=$(docker-compose -f docker-compose.dev.yml exec -T superego-dev ls /app/src/superego_mcp/main.py 2>/dev/null || echo "failed")
if [ "$mount_check" != "failed" ]; then
log_success "Volume mounts: source code accessible ✓"
return 0
else
log_error "Volume mounts: source code not accessible"
return 1
fi
}
# Main test execution
main() {
log_info "🚀 Starting Development Docker Infrastructure Tests"
log_info "Testing acceptance criteria for Task 117"
echo ""
local test_results=0
# Test 1: Build time
if ! test_build_time; then
test_results=$((test_results + 1))
fi
echo ""
# Test 2: Image size
if ! test_image_size; then
test_results=$((test_results + 1))
fi
echo ""
# Test 3: Startup time
if ! test_startup_time; then
test_results=$((test_results + 1))
fi
echo ""
# Test 4: UV integration
if ! test_uv_integration; then
test_results=$((test_results + 1))
fi
echo ""
# Test 5: Debugging support
if ! test_debugging_support; then
test_results=$((test_results + 1))
fi
echo ""
# Test 6: Volume mounts
if ! test_volume_mounts; then
test_results=$((test_results + 1))
fi
echo ""
# Cleanup
log_info "Cleaning up test containers..."
docker-compose -f docker-compose.dev.yml down > /dev/null 2>&1 || true
# Summary
if [ $test_results -eq 0 ]; then
log_success "🎉 All tests passed! Development Docker infrastructure meets acceptance criteria"
exit 0
else
log_warning "⚠️ ${test_results} test(s) failed or need manual verification"
log_info "Infrastructure is functional but may not meet all performance targets"
exit 1
fi
}
# Check if required tools are available
if ! command -v docker-compose > /dev/null 2>&1; then
log_error "docker-compose is required but not installed"
exit 1
fi
if ! command -v curl > /dev/null 2>&1; then
log_error "curl is required but not installed"
exit 1
fi
# Run main test
main "$@"