forked from FudanSELab/train-ticket-auto-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redeploy_service_old.sh
executable file
·78 lines (61 loc) · 2.26 KB
/
redeploy_service_old.sh
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
#!/bin/bash
# Function for consistent log formatting
log_info() {
echo -e "\n[INFO] $(date '+%Y-%m-%d %H:%M:%S') - $1"
}
log_error() {
echo -e "\n[ERROR] $(date '+%Y-%m-%d %H:%M:%S') - $1" >&2
}
log_success() {
echo -e "\n[SUCCESS] $(date '+%Y-%m-%d %H:%M:%S') - $1"
}
# Function to build and deploy a service
build_and_deploy_service() {
local service=$1
local tag=$2
log_info "Starting deployment process for $service"
# Navigate to the service directory
cd "${service}" || { log_error "Failed to navigate to ${service} directory"; return 1; }
# Build Docker image
log_info "Building Docker image for $service:$tag"
if ! sudo docker build -t "docclabgroup/${service}:${tag}" .; then
log_error "Docker build failed for $service"
return 1
fi
# Push Docker image
log_info "Pushing Docker image for $service:$tag"
if ! sudo docker push "docclabgroup/${service}:${tag}"; then
log_error "Docker push failed for $service"
return 1
fi
# Update Kubernetes deployment
log_info "Updating Kubernetes deployment for $service"
if ! kubectl set image "deployment/${service}" "${service}=docclabgroup/${service}:${tag}"; then
log_error "Kubernetes deployment update failed for $service"
return 1
fi
# Wait for rollout
log_info "Waiting for rollout completion of $service"
if ! kubectl rollout status "deployment/${service}"; then
log_error "Kubernetes rollout failed for $service"
return 1
fi
cd .. || { log_error "Failed to navigate back from ${service} directory"; return 1; }
log_success "Successfully deployed $service"
}
# Main execution starts here
log_info "Starting main execution"
cd /local/train-ticket-2 || { log_error "Failed to navigate to train-ticket directory"; exit 1; }
sudo chown -R $(whoami) .
# First Phase: Maven Build
log_info "Phase 2: Building project with Maven"
if ! mvn clean install -DskipTests; then
log_error "Maven build failed"
exit 1
fi
log_success "Maven build completed"
# Second Phase: Build and Deploy Services
echo -e "\n----------------------------------------"
log_info "Building and deploying service: $1"
build_and_deploy_service "$1" "$2"
echo "----------------------------------------"