-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminikube.sh
More file actions
executable file
·213 lines (176 loc) · 5.81 KB
/
Copy pathminikube.sh
File metadata and controls
executable file
·213 lines (176 loc) · 5.81 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
#!/bin/bash
# set -e
REPO_DIR=$(pwd)
# Colors for terminal output
BOLD_YELLOW="\e[1;33m"
RESET="\e[0m"
# Base directories containing the app folders
BASE_DIRS=("ea-platform" "brand")
VERSION=${2:-"latest"}
# Namespaces for Helm deployments
EA_NAMESPACE="ea-platform"
BRAND_NAMESPACE="eru-labs-brand"
build_and_push() {
eval $(minikube docker-env)
echo -e "${BOLD_YELLOW}BUILDING LOCAL IMAGES${RESET}"
local app_path=$1
local app_name=$(basename "$app_path")
echo "Processing app: $app_name"
echo "Building Docker image for $app_name..."
docker build -t "$app_name:$VERSION" "$app_path"
echo "Completed build and push for $app_name"
}
deploy_stack_terraform() {
echo -e "${BOLD_YELLOW}DEPLOYING APPS AND DEPENDENCIES TO MINIKUBE${RESET}"
cd infra/environments/local/cluster
terraform init
terraform apply -auto-approve
cd $REPO_DIR
cd infra/environments/local/apps
terraform init
terraform apply -auto-approve
cd $REPO_DIR
}
k8s_ingress_dns() {
MINIKUBE_IP=$(minikube ip)
echo "I need sudo permissions to update your /etc/hosts file"
HOST_ENTRIES=(
"api.ea.erulabs.local"
"ea.erulabs.local"
"erulabs.local"
"grafana.erulabs.local"
)
for HOSTNAME in "${HOST_ENTRIES[@]}"; do
# Check if the exact IP and hostname pair exists
if ! grep -q "^$MINIKUBE_IP[[:space:]]\+$HOSTNAME\$" /etc/hosts; then
echo "$MINIKUBE_IP $HOSTNAME" | sudo tee -a /etc/hosts > /dev/null
echo "Added $HOSTNAME to /etc/hosts"
else
echo "$HOSTNAME already exists in /etc/hosts, skipping..."
fi
done
}
remove_k8s_ingress_dns() {
MINIKUBE_IP=$(minikube ip)
echo "I need sudo permissions to remove entries from your /etc/hosts file"
HOST_ENTRIES=(
"api.ea.erulabs.local"
"ea.erulabs.local"
"erulabs.local"
"grafana.erulabs.local"
)
for HOSTNAME in "${HOST_ENTRIES[@]}"; do
# Check if the exact IP and hostname pair exists
if grep -q "^$MINIKUBE_IP[[:space:]]\+$HOSTNAME\$" /etc/hosts; then
# Remove the matching line
sudo sed -i.bak "/^$MINIKUBE_IP[[:space:]]\+$HOSTNAME$/d" /etc/hosts
echo "Removed $HOSTNAME from /etc/hosts"
else
echo "$HOSTNAME not found in /etc/hosts, skipping..."
fi
done
}
k8s_port_forward() {
echo -e "${BOLD_YELLOW}STARTING PORTFORWARDS${RESET}"
# Port-forward ea-platform mongodb
nohup kubectl port-forward deployment/mongodb 8086:27017 --namespace $EA_NAMESPACE >/dev/null 2>&1 &
echo "Port-forwarding for ea-platform mongodb on port 8086 started."
# Port-forward eru-labs-brand mongodb
nohup kubectl port-forward deployment/mongodb 8087:27017 --namespace $BRAND_NAMESPACE >/dev/null 2>&1 &
echo "Port-forwarding for eru-labs-brand mongodb on port 8087 started."
}
seed_test_data() {
echo -e "${BOLD_YELLOW}SEEDING TEST DATA WITH SMOKE TEST SCRIPTS${RESET}"
cd ea-platform/ea-ainu-manager/tests
./smoke/post-user.sh
cd ../../ea-agent-manager/tests
./smoke/post-agent.sh
./smoke/post-node.sh
cd $REPO_DIR
}
run_tests() {
echo "Running ea-ainu-manager smoke tests"
cd ea-platform/ea-ainu-manager/tests
./smoke/get-all-users.sh
./smoke/get-user.sh
./smoke/post-user-device.sh
./smoke/post-user-job.sh
./smoke/delete-user-device.sh
./smoke/delete-user-job.sh
./smoke/put-user-compute-credits.sh
echo "Running ea-agent-manager smoke tests"
cd ../../ea-agent-manager/tests
./smoke/get-all-agents.sh
./smoke/get-all-nodes.sh
./smoke/get-agent.sh
./smoke/get-node.sh
echo "Running ea-job-api smoke tests"
cd ../../ea-job-api/tests
./smoke/post-job.sh
cd $REPO_DIR
}
cleanup() {
echo "Cleaning up all kubectl port-forward processes..."
# Find all kubectl port-forward processes and kill them
pkill -f "kubectl port-forward"
remove_k8s_ingress_dns
echo "Port-forwarding processes stopped."
pwd
cd infra/environments/local
terraform init
terraform destroy -auto-approve
cd $REPO_DIR
}
# Main Script
case "$1" in
start)
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.0/standard-install.yaml
minikube addons enable registry
minikube addons enable metrics-server
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
for dir in "${BASE_DIRS[@]}"; do
if [[ ! -d "$dir" ]]; then
echo "Base directory $dir does not exist. Skipping."
continue
fi
# Process each app in the directory
echo "Iterating through apps in $dir..."
for app_path in "$dir"/*; do
# Skip if it's not a directory
if [[ -d "$app_path" ]]; then
build_and_push "$app_path"
fi
done
done
deploy_stack_terraform
k8s_ingress_dns
k8s_port_forward
# seed_test_data
# run_tests
echo "All apps processed and deployed successfully."
;;
stop)
cleanup
;;
build)
for dir in "${BASE_DIRS[@]}"; do
if [[ ! -d "$dir" ]]; then
echo "Base directory $dir does not exist. Skipping."
continue
fi
# Process each app in the directory
echo "Iterating through apps in $dir..."
for app_path in "$dir"/*; do
# Skip if it's not a directory
if [[ -d "$app_path" ]]; then
build_and_push "$app_path"
fi
done
done
;;
*)
echo "Usage: $0 {start|stop|build} [version]"
exit 1
;;
esac