-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy-kubernetes.sh
96 lines (76 loc) · 2.45 KB
/
deploy-kubernetes.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
cd "$(dirname "$0")"
if [ -f ".env" ]; then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
NAMESPACE=${GAMIFICATIONENGINE_NAMESPACE}
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
show_help() {
echo "Usage: $0 [OPTION]"
echo "Apply Kubernetes YAML files for specific components."
echo ""
echo "Options:"
echo " --postgres Apply only the PostgreSQL deployment and its dependencies."
echo " --api Apply only the API deployment and its dependencies."
echo " --verbose Display verbose output."
echo " --help Display this help message."
echo ""
echo "Examples:"
echo " $0 --postgres # Apply only the PostgreSQL deployment."
echo " $0 --api # Apply only the API deployment."
echo " $0 --api --verbose # Apply only the API deployment with verbose output."
}
apply_yaml() {
FILE=$1
VERBOSE=$2
TEMP_FILE="temp-$(basename $FILE)"
envsubst < $FILE > $TEMP_FILE
if [ "$VERBOSE" = "--verbose" ]; then
echo -e "${YELLOW}Executing command: kubectl --namespace $NAMESPACE apply -f $TEMP_FILE${NC}"
fi
kubectl --namespace $NAMESPACE apply -f $TEMP_FILE
if [ $? -eq 0 ]; then
echo -e "${GREEN}[+] Success: The resource $TEMP_FILE has been successfully applied to the namespace $NAMESPACE.${NC}"
else
echo -e "${RED}[-] Error: Failed to apply the resource $TEMP_FILE to the namespace $NAMESPACE.${NC}"
fi
rm $TEMP_FILE
}
for arg in "$@"; do
if [ "$arg" = "--help" ]; then
show_help
exit 0
fi
done
POSTGRES_FILES=(
"kubernetes/volumen/postgres-data-persistentvolumeclaim.yaml"
"kubernetes/services/postgres-service.yaml"
"kubernetes/deployments/postgres-deployment.yaml"
)
API_FILES=(
"kubernetes/configmaps/env-prod-configmap.yaml"
"kubernetes/services/gamificationengine-service.yaml"
"kubernetes/deployments/gamificationengine-deployment.yaml"
)
INGRESS=(
"kubernetes/ingresses/ingress.yaml"
)
if [ "$1" = "--postgres" ]; then
FILES=("${POSTGRES_FILES[@]}")
elif [ "$1" = "--api" ]; then
FILES=("${API_FILES[@]}")
elif [ "$1" = "--ingress" ]; then
FILES=("${INGRESS[@]}")
else
echo "Invalid option or no option provided. Use --help for usage information."
exit 1
fi
for FILE in "${FILES[@]}"; do
apply_yaml $FILE $2 # $2 can be --verbose
done
echo -e "${BLUE}[*] Info: Process completed.${NC}"