-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·259 lines (222 loc) · 6.53 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·259 lines (222 loc) · 6.53 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
#!/bin/bash
# Relay Test Script
# This script helps test the Relay container auto-updater on your local machine
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOCKER_DIR="$SCRIPT_DIR/docker"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
print_header() {
echo -e "\n${BLUE}════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}════════════════════════════════════════════════════════════${NC}\n"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}! $1${NC}"
}
print_info() {
echo -e "${CYAN}→ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
# Build Relay
build() {
print_header "Building Relay"
cd "$DOCKER_DIR"
docker compose build --no-cache
print_success "Relay built successfully"
}
# Start Relay only
start_relay() {
print_header "Starting Relay"
cd "$DOCKER_DIR"
docker compose up -d
print_success "Relay started"
echo ""
print_info "View logs with: $0 logs"
}
# Start Relay and test containers
start_all() {
print_header "Starting Relay and Test Containers"
cd "$DOCKER_DIR"
docker compose -f docker-compose.yml -f docker-compose.test.yml up -d
print_success "All containers started"
echo ""
show_monitored
}
# Stop all containers
stop() {
print_header "Stopping All Containers"
cd "$DOCKER_DIR"
docker compose -f docker-compose.yml -f docker-compose.test.yml down 2>/dev/null || docker compose down
print_success "All containers stopped"
}
# Restart all containers
restart() {
stop
start_all
}
# Show Relay logs
logs() {
print_header "Relay Logs (last 100 lines)"
docker logs relay --tail 100 2>/dev/null || print_error "Relay container not running"
}
# Follow Relay logs
follow() {
print_header "Following Relay Logs (Ctrl+C to exit)"
docker logs relay -f 2>/dev/null || print_error "Relay container not running"
}
# Show monitored containers
show_monitored() {
print_header "Containers with relay.enable=true"
echo ""
docker ps --filter "label=relay.enable=true" --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Label \"relay.update\"}}" 2>/dev/null || echo "No containers found"
echo ""
}
# Show all containers
ps() {
print_header "All Containers"
docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
}
# Run a complete test cycle
test() {
print_header "Running Complete Test"
echo "Step 1: Building Relay..."
build
echo ""
echo "Step 2: Starting containers..."
start_all
echo ""
echo "Step 3: Waiting for initial check (10 seconds)..."
sleep 10
echo ""
echo "Step 4: Showing Relay logs..."
logs
echo ""
print_success "Test complete!"
echo ""
echo "Next steps:"
echo -e " ${CYAN}$0 follow${NC} - Watch logs in real-time"
echo -e " ${CYAN}$0 monitored${NC} - Show monitored containers"
echo -e " ${CYAN}$0 stop${NC} - Stop all containers"
}
# Quick test without rebuilding
quick() {
print_header "Quick Test (no rebuild)"
cd "$DOCKER_DIR"
docker compose -f docker-compose.yml -f docker-compose.test.yml up -d
echo ""
print_info "Waiting 5 seconds for startup..."
sleep 5
echo ""
show_monitored
echo ""
logs
}
# Check container status
status() {
print_header "Relay Status"
if docker ps --format '{{.Names}}' | grep -q '^relay$'; then
print_success "Relay is running"
echo ""
docker ps --filter "name=relay" --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
else
print_error "Relay is not running"
fi
echo ""
print_header "Monitored Containers"
local count=$(docker ps --filter "label=relay.enable=true" --format '{{.Names}}' 2>/dev/null | wc -l | tr -d ' ')
echo "Found $count container(s) with relay.enable=true"
echo ""
docker ps --filter "label=relay.enable=true" --format "table {{.Names}}\t{{.Image}}\t{{.Label \"relay.update\"}}" 2>/dev/null
}
# Clean up everything
clean() {
print_header "Cleaning Up"
cd "$DOCKER_DIR"
docker compose -f docker-compose.yml -f docker-compose.test.yml down -v --remove-orphans 2>/dev/null || true
docker compose down -v --remove-orphans 2>/dev/null || true
print_success "Cleanup complete"
}
# Print usage
usage() {
echo ""
echo -e "${CYAN}Relay Test Script${NC}"
echo ""
echo "Usage: $0 <command>"
echo ""
echo "Commands:"
echo -e " ${GREEN}build${NC} Build Relay Docker image (with --no-cache)"
echo -e " ${GREEN}start${NC} Start Relay only"
echo -e " ${GREEN}start-all${NC} Start Relay and test containers"
echo -e " ${GREEN}stop${NC} Stop all containers"
echo -e " ${GREEN}restart${NC} Restart all containers"
echo -e " ${GREEN}logs${NC} Show Relay logs (last 100 lines)"
echo -e " ${GREEN}follow${NC} Follow Relay logs in real-time"
echo -e " ${GREEN}monitored${NC} Show containers being monitored"
echo -e " ${GREEN}ps${NC} Show all containers"
echo -e " ${GREEN}status${NC} Show Relay and monitored container status"
echo -e " ${GREEN}test${NC} Run complete test (build + start + verify)"
echo -e " ${GREEN}quick${NC} Quick test without rebuilding"
echo -e " ${GREEN}clean${NC} Stop and remove all containers"
echo ""
echo "Examples:"
echo -e " ${YELLOW}$0 test${NC} # Full test cycle"
echo -e " ${YELLOW}$0 quick${NC} # Quick start without rebuild"
echo -e " ${YELLOW}$0 follow${NC} # Watch logs live"
echo ""
}
# Main command handler
case "${1:-}" in
build)
build
;;
start)
start_relay
;;
start-all)
start_all
;;
stop)
stop
;;
restart)
restart
;;
logs)
logs
;;
follow)
follow
;;
monitored)
show_monitored
;;
ps)
ps
;;
status)
status
;;
test)
test
;;
quick)
quick
;;
clean)
clean
;;
*)
usage
;;
esac