2020-01-31 22:16:34 +03:00
|
|
|
#!/bin/sh -x
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "BEGIN @ $(date +"%T"): START OF SCRIPT"
|
|
|
|
|
|
|
|
# Check Helm Installation
|
|
|
|
if ! [ -x "$(command -v helm)" ]; then
|
|
|
|
echo "Please install Helm."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
# Check JQ Installation
|
|
|
|
if ! [ -x "$(command -v jq)" ]; then
|
|
|
|
echo "Please install JQ. You can install by typing:"
|
|
|
|
echo "sudo apt install jq"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
# Check Kubernetes Installation
|
|
|
|
if ! [ -x "$(command -v kubectl)" ]; then
|
|
|
|
echo "Please install Kubernetes."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
# Check Azure CLI Installation
|
|
|
|
if ! [ -x "$(command -v az)" ]; then
|
|
|
|
echo "Please install the Azure CLI."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "BEGIN @ $(date +"%T"): Set variables..."
|
|
|
|
|
|
|
|
# Initialize Variables for flags
|
|
|
|
AD_APP_NAME=''
|
|
|
|
CLUSTER_NAME=''
|
|
|
|
CLUSTER_RG=''
|
|
|
|
EMAIL=''
|
|
|
|
LOCATION=''
|
|
|
|
INPUTIMAGE=''
|
2021-10-20 21:38:02 +03:00
|
|
|
ALT_TENANT_ID=''
|
2020-01-31 22:16:34 +03:00
|
|
|
SKIP_CLUSTER_CREATION=''
|
2021-10-28 00:50:19 +03:00
|
|
|
E2E_TEST_FLAG=''
|
|
|
|
SP=''
|
|
|
|
SP_SECRET=''
|
2020-01-31 22:16:34 +03:00
|
|
|
|
2021-10-28 00:50:19 +03:00
|
|
|
while getopts "a:c:r:e:l:i:t:s:z:pgh" OPTION
|
2020-01-31 22:16:34 +03:00
|
|
|
do
|
|
|
|
case $OPTION in
|
|
|
|
a)
|
2021-10-14 00:29:09 +03:00
|
|
|
AD_APP_NAME=$OPTARG ;;
|
2020-01-31 22:16:34 +03:00
|
|
|
c)
|
2021-10-14 00:29:09 +03:00
|
|
|
CLUSTER_NAME=$OPTARG ;;
|
2020-01-31 22:16:34 +03:00
|
|
|
r)
|
2021-10-14 00:29:09 +03:00
|
|
|
CLUSTER_RG=$OPTARG ;;
|
2020-01-31 22:16:34 +03:00
|
|
|
e)
|
|
|
|
EMAIL=$OPTARG ;;
|
|
|
|
l)
|
|
|
|
LOCATION=$OPTARG ;;
|
|
|
|
i)
|
|
|
|
INPUTIMAGE=$OPTARG ;;
|
2021-10-20 21:38:02 +03:00
|
|
|
t)
|
|
|
|
ALT_TENANT_ID=$OPTARG ;;
|
2021-10-28 00:50:19 +03:00
|
|
|
s)
|
|
|
|
SP=$OPTARG ;;
|
|
|
|
z)
|
|
|
|
SP_SECRET=$OPTARG ;;
|
2020-01-31 22:16:34 +03:00
|
|
|
p)
|
2021-10-15 07:18:47 +03:00
|
|
|
SKIP_CLUSTER_CREATION="True" ;;
|
2021-10-28 00:50:19 +03:00
|
|
|
g)
|
|
|
|
E2E_TEST_FLAG="True" ;;
|
2020-01-31 22:16:34 +03:00
|
|
|
h)
|
|
|
|
# Change to how others show it like az
|
|
|
|
echo "HELP: Here are the flags and their variables"
|
2020-01-31 22:45:31 +03:00
|
|
|
echo "REQUIRED: -a is for AD_APP_NAME"
|
2021-10-12 22:49:56 +03:00
|
|
|
echo "REQUIRED: -c is for CLUSTER_NAME *Note: Cluster Name must be unique*"
|
2020-01-31 22:45:31 +03:00
|
|
|
echo "REQUIRED: -r is for CLUSTER_RG"
|
|
|
|
echo "REQUIRED: -e is for EMAIL"
|
|
|
|
echo "REQUIRED: -l is for LOCATION"
|
|
|
|
echo "OPTOINAL: -i is for INPUTIMAGE"
|
2021-10-20 21:38:02 +03:00
|
|
|
echo "OPTOINAL: -t is for ALT_TENANT_ID"
|
2021-10-28 23:23:45 +03:00
|
|
|
echo "OPTOINAL: -s is for SERVICE_PRICIPAL"
|
|
|
|
echo "OPTOINAL: -z is for SP_SECRET"
|
2020-01-31 22:45:31 +03:00
|
|
|
echo "OPTOINAL: -p is for SKIP_CLUSTER_CREATION"
|
2020-01-31 22:16:34 +03:00
|
|
|
exit ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-01-31 22:45:31 +03:00
|
|
|
# Force required flags.
|
2021-10-20 01:24:35 +03:00
|
|
|
if [ -z "$AD_APP_NAME" ] || [ -z "$CLUSTER_NAME" ] || [ -z "$CLUSTER_RG" ] || [ -z "$EMAIL" ] || [ -z "$LOCATION" ]; then
|
2020-01-31 22:45:31 +03:00
|
|
|
echo "*****ERROR. Please enter all required flags.*****"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-10-28 23:09:22 +03:00
|
|
|
echo ""
|
|
|
|
# Show the subscription we will be deploying to.
|
|
|
|
if [ -z "$E2E_TEST_FLAG" ]; then
|
|
|
|
echo "******We will be deploying to this subscription******"
|
|
|
|
az account show
|
|
|
|
fi
|
|
|
|
|
2020-01-31 22:16:34 +03:00
|
|
|
APP_HOSTNAME="$AD_APP_NAME.$LOCATION.cloudapp.azure.com"
|
|
|
|
HOMEPAGE=https://$APP_HOSTNAME
|
|
|
|
IDENTIFIER_URIS=$HOMEPAGE
|
2021-11-29 20:18:19 +03:00
|
|
|
REPLY_URLS=https://$APP_HOSTNAME/easyauth/signin-oidc
|
2020-01-31 22:16:34 +03:00
|
|
|
|
|
|
|
echo "The value of -a is $AD_APP_NAME - AD_APP_NAME"
|
|
|
|
echo "The value of -c is $CLUSTER_NAME - CLUSTER_NAME"
|
|
|
|
echo "The value of -r is $CLUSTER_RG - CLUSTER_RG"
|
|
|
|
echo "The value of -e is $EMAIL - EMAIL"
|
|
|
|
echo "The value of -l is $LOCATION - LOCATION"
|
|
|
|
echo "The value of -i is $INPUTIMAGE - INPUTIMAGE"
|
2021-10-20 21:38:02 +03:00
|
|
|
echo "The value of -t is $ALT_TENANT_ID - ALT_TENANT_ID"
|
2021-10-28 23:23:45 +03:00
|
|
|
echo "The value of -s is $SP - SERVICE_PRICIPAL"
|
2021-10-28 00:50:19 +03:00
|
|
|
echo "The value of -z is $SP_SECRET - SP_SECRET"
|
2020-01-31 22:16:34 +03:00
|
|
|
echo "The value of -p is $SKIP_CLUSTER_CREATION - SKIP_CLUSTER_CREATION"
|
2021-10-28 00:50:19 +03:00
|
|
|
echo "The value of -g is $E2E_TEST_FLAG - E2E_TEST_FLAG"
|
2020-01-31 22:16:34 +03:00
|
|
|
echo "COMPLETE @ $(date +"%T"): Setting variables"
|
|
|
|
|
|
|
|
echo "****BEGIN @ $(date +"%T"): Call AKS Cluster Creation script...****"
|
|
|
|
# If there is no flag set for SKIP_CLUSTER_CREATION, then create the AKS cluster.
|
|
|
|
if [ -z "$SKIP_CLUSTER_CREATION" ]; then
|
2020-02-01 01:56:18 +03:00
|
|
|
. ./AutomationScripts/1-clusterCreation.sh
|
2020-01-31 22:16:34 +03:00
|
|
|
else
|
|
|
|
echo "CLUSTER CREATION WAS SKIPPED!"
|
|
|
|
fi
|
|
|
|
echo "****COMPLETE @ $(date +"%T"): Done cluster creation script.****"
|
|
|
|
|
|
|
|
# Get the credentials outside of cluster creation script.
|
|
|
|
echo "BEGIN @ $(date +"%T"): Getting cluster creds..."
|
|
|
|
az aks get-credentials -g $CLUSTER_RG -n $CLUSTER_NAME
|
|
|
|
echo "COMPLETE @ $(date +"%T"): Getting cluster creds"
|
|
|
|
|
|
|
|
|
|
|
|
# Add Helm
|
2021-06-08 01:49:31 +03:00
|
|
|
helm repo add stable https://charts.helm.sh/stable
|
2020-01-31 22:16:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
echo "****BEGIN @ $(date +"%T"): Call Ingress Controller Creation script****"
|
2020-02-01 01:56:18 +03:00
|
|
|
. ./AutomationScripts/2-ingressCreation.sh
|
2020-01-31 22:16:34 +03:00
|
|
|
echo "****COMPLETE @ $(date +"%T"): Ingress controller created script****"
|
|
|
|
|
|
|
|
echo "****BEGIN @ $(date +"%T"): Call ADD App Creation script****"
|
2020-02-01 01:56:18 +03:00
|
|
|
. ./AutomationScripts/3-registerAADApp.sh
|
2020-01-31 22:16:34 +03:00
|
|
|
echo "****COMPLETE @ $(date +"%T"): AAD App created script****"
|
|
|
|
|
|
|
|
echo "****BEGIN @ $(date +"%T"): Call Install Cert Manager script****"
|
2021-12-10 19:56:42 +03:00
|
|
|
. ./AutomationScripts/4-installCertManager.sh
|
2020-01-31 22:16:34 +03:00
|
|
|
echo "****COMPLETE @ $(date +"%T"): Installed Cert Manager script****"
|
|
|
|
|
2021-12-10 19:56:42 +03:00
|
|
|
echo "****BEGIN @ $(date +"%T"): Call Deploy MSAL Proxy script****"
|
|
|
|
. ./AutomationScripts/5-deployMSALProxy.sh
|
|
|
|
echo "****COMPLETE @ $(date +"%T"): Deployed MSAL Proxy script****"
|
|
|
|
|
2021-06-10 22:16:39 +03:00
|
|
|
echo "BEGIN @ $(date +"%T"): Deploy sample app..."
|
|
|
|
# If we have a parameter for an image install a custom image. If not, then we install kuard.
|
|
|
|
if [ -z "$INPUTIMAGE" ]; then
|
2021-12-10 19:56:42 +03:00
|
|
|
echo "No image input, installing sample."
|
2021-12-10 15:51:01 +03:00
|
|
|
kubectl run easyauth-sample-pod --image=docker.io/lesterjt/easyauthfork8s-sample:latest --expose --port=80
|
2021-06-10 22:16:39 +03:00
|
|
|
else
|
|
|
|
echo "Your custom image $INPUTIMAGE installed"
|
2021-12-10 15:51:01 +03:00
|
|
|
kubectl run custom-pod --image=$INPUTIMAGE --expose --port=80
|
2021-06-10 22:16:39 +03:00
|
|
|
fi
|
|
|
|
echo "COMPLETE @ $(date +"%T"): Deployed sample app"
|
|
|
|
|
2020-01-31 22:16:34 +03:00
|
|
|
echo "****BEGIN @ $(date +"%T"): Call Deploy New Ingress Resource script****"
|
2020-02-01 01:56:18 +03:00
|
|
|
. ./AutomationScripts/6-deployNewIngressResource.sh
|
2020-01-31 22:16:34 +03:00
|
|
|
echo "****COMPLETE @ $(date +"%T"): Deployed New Ingress Resource script****"
|
|
|
|
|
|
|
|
echo "BEGIN @ $(date +"%T"): Verify Production Certificate works..."
|
2021-10-14 23:08:48 +03:00
|
|
|
INPUT_STATUS=false
|
2021-10-14 23:35:04 +03:00
|
|
|
n=50
|
2021-10-14 23:08:48 +03:00
|
|
|
while [[ "$INPUT_STATUS" != "True" || "$INPUT_TYPE" != "Ready" ]]
|
2020-01-31 22:16:34 +03:00
|
|
|
do
|
|
|
|
echo ""
|
|
|
|
kubectl get certificate $TLS_SECRET_NAME
|
2021-10-14 23:08:48 +03:00
|
|
|
INPUT_STATUS=$(kubectl get certificate $TLS_SECRET_NAME -o=jsonpath='{.status.conditions[0].status}')
|
|
|
|
INPUT_TYPE=$(kubectl get certificate $TLS_SECRET_NAME -o=jsonpath='{.status.conditions[0].type}')
|
|
|
|
echo "status: " $INPUT_STATUS
|
|
|
|
echo "type: " $INPUT_TYPE
|
2021-10-14 19:13:07 +03:00
|
|
|
sleep 5
|
2021-10-14 23:35:04 +03:00
|
|
|
if [ "$n" == "0" ]; then
|
|
|
|
echo "ERROR. INFINITE LOOP in main.sh when calling kubectl get certificate."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
n=$((n-1))
|
2020-01-31 22:16:34 +03:00
|
|
|
echo ""
|
|
|
|
done
|
|
|
|
echo "COMPLETE @ $(date +"%T"): Verify Production Certificate works"
|
|
|
|
echo "END OF SCRIPT"
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "Visit the app in the browser. Good luck! " $HOMEPAGE
|
|
|
|
echo ""
|
2021-10-12 21:41:16 +03:00
|
|
|
echo ""
|