-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathcompose-deploy.sh
More file actions
executable file
·235 lines (186 loc) · 8.6 KB
/
Copy pathcompose-deploy.sh
File metadata and controls
executable file
·235 lines (186 loc) · 8.6 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
#!/usr/bin/env bash
# ===============================================================================
#
# ██████╗██╗ ██╗ █████╗ ██████╗ ███████╗██╗███╗ ███╗██╗ ██╗██╗ █████╗ ████████╗ ██████╗ ██████╗
# ██╔════╝██║ ██╔╝██╔══██╗██╔══██╗ ██╔════╝██║████╗ ████║██║ ██║██║ ██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗
# ██║ █████╔╝ ███████║██║ ██║ ███████╗██║██╔████╔██║██║ ██║██║ ███████║ ██║ ██║ ██║██████╔╝
# ██║ ██╔═██╗ ██╔══██║██║ ██║ ╚════██║██║██║╚██╔╝██║██║ ██║██║ ██╔══██║ ██║ ██║ ██║██╔══██╗
# ╚██████╗██║ ██╗██║ ██║██████╔╝ ███████║██║██║ ╚═╝ ██║╚██████╔╝███████╗██║ ██║ ██║ ╚██████╔╝██║ ██║
# ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
#
# ===============================================================================
# Docker Compose CKAD Deployment Script
# Version: 1.0.0
# Author: Nishan B
# ===============================================================================
set -e
# Define colors for better readability
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
GRAY='\033[0;90m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Define symbols
CHECK="${GREEN}✓${NC}"
CROSS="${RED}✗${NC}"
INFO="${BLUE}ℹ${NC}"
WARN="${YELLOW}⚠${NC}"
ARROW="${CYAN}➜${NC}"
STAR="${PURPLE}★${NC}"
CLOCK="${YELLOW}⏱${NC}"
# Define variables
SCRIPT_START_TIME=$(date +%s)
# ===============================================================================
# UTILITY FUNCTIONS
# ===============================================================================
# Print timestamp
print_timestamp() {
echo -e "${GRAY}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"
}
# Print section header
print_header() {
local title="$1"
local title_length=${#title}
local total_length=80
local side_length=$(( (total_length - title_length - 2) / 2 ))
local side_line=$(printf '%*s' "$side_length" | tr ' ' '═')
echo -e "\n${BOLD}${PURPLE}$side_line${NC} ${BOLD}${CYAN}$title${NC} ${BOLD}${PURPLE}$side_line${NC}\n"
}
# Print success message
print_success() {
print_timestamp "${CHECK} ${GREEN}$1${NC}"
}
# Print info message
print_info() {
print_timestamp "${INFO} $1"
}
# Print warning message
print_warning() {
print_timestamp "${WARN} ${YELLOW}$1${NC}"
}
# Print error message
print_error() {
print_timestamp "${CROSS} ${RED}$1${NC}" >&2
}
# Print progress
print_progress() {
echo -e " ${ARROW} ${GRAY}$1${NC}"
}
# Error handler
handle_error() {
print_error "An error occurred at line $1"
print_error "Deployment failed!"
exit 1
}
# Calculate elapsed time
elapsed_time() {
local end_time=$(date +%s)
local elapsed=$((end_time - SCRIPT_START_TIME))
local minutes=$((elapsed / 60))
local seconds=$((elapsed % 60))
echo "${minutes}m ${seconds}s"
}
# Setup error handling
trap 'handle_error $LINENO' ERR
# ===============================================================================
# MAIN SCRIPT
# ===============================================================================
print_header "DEPLOYMENT STARTED"
print_info "Starting deployment process for CKAD Simulator with Docker Compose"
# ===============================================================================
# DOCKER IMAGE BUILDING
# ===============================================================================
print_header "DOCKER IMAGE BUILDING"
print_progress "Building Docker images via Docker Compose..."
COMPOSE_BAKE=true docker compose build
print_success "All Docker images built successfully"
# ===============================================================================
# DOCKER COMPOSE DEPLOYMENT
# ===============================================================================
print_header "DOCKER COMPOSE DEPLOYMENT"
print_progress "Starting Docker Compose services..."
docker compose up -d --remove-orphans
print_success "All services started successfully"
# ===============================================================================
# SERVICE AVAILABILITY CHECK
# ===============================================================================
print_header "SERVICE AVAILABILITY CHECK"
print_progress "${CLOCK} Waiting for services to be ready..."
sleep 15 # Give some time for services to start
# Check if the VNC service is running
if docker compose ps remote-desktop | grep "Up"; then
print_success "VNC service is running"
else
print_warning "VNC service may not be running properly"
fi
# Check if the webapp service is running
if docker compose ps webapp | grep "Up"; then
print_success "Webapp service is running"
else
print_warning "Webapp service may not be running properly"
fi
# Check if the Nginx service is running
if docker compose ps nginx | grep "Up"; then
print_success "Nginx service is running"
else
print_warning "Nginx service may not be running properly"
fi
# Check if the jumphost service is running
if docker compose ps jumphost | grep "Up"; then
print_success "Jump host service is running"
else
print_warning "Jump host service may not be running properly"
fi
# Check if the Kubernetes cluster service is running
if docker compose ps k8s-api-server | grep "Up"; then
print_success "Kubernetes cluster is running"
# Wait for the KIND cluster to be fully ready
print_progress "${CLOCK} Waiting for Kubernetes cluster to be fully initialized..."
sleep 30
# Check if cluster is accessible
if docker compose exec k8s-api-server kind get clusters | grep "kind-cluster"; then
print_success "KIND cluster is operational and accessible"
else
print_warning "KIND cluster may still be initializing"
fi
else
print_warning "Kubernetes cluster may not be running properly"
fi
# ===============================================================================
# DEPLOYMENT SUMMARY
# ===============================================================================
TOTAL_TIME=$(elapsed_time)
print_header 'DEPLOYMENT SUMMARY'
echo -e "${STAR} ${GREEN}Deployment completed successfully!${NC}"
echo -e "${INFO} ${CYAN}Environment:${NC} CKAD Simulator (Docker Compose)"
echo -e "${INFO} ${CYAN}Services deployed:${NC} 5 (remote-desktop, webapp, nginx, jumphost, k8s-api-server)"
echo -e "${INFO} ${CYAN}Total elapsed time:${NC} ${YELLOW}${TOTAL_TIME}${NC}"
echo -e "\n${STAR} ${GREEN}Your CKAD simulator is ready to use!${NC} ${STAR}\n"
# ===============================================================================
# ACCESS INFORMATION
# ===============================================================================
print_header "ACCESS INFORMATION"
# Get the host IP address
HOST_IP=$(hostname -I | awk '{print $1}')
if [ -z "$HOST_IP" ]; then
HOST_IP="localhost"
fi
echo -e "${CYAN}The following services are available:${NC}"
echo -e "\n${STAR} ${GREEN}Access Simulator here:${NC} ${BOLD}http://${HOST_IP}:30080${NC}"
#open browser on host machine
open http://${HOST_IP}:30080
echo -e "${INFO} ${GRAY}Note: All other services (VNC, jumphost, K8s) are only accessible internally through the web application.${NC}"
# ===============================================================================
# HELPFUL COMMANDS
# ===============================================================================
print_header "HELPFUL COMMANDS"
echo -e "${CYAN}To stop the environment:${NC}"
echo -e " ${GREEN}docker compose down --volumes --remove-orphans${NC}"
echo -e "\n${CYAN}To restart the environment:${NC}"
echo -e " ${GREEN}docker compose restart${NC}"
echo -e "\n${CYAN}To view logs:${NC}"
echo -e " ${GREEN}docker compose logs -f${NC}"