-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
152 lines (133 loc) · 4.5 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
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
#!/bin/bash
# set -e
echo "------------------------"
echo "Deploying Docker EE"
echo "------------------------"
echo ""
DOCKER_ENGINE_VERSION="17.06.2-ee-5"
DOCKER_UCP_VERSION="2.2.4"
DOCKER_DTR_VERSION="2.3.4"
#TODO: Check versions return a 200
if [[ -z "${AZURE_RESOURCE_GROUP_NAME// }" ]]; then
echo "azure resource group name:"
read AZURE_RESOURCE_GROUP_NAME
fi
if [[ -z "${AZURE_LOCATION// }" ]]; then
echo "azure location:"
read AZURE_LOCATION
fi
if [[ -z "${AZURE_ITEM_PREFIX// }" ]]; then
echo "azure resource prefix:"
read AZURE_ITEM_PREFIX
fi
if [[ -z "${AZURE_DOCKER_ADMIN_PASSWORD// }" ]]; then
echo "admin password:"
read -s AZURE_DOCKER_ADMIN_PASSWORD
echo "confirm admin password:"
read -s confirm_admin_password
if [[ $AZURE_DOCKER_ADMIN_PASSWORD != $confirm_admin_password ]]; then
echo "[error] passwords do not match!"
exit 1
fi
fi
if [[ -z "${SSH_PUBLIC_KEY// }" ]]; then
default_ssh_public_key_path="$HOME/.ssh/id_rsa.pub"
echo "ssh public key path ($default_ssh_public_key_path):"
read ssh_public_key_path
if [[ -z "${ssh_public_key_path}" ]]; then
ssh_public_key_path=$default_ssh_public_key_path
fi
SSH_PUBLIC_KEY=$(cat "$ssh_public_key_path")
fi
echo "Resource Group Name: $AZURE_RESOURCE_GROUP_NAME"
echo "Azure Location: $AZURE_LOCATION"
echo "Resource Prefix: $AZURE_ITEM_PREFIX"
echo "Admin Password: <secure password>"
echo "SSH Public Key: $SSH_PUBLIC_KEY"
echo "Is this correct [y/n]?"
read continueAnswer
if [[ $continueAnswer != "y" ]]; then
echo "cancelling script"
exit
fi
if [[ $DEBUG == "true" ]]; then
#upload script assets
echo "#MTA Infra - Scripts" >> ./azure/scripts/README.md
IFS='/' read -r -a scripts_uri_array <<< "$(gist -pR ./azure/scripts/README.md)"
scripts_base_uri="https://gist.github.com/${scripts_uri_array[3]}/${scripts_uri_array[4]}/raw/"
scripts_gist_id=${scripts_uri_array[4]}
rm ./azure/scripts/README.md
for filepath in ./azure/scripts/*; do
echo "[DEBUG] uploading $filepath"
url=$(gist -u $scripts_gist_id $filepath)
done
echo "[DEBUG] scripts base url: $scripts_base_uri"
#upload template assets
echo "#MTA Infra - Templates" >> ./azure/ee-windows/README.md
IFS='/' read -r -a templates_uri_array <<< "$(gist -pR ./azure/ee-windows/README.md)"
templates_base_uri="https://gist.github.com/${templates_uri_array[3]}/${templates_uri_array[4]}/raw/"
templates_gist_id=${templates_uri_array[4]}
rm ./azure/ee-windows/README.md
for filepath in ./azure/ee-windows/*; do
echo "[DEBUG] uploading $filepath"
url=$(gist -u $templates_gist_id $filepath)
done
echo "[DEBUG] templates base url: $templates_base_uri"
#set artifact base url parameter
artifactBaseUriParameter="
,
\"templatesBaseUri\": {
\"value\": \""$templates_base_uri"\"
},
\"scriptsBaseUri\": {
\"value\": \""$scripts_base_uri"\"
}
"
fi
parameters="
{
\"prefix\": {
\"value\": \""$AZURE_ITEM_PREFIX"\"
},
\"adminUsername\": {
\"value\": \"docker\"
},
\"adminPassword\": {
\"value\": \""$AZURE_DOCKER_ADMIN_PASSWORD"\"
},
\"sshPublicKey\": {
\"value\": \""$SSH_PUBLIC_KEY"\"
},
\"dockerVersion\": {
\"value\": \""$DOCKER_ENGINE_VERSION"\"
},
\"ucpVersion\": {
\"value\": \""$DOCKER_UCP_VERSION"\"
},
\"dtrVersion\": {
\"value\": \""$DOCKER_DTR_VERSION"\"
}
$artifactBaseUriParameter
}
"
#create resource group
echo "[INFO] creating resource group: $AZURE_RESOURCE_GROUP_NAME"
rg=$(az group create --name $AZURE_RESOURCE_GROUP_NAME --location $AZURE_LOCATION)
if [[ $DEBUG == "true" ]]; then
echo "[DEBUG] setting trap to cleanup gist on exit"
trap "echo '[DEBUG] cleaning up gist scripts and templates'; gist --delete $scripts_gist_id; gist --delete $templates_gist_id" EXIT
echo "[DEBUG] creating deployment"
az group deployment create \
--template-file azure/ee-windows/index.json \
--parameters "$parameters" \
-g $AZURE_RESOURCE_GROUP_NAME \
--verbose
else
echo "[INFO] creating deployment"
az group deployment create \
--template-uri https://raw.githubusercontent.com/BrandonRoyal/mta_infra/master/azure/ee-windows/index.json \
--parameters "$parameters" \
-g $AZURE_RESOURCE_GROUP_NAME \
--verbose
fi
az network public-ip list --query "[].{name:name, fqdn:dnsSettings.fqdn}" -g $AZURE_RESOURCE_GROUP_NAME