forked from RedisLabs/pubsub-sub-bench
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-test.sh
More file actions
executable file
·136 lines (115 loc) · 4.05 KB
/
docker-test.sh
File metadata and controls
executable file
·136 lines (115 loc) · 4.05 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
#!/bin/bash
# Docker test script for local validation
# This script mimics the GitHub Action validation locally
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
# Function to print colored output
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_step() {
echo -e "${BLUE}[STEP]${NC} $1"
}
# Configuration
IMAGE_NAME="pubsub-sub-bench-test"
TAG="local-test"
FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
print_info "Starting Docker validation tests..."
# Step 0: Check Docker Hub credentials (optional for local testing)
print_step "Checking Docker Hub credentials..."
if [[ -n "$DOCKER_USERNAME" && -n "$DOCKER_PASSWORD" ]]; then
print_info "✅ Docker Hub credentials found in environment"
elif docker info | grep -q "Username:"; then
print_info "✅ Already logged in to Docker Hub"
else
print_warning "⚠️ Docker Hub credentials not found"
print_info "Set DOCKER_USERNAME and DOCKER_PASSWORD environment variables or run 'docker login' for publishing"
fi
# Step 1: Build the image
print_step "Building Docker image..."
if ./docker-build.sh -n "$IMAGE_NAME" -t "$TAG"; then
print_info "✅ Docker build successful"
else
print_error "❌ Docker build failed"
exit 1
fi
# Step 2: Test basic functionality
print_step "Testing basic functionality..."
# Test help command
print_info "Testing --help command..."
if docker run --rm "$FULL_IMAGE_NAME" --help > /dev/null; then
print_info "✅ Help command works"
else
print_error "❌ Help command failed"
exit 1
fi
# Test version command
print_info "Testing --version command..."
if docker run --rm "$FULL_IMAGE_NAME" --version > /dev/null; then
print_info "✅ Version command works"
else
print_error "❌ Version command failed"
exit 1
fi
# Step 3: Test with Redis (if available)
print_step "Testing Redis connectivity (optional)..."
if command -v redis-server > /dev/null; then
print_info "Redis server found, testing connectivity..."
# Start Redis in background if not running
if ! pgrep redis-server > /dev/null; then
print_info "Starting Redis server..."
redis-server --port 6379 --daemonize yes
sleep 2
fi
# Test connection
if timeout 5 docker run --rm --network=host "$FULL_IMAGE_NAME" \
-host localhost -port 6379 -test-time 2 -clients 1 \
-channel-minimum 1 -channel-maximum 1 -mode subscribe > /dev/null 2>&1; then
print_info "✅ Redis connectivity test passed"
else
print_warning "⚠️ Redis connectivity test failed (this may be expected if no publisher is running)"
fi
else
print_warning "⚠️ Redis server not found, skipping connectivity test"
fi
# Step 4: Test file output permissions
print_step "Testing file output permissions..."
TEMP_DIR=$(mktemp -d)
if docker run --rm -v "$TEMP_DIR:/app/output" "$FULL_IMAGE_NAME" \
-json-out-file test-output.json -test-time 1 -clients 1 \
-channel-minimum 1 -channel-maximum 1 -mode subscribe > /dev/null 2>&1; then
if [ -f "$TEMP_DIR/test-output.json" ]; then
print_info "✅ File output test passed"
else
print_warning "⚠️ JSON file not created (expected if no messages received)"
fi
else
print_warning "⚠️ File output test completed with warnings (expected without Redis publisher)"
fi
rm -rf "$TEMP_DIR"
# Step 5: Test image size
print_step "Checking image size..."
IMAGE_SIZE=$(docker images --format "table {{.Size}}" "$FULL_IMAGE_NAME" | tail -n 1)
print_info "Image size: $IMAGE_SIZE"
# Step 6: Clean up
print_step "Cleaning up..."
docker rmi "$FULL_IMAGE_NAME" > /dev/null 2>&1 || true
print_info "🎉 All Docker validation tests completed successfully!"
print_info ""
print_info "Summary:"
print_info " ✅ Docker build successful"
print_info " ✅ Basic functionality tests passed"
print_info " ✅ Image size: $IMAGE_SIZE"
print_info ""
print_info "The Docker setup is ready for production use!"