-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
100 lines (84 loc) · 2.51 KB
/
deploy.sh
File metadata and controls
100 lines (84 loc) · 2.51 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
#!/bin/bash
# Build and deployment script for the Stress Test Application
set -e
# Configuration
IMAGE_NAME="stress-test-app"
IMAGE_TAG="latest"
NAMESPACE="default"
echo "=== .NET Core Stress Test Application Build & Deploy ==="
# Function to print usage
print_usage() {
echo "Usage: $0 [build|deploy|build-deploy|clean]"
echo " build - Build Docker image"
echo " deploy - Deploy to Kubernetes"
echo " build-deploy - Build and deploy"
echo " clean - Clean up Kubernetes resources"
exit 1
}
# Function to build Docker image
build_image() {
echo "Building Docker image..."
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
echo "Docker image built successfully: ${IMAGE_NAME}:${IMAGE_TAG}"
}
# Function to deploy to Kubernetes
deploy_to_k8s() {
echo "Deploying to Kubernetes..."
# Apply ConfigMap first
kubectl apply -f k8s/configmap.yaml -n ${NAMESPACE}
# Apply Deployment and Service
kubectl apply -f k8s/deployment.yaml -n ${NAMESPACE}
echo "Deployment completed successfully"
echo "Checking deployment status..."
kubectl get pods -l app=stress-test-app -n ${NAMESPACE}
kubectl get services -l app=stress-test-app -n ${NAMESPACE}
}
# Function to clean up resources
clean_resources() {
echo "Cleaning up Kubernetes resources..."
kubectl delete -f k8s/deployment.yaml -n ${NAMESPACE} --ignore-not-found=true
kubectl delete -f k8s/configmap.yaml -n ${NAMESPACE} --ignore-not-found=true
echo "Cleanup completed"
}
# Function to check prerequisites
check_prerequisites() {
# Check if Docker is available
if ! command -v docker &> /dev/null; then
echo "Error: Docker is not installed or not in PATH"
exit 1
fi
# Check if kubectl is available
if ! command -v kubectl &> /dev/null; then
echo "Error: kubectl is not installed or not in PATH"
exit 1
fi
# Check if we can connect to Kubernetes cluster
if ! kubectl cluster-info &> /dev/null; then
echo "Error: Cannot connect to Kubernetes cluster"
exit 1
fi
}
# Main script logic
case "${1:-}" in
"build")
check_prerequisites
build_image
;;
"deploy")
check_prerequisites
deploy_to_k8s
;;
"build-deploy")
check_prerequisites
build_image
deploy_to_k8s
;;
"clean")
check_prerequisites
clean_resources
;;
*)
print_usage
;;
esac
echo "Operation completed successfully!"