-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-production.sh
More file actions
executable file
·265 lines (231 loc) · 6.93 KB
/
Copy pathtest-production.sh
File metadata and controls
executable file
·265 lines (231 loc) · 6.93 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
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
#!/bin/bash
# Trackeep Production Readiness Test Script
# This script tests all critical components before deployment
set -e
echo "========================================="
echo "Trackeep Production Readiness Test"
echo "========================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test counters
PASSED=0
FAILED=0
WARNINGS=0
# Helper functions
pass() {
echo -e "${GREEN}✓ PASS${NC}: $1"
((PASSED++))
}
fail() {
echo -e "${RED}✗ FAIL${NC}: $1"
((FAILED++))
}
warn() {
echo -e "${YELLOW}⚠ WARN${NC}: $1"
((WARNINGS++))
}
# Test 1: Check environment file
echo "Test 1: Environment Configuration"
if [ -f ".env" ]; then
pass "Environment file exists"
# Check required variables
required_vars=("DB_PASSWORD" "JWT_SECRET" "ENCRYPTION_KEY")
for var in "${required_vars[@]}"; do
if grep -q "^${var}=" .env && ! grep -q "^${var}=$" .env && ! grep -q "^${var}=<" .env; then
pass "$var is set"
else
fail "$var is not set or uses placeholder value"
fi
done
else
fail "Environment file (.env) not found"
fi
echo ""
# Test 2: Check Docker
echo "Test 2: Docker Environment"
if command -v docker &> /dev/null; then
pass "Docker is installed"
docker_version=$(docker --version | awk '{print $3}' | tr -d ',')
echo " Docker version: $docker_version"
else
fail "Docker is not installed"
fi
if command -v docker-compose &> /dev/null; then
pass "Docker Compose is installed"
compose_version=$(docker-compose --version | awk '{print $4}' | tr -d ',')
echo " Docker Compose version: $compose_version"
else
fail "Docker Compose is not installed"
fi
echo ""
# Test 3: Check backend build
echo "Test 3: Backend Build"
if [ -d "backend" ]; then
pass "Backend directory exists"
cd backend
if [ -f "go.mod" ]; then
pass "Go module file exists"
# Try to build
echo " Building backend..."
if go build -o /tmp/trackeep-test 2>&1 | tee /tmp/build.log; then
pass "Backend builds successfully"
rm -f /tmp/trackeep-test
else
fail "Backend build failed (see /tmp/build.log)"
cat /tmp/build.log
fi
else
fail "go.mod not found"
fi
cd ..
else
fail "Backend directory not found"
fi
echo ""
# Test 4: Check frontend
echo "Test 4: Frontend Build"
if [ -d "frontend" ]; then
pass "Frontend directory exists"
cd frontend
if [ -f "package.json" ]; then
pass "package.json exists"
if [ -d "node_modules" ]; then
pass "Node modules installed"
else
warn "Node modules not installed (run: npm install)"
fi
# Check if dist exists (built)
if [ -d "dist" ]; then
pass "Frontend is built"
else
warn "Frontend not built (run: npm run build)"
fi
else
fail "package.json not found"
fi
cd ..
else
fail "Frontend directory not found"
fi
echo ""
# Test 5: Check Docker Compose configuration
echo "Test 5: Docker Compose Configuration"
if [ -f "docker-compose.prod.yml" ]; then
pass "Production docker-compose file exists"
# Validate docker-compose file
if docker-compose -f docker-compose.prod.yml config > /dev/null 2>&1; then
pass "Docker Compose configuration is valid"
else
fail "Docker Compose configuration has errors"
fi
else
fail "docker-compose.prod.yml not found"
fi
echo ""
# Test 6: Security checks
echo "Test 6: Security Configuration"
# Check JWT secret strength
if [ -f ".env" ]; then
jwt_secret=$(grep "^JWT_SECRET=" .env | cut -d'=' -f2)
if [ ${#jwt_secret} -ge 32 ]; then
pass "JWT_SECRET has sufficient length (${#jwt_secret} chars)"
else
fail "JWT_SECRET is too short (${#jwt_secret} chars, minimum 32)"
fi
# Check encryption key strength
enc_key=$(grep "^ENCRYPTION_KEY=" .env | cut -d'=' -f2)
if [ ${#enc_key} -ge 32 ]; then
pass "ENCRYPTION_KEY has sufficient length (${#enc_key} chars)"
else
fail "ENCRYPTION_KEY is too short (${#enc_key} chars, minimum 32)"
fi
fi
# Check for default passwords
if grep -q "password123\|admin123\|changeme" .env 2>/dev/null; then
fail "Default/weak passwords detected in .env"
else
pass "No obvious default passwords found"
fi
echo ""
# Test 7: Port availability
echo "Test 7: Port Availability"
check_port() {
local port=$1
local service=$2
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
warn "Port $port ($service) is already in use"
else
pass "Port $port ($service) is available"
fi
}
check_port 8080 "Backend"
check_port 5432 "PostgreSQL"
check_port 6379 "DragonflyDB"
check_port 80 "Frontend"
echo ""
# Test 8: Disk space
echo "Test 8: System Resources"
available_space=$(df -BG . | tail -1 | awk '{print $4}' | tr -d 'G')
if [ "$available_space" -ge 20 ]; then
pass "Sufficient disk space available (${available_space}GB)"
else
warn "Low disk space (${available_space}GB, recommended: 20GB+)"
fi
# Check memory
total_mem=$(free -g | awk '/^Mem:/{print $2}')
if [ "$total_mem" -ge 4 ]; then
pass "Sufficient memory available (${total_mem}GB)"
else
warn "Low memory (${total_mem}GB, recommended: 4GB+)"
fi
echo ""
# Test 9: Database migrations
echo "Test 9: Database Schema"
if [ -d "backend/migrations" ]; then
migration_count=$(ls -1 backend/migrations/*.sql 2>/dev/null | wc -l)
if [ "$migration_count" -gt 0 ]; then
pass "Database migrations found ($migration_count files)"
else
warn "No SQL migration files found (using auto-migration)"
fi
else
warn "Migrations directory not found"
fi
echo ""
# Test 10: SSL/TLS Configuration
echo "Test 10: SSL/TLS Configuration"
if [ -f "nginx.conf" ] || [ -f "/etc/nginx/sites-available/trackeep" ]; then
pass "Nginx configuration found"
if grep -q "ssl_certificate" nginx.conf 2>/dev/null || grep -q "ssl_certificate" /etc/nginx/sites-available/trackeep 2>/dev/null; then
pass "SSL configuration detected"
else
warn "SSL not configured (recommended for production)"
fi
else
warn "Nginx configuration not found (consider using reverse proxy)"
fi
echo ""
# Summary
echo "========================================="
echo "Test Summary"
echo "========================================="
echo -e "${GREEN}Passed: $PASSED${NC}"
echo -e "${YELLOW}Warnings: $WARNINGS${NC}"
echo -e "${RED}Failed: $FAILED${NC}"
echo ""
if [ $FAILED -eq 0 ]; then
if [ $WARNINGS -eq 0 ]; then
echo -e "${GREEN}✓ All tests passed! Ready for production deployment.${NC}"
exit 0
else
echo -e "${YELLOW}⚠ Tests passed with warnings. Review warnings before deployment.${NC}"
exit 0
fi
else
echo -e "${RED}✗ Some tests failed. Fix issues before deploying to production.${NC}"
exit 1
fi