This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathinception.sh
executable file
·103 lines (86 loc) · 4.71 KB
/
inception.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
#!/bin/bash
set -e # stop script execution on failure
set -x
## -------
# Write stdout and stderr to inception.txt file
exec > >(tee "inception.txt")
exec 2>&1
## -------
# Import global variables
. ./globalVariables.prod.sh
## -------
# Login to Azure and set the Azure subscription for this script to use
echo ........ Logging into Azure
az login
az account set --subscription $AZURE_SUBSCRIPTION_ID
## -------
# Make sure DNS name is available for Azure Traffic Manager, if not, exit
if [ $(az network traffic-manager profile check-dns --name $PROJECT_NAME.$PUBLIC_DOMAIN_NAME_SUFFIX --query nameAvailable) = "false" ]; then
echo "!!!DNS name $PROJECT_NAME is not available in Azure Traffic Manager - exiting!!!"
exit 1
fi
## -------
# Create the Azure resource group(s) to hold common resources
echo ........ Creating resource groups
! az group delete --name=$COMMON_RESOURCE_GROUP --yes
az group create --name $COMMON_RESOURCE_GROUP --location $AZURE_LOCATION
## -------
# Create the Azure Traffic Manager profile
AZURE_TRAFFIC_MANAGER_PROFILE_NAME=$PROJECT_NAME-$RESOURCE_NAME_STRING_AZURE_TRAFFIC_MANAGER
az network traffic-manager profile create --name $AZURE_TRAFFIC_MANAGER_PROFILE_NAME --resource-group $COMMON_RESOURCE_GROUP --routing-method Priority --unique-dns-name $PROJECT_NAME.$PUBLIC_DOMAIN_NAME_SUFFIX
## -------
## Create key vault that k8 hexodite will use to get pod specific secrets
K8_DEPLOYMENT_KEYVAULT_NAME=$PROJECT_NAME-$RESOURCE_NAME_STRING_AZURE_KEY_VAULT_DEPLOY
export K8_DEPLOYMENT_KEYVAULT_NAME
! az keyvault delete --name $K8_DEPLOYMENT_KEYVAULT_NAME --resource-group $COMMON_RESOURCE_GROUP
az keyvault create --name $K8_DEPLOYMENT_KEYVAULT_NAME --resource-group $COMMON_RESOURCE_GROUP --location $AZURE_LOCATION
## -------
# Create the Azure Container Registry
echo ........ Creating Azure Container Registry
. ./deployContainerRegistry.sh
## -------
## build and push hexadite to ACR
ACR_URL=`az acr show --name $AZURE_CONTAINER_REGISTRY_NAME --query loginServer -o tsv`
ACR_USERNAME=`az acr credential show --name $AZURE_CONTAINER_REGISTRY_NAME --query username -o tsv`
ACR_PASSWORD=`az acr credential show --name $AZURE_CONTAINER_REGISTRY_NAME --query passwords[0].value -o tsv`
git clone https://github.com/Hexadite/acs-keyvault-agent
cd acs-keyvault-agent
docker build . -t ${ACR_URL}/hexadite:latest
docker login -u $ACR_USERNAME -p $ACR_PASSWORD $ACR_URL
docker push ${ACR_URL}/hexadite:latest
cd ..
rm -rf acs-keyvault-agent
## -------
# Create App Insights
echo ........ Creating App Insights
. ./deployAppInsights.sh
## -------
# Create OMS Workspace
echo ........ Creating OMS Workspace
K8_DEPLOYMENT_DIAGSA_NAME="${PROJECT_NAME}diagsa"
# Storage account creation will fail if the name contains '-'. Find and replace with blank
K8_DEPLOYMENT_DIAGSA_NAME="${K8_DEPLOYMENT_DIAGSA_NAME//-/}"
# Generate log analytics parameters file
LOG_ANALYTICS_OMS_PARAMS=$(<logAnalyticsOms.parameters.json)
LOG_ANALYTICS_OMS_PARAMS=$(jq --arg workspaceName $PROJECT_NAME-$AZURE_LOCATION-ws '.parameters.workspaceName.value=$workspaceName' <<< "$LOG_ANALYTICS_OMS_PARAMS")
LOG_ANALYTICS_OMS_PARAMS=$(jq --arg storageAccountName $K8_DEPLOYMENT_DIAGSA_NAME '.parameters.applicationDiagnosticsStorageAccountName.value=$storageAccountName' <<< "$LOG_ANALYTICS_OMS_PARAMS")
LOG_ANALYTICS_OMS_PARAMS=$(jq --arg resourceGroup $COMMON_RESOURCE_GROUP '.parameters.applicationDiagnosticsStorageAccountResourceGroup.value=$resourceGroup' <<< "$LOG_ANALYTICS_OMS_PARAMS")
echo $LOG_ANALYTICS_OMS_PARAMS > logAnalyticsOms.parameters.temp.json
! az storage account delete --name $K8_DEPLOYMENT_DIAGSA_NAME --resource-group $COMMON_RESOURCE_GROUP --yes
az storage account create --name $K8_DEPLOYMENT_DIAGSA_NAME --resource-group $COMMON_RESOURCE_GROUP --location eastus --sku Standard_LRS
! az group deployment delete --resource-group $COMMON_RESOURCE_GROUP --name "Microsoft.LogAnalyticsOMS"
az group deployment create --resource-group $COMMON_RESOURCE_GROUP --name "Microsoft.LogAnalyticsOMS" --template-file logAnalyticsOms.json --parameters @logAnalyticsOms.parameters.temp.json
! rm ./logAnalyticsOms.parameters.temp.json
## -------
# Create the middle tier service
echo ........ Creating middle tier services
. ./createMtSvc.sh
## -------
# Azure resource creation complete, values for the resources created
echo ........ "Azure resource deployment complete. All resources deployed to the following resource group."
echo COMMON_RESOURCE_GROUP=$COMMON_RESOURCE_GROUP
echo ........ "The following resources were created."
echo K8_DEPLOYMENT_KEYVAULT_NAME=$K8_DEPLOYMENT_KEYVAULT_NAME
echo AZURE_CONTAINER_REGISTRY_NAME=$AZURE_CONTAINER_REGISTRY_NAME
echo AZURE_TRAFFIC_MANAGER_PROFILE_NAME=$AZURE_TRAFFIC_MANAGER_PROFILE_NAME
echo MT_CONNECTION_STRING=$MT_CONNECTION_STRING