-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateEnvironments.sh
More file actions
137 lines (121 loc) · 5.36 KB
/
UpdateEnvironments.sh
File metadata and controls
137 lines (121 loc) · 5.36 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
#!/bin/bash
# =============================================================================
# Script to update image hashes in docker-compose
# Author: Ander Fernández
# Description: This script allows updating the image hashes in the docker-compose.yaml
# file for different environments in a quick way.
# =============================================================================
# Function to update the docker-compose.yaml file (only for ui service)
update_docker_compose() {
# Ask for the new hash for the selected service
read -p "Enter the new hash for the image: " new_hash
# Determine the path to the docker-compose.yaml file based on the selected environment
docker_compose_file="./deploy/$selected_env/docker-compose.yaml"
# Check if the file exists
if [[ ! -f "$docker_compose_file" ]]; then
echo "Error: The file $docker_compose_file is not found."
return 1
fi
# Perform the update based on the selected service
case "$1" in
am|1)
# Update the docker-compose.yaml file for the am service and comment the old hash
sed -i "s|/amadeusmodel:|/amadeusmodel:${new_hash} #|g" "$docker_compose_file"
echo "The file $docker_compose_file has been updated with the new hash for 'am': $new_hash"
;;
es|2)
# Update the docker-compose.yaml file for the es service and comment the old hash
sed -i "s|/protones:|/protones:${new_hash} #|g" "$docker_compose_file"
echo "The file $docker_compose_file has been updated with the new hash for 'es': $new_hash"
;;
ui|3)
# Update the docker-compose.yaml file for the ui service and comment the old hash
sed -i "s|/protonui:|/protonui:${new_hash} #|g" "$docker_compose_file"
echo "The file $docker_compose_file has been updated with the new hash for 'ui': $new_hash"
;;
adl|4)
# Update the docker-compose.yaml file for the adl service and comment the old hash
sed -i "s|/adl:|/adl:${new_hash} #|g" "$docker_compose_file"
echo "The file $docker_compose_file has been updated with the new hash for 'adl': $new_hash"
;;
spb|5)
# Update the docker-compose.yaml file for the spb service and comment the old hash
sed -i "s|/sparplug-bridge:|/sparplug-bridge:${new_hash} #|g" "$docker_compose_file"
echo "The file $docker_compose_file has been updated with the new hash for 'spb': $new_hash"
;;
sqlb|6)
# Update the docker-compose.yaml file for the sqlb service and comment the old hash
sed -i "s|/sql-bridge:|/sql-bridge:${new_hash} #|g" "$docker_compose_file"
echo "The file $docker_compose_file has been updated with the new hash for 'sqlb': $new_hash"
;;
*)
echo "No update for docker-compose.yaml, as the selected service is not recognized."
;;
esac
}
# Function to perform service updates
perform_update() {
case $1 in
am|1|es|2|ui|3|adl|4|spb|5|sqlb|6)
update_docker_compose "$1"
;;
*)
echo "Invalid option selected. No updates were applied."
;;
esac
}
while true; do
# Display environment selection menu
echo "Select the environment you want to update:"
read -p "Enter your choice (ufa-tst/vilo-tst/ufa-dev/vilo-dev...): " env_choice
echo "Selected environment: $env_choice"
# Verify if the docker-compose.yaml file exists for the selected environment
docker_compose_file="./deploy/$env_choice/docker-compose.yaml"
if [[ ! -f "$docker_compose_file" ]]; then
echo "Error: The file $docker_compose_file does not exist. Please select a valid environment."
continue # Go back to environment selection
fi
selected_env="$env_choice" # Store the valid environment
while true; do
# Display system update menu
echo "Select the service you want to update in $selected_env:"
echo "1. am"
echo "2. es"
echo "3. ui"
echo "4. adl"
echo "5. spb"
echo "6. sqlb"
read -p "Enter your choice (am/es/ui/adl/spb/sqlb): " choice
# Call the function with the user's input
perform_update "$choice"
# Ask if the user wants to update another service in the same environment
read -p "Do you want to update another service in $selected_env? (y/n): " again_service
if [[ "$again_service" != "y" ]]; then
break
fi
done
# Ask if the user wants to restart the environment to apply changes
read -p "Do you want to restart the environment $selected_env to apply changes? (y/n): " restart_env
if [[ "$restart_env" == "y" ]]; then
(
cd "./deploy/$selected_env" || exit
docker compose down
docker compose up -d --remove-orphans --force-recreate -V
)
echo
echo
echo "The environment $selected_env has been restarted successfully."
echo
echo
fi
# Ask if the user wants to switch to another environment
read -p "Do you want to switch to another environment? (y/n): " again_env
if [[ "$again_env" != "y" ]]; then
echo
echo
echo "Exiting the script. Goodbye!"
echo
echo
break
fi
done