-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
78 lines (63 loc) · 1.93 KB
/
deploy.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
#!/bin/bash
declare -A deployments
# Select deployment servers
servers=()
read -p "=> Deploy to 1) staging, 2) production: " selection
if [[ $selection =~ [1] ]]; then servers+=("staging"); fi
if [[ $selection =~ [2] ]]; then servers+=("production"); fi
if [[ ${#servers[@]} -eq 0 ]]; then
echo "You must select at least one server."
exit
fi
# Select projects for deployment
projects=("ag-weather" "ag-vdifn" "soils-ag-wx" "wisp")
echo
echo "Available projects:"
for i in "${!projects[@]}"; do
echo "$((i+1)). ${projects[i]}"
done
read -p "=> Enter project numbers to deploy: " selected_projects
echo
for (( i=0; i<${#selected_projects}; i++ )); do
num=${selected_projects:$i:1}
if [[ $num =~ [1-4] ]]; then
project=${projects[$((num-1))]}
# Get branch for this project
read -p "Git branch for ${project}: " branch
# Store deployment info
deployments[$project]="branch:$branch"
fi
done
if [[ ${#deployments[@]} -eq 0 ]]; then
echo "No projects selected for deployment."
exit
fi
# Execute deployments
statuses=()
echo
for project in "${!deployments[@]}"; do
IFS=';' read -r -a info <<< "${deployments[$project]}"
branch="${info[0]#branch:}"
for server in "${servers[@]}"; do
echo "Deploying $project to $server..."
cd ~/"code/$project" || { echo "Failed to change directory to $project"; exit; }
if [ -n "$branch" ]; then
echo "Using BRANCH=${branch}"
BRANCH="$branch" cap "$server" deploy
else
cap "$server" deploy
fi
if [ $? -eq 0 ]; then
statuses+=("$project deployed successfully to $server")
else
echo "Deployment of $project to $server failed!"
exit
fi
cd - > /dev/null || exit
echo
done
done
# Report deployments
for status in "${statuses[@]}"; do
echo $status
done