Skip to content

Commit

Permalink
init repo
Browse files Browse the repository at this point in the history
added bicep cli into setup machine script

added support for subscription Id, fixed bugs

fixed test vm

added support for signing marketplace agreement, refactoring

refactoring

improved UX, README, added E2E script

improved README and UX

added RDP for MacOS

improved docs

added bicepparam example for VM, changed path for extension scripts
  • Loading branch information
vjirovsky-pure committed Sep 4, 2023
1 parent 20fbd5f commit de39523
Show file tree
Hide file tree
Showing 20 changed files with 1,204 additions and 160 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
03-test-vm.bicepparam
01-prereq.bicepparam
02-cbs.bicepparam
tmp*.json
*.bicepparam
e2e-demo-params.sh
23 changes: 20 additions & 3 deletions 00-setup-machine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@ echo "Installing tools"
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash


#4.5. Install the Azure CLI packages, jq, .NET, zip
#4.5. Install the Azure CLI packages, bicep, jq, .NET, zip
if [[ "$OSTYPE" =~ ^linux ]]; then
sudo apt -qy install jq

curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
# Mark it as executable
chmod +x ./bicep
# Add bicep to your PATH (requires admin)
sudo mv ./bicep /usr/local/bin/bicep
fi

if [[ "$OSTYPE" =~ ^darwin ]]; then
# Add the tap for bicep
brew tap azure/bicep

brew help
if [[ $? != 0 ]] ; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
brew update
fi
brew install jq
brew install bicep
fi

# check installed tooling
Expand All @@ -40,7 +50,6 @@ if [ $? == 0 ]; then
else
echo "Installing bicep"
az bicep install
exit 1;
fi

jq --version
Expand All @@ -51,12 +60,20 @@ else
exit 1;
fi

bicep --version
if [ $? == 0 ]; then
echosuccess "[.] bicep-cli tool...OK";
else
echoerr "Error with 'bicep-cli' tool!";
exit 1;
fi

echo "Asking user to log in...";
# ask user for login
az login
if [ $? == 0 ]; then
echosuccess "
Your machine should be ready! Now proceed with ./deploy.sh script
Your machine should be ready! Now proceed with './01-deploy-prerequisities.sh' script
";
else
Expand Down
44 changes: 25 additions & 19 deletions 01-deploy-prerequisities.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
#!/bin/bash

SHOW_DEBUG_OUTPUT=false

escape_quotes(){
echo $@ | sed s/'"'/'\\"'/g
}


echoerr() { printf "\033[0;31m%s\n\033[0m" "$*" >&2; }
echosuccess() { printf "\033[0;32m%s\n\033[0m" "$*" >&2; }

source $(dirname $0)/script-modules/common.sh

# Read the bicep parameters
parametersfilename='01-prereq.bicepparam'

echo " "
echo " "
echo " CBS DEPLOYMENT - PREREQUISITES "
echo " "
echo " "
echo " "

source $(dirname $0)/script-modules/ascii-logo.sh

echo "Deploying required infrastructure"
echo -e "
------------------------------------------------------------
Pure Cloud Block Store - Prerequisites Deployment
(c) 2023 Pure Storage
v$CLI_VERSION
------------------------------------------------------------
"

paramsJson=`bicep build-params $parametersfilename --stdout | jq -r ".parametersJson"`


location=`echo $paramsJson | jq -r ".parameters.location.value"`
subscriptionId=`echo $paramsJson | jq -r ".parameters.subscriptionId.value"`
resourceGroupName=`echo $paramsJson | jq -r ".parameters.resourceGroupName.value"`

echo -e "${C_BLUE3}${C_GREY85}
[Step #1] Deploying required infrastructure in subscription $subscriptionId:${NO_FORMAT}
"
echo "
Subscription Id: $subscriptionId
RG name: $resourceGroupName
Location: $location
"


# Deploy our infrastructure
output=$(az deployment sub create \
--name "CBS-deploy-prereq-bicep-sh" \
--location $location \
--subscription $subscriptionId \
--template-file "templates/prerequisites.bicep" \
--parameters $parametersfilename
)
Expand Down Expand Up @@ -64,5 +70,5 @@ echo " ----------------------------------------------"
echo ""
echo ""
echo ""
echosuccess "The deployment of prerequisities has been completed. Now you can proceed to deployment of CBS itself with *02-deploy-cbs.sh*."
echosuccess "[COMPLETED] The deployment of prerequisities has been completed. Now you can proceed to deployment of CBS with **02-deploy-cbs.sh** script file."
echo ""
2 changes: 2 additions & 0 deletions 01-prereq.bicepparam.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using 'templates/prerequisites.bicep'

param location = 'westeurope'
param subscriptionId = 'xxxxxxxx-xxxx-xxxx-xxx-xxxxxxxxxxxx'
param resourceGroupName = 'your-resource-group-name'

4 changes: 3 additions & 1 deletion 02-cbs.bicepparam.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using 'templates/cbs-managed-app.bicep'

param location = 'westeurope'
param resourceName = 'my-resource-name'
param subscriptionId = 'xxxxxxxx-xxxx-xxxx-xxx-xxxxxxxxxxxx'
param resourceGroupName = 'your-resource-group-name'

param resourceName = 'my-resource-name'
param alertRecipients = '[email protected]'
param arrayName = 'my-array-name'
param licenseKey = 'CBS-TRIAL-LICENSE'
Expand Down
98 changes: 65 additions & 33 deletions 02-deploy-cbs.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,86 @@
#!/bin/bash
set -e
SHOW_DEBUG_OUTPUT=false

escape_quotes(){
echo $@ | sed s/'"'/'\\"'/g
}


curlwithcode() {
code=0
# Run curl in a separate command, capturing output of -w "%{http_code}" into statuscode
# and sending the content to a file with -o >(cat >/tmp/curl_body)
statuscode=$(curl -w "%{http_code}" \
-o >(cat >/tmp/curl_body) \
"$@"
) || code="$?"

body="$(cat /tmp/curl_body)"
echo "{\"statusCode\": $statuscode,"
echo "\"exitCode\": $code,"
echo "\"body\": \"$(escape_quotes $body)\"}"
}

echoerr() { printf "\033[0;31m%s\n\033[0m" "$*" >&2; }
echosuccess() { printf "\033[0;32m%s\n\033[0m" "$*" >&2; }
source $(dirname $0)/script-modules/common.sh


# Read the bicep parameters
parametersfilename='./02-cbs.bicepparam'

echo " "
echo " "
echo " CBS DEPLOYMENT "
echo " "
echo " "
echo " "



echo "Deploying CBS managed app"
source $(dirname $0)/script-modules/ascii-logo.sh

paramsJson=`bicep build-params $parametersfilename --stdout | jq -r ".parametersJson"`
echo -e "
------------------------------------------------------------
Pure Cloud Block Store - CBS Deployment
(c) 2023 Pure Storage
v$CLI_VERSION
------------------------------------------------------------
"

bicep_raw=`bicep build-params $parametersfilename --stdout`
paramsJson=`echo $bicep_raw | jq -r ".parametersJson"`

location=`echo $paramsJson | jq -r ".parameters.location.value"`
subscriptionId=`echo $paramsJson | jq -r ".parameters.subscriptionId.value"`
resourceGroupName=`echo $paramsJson | jq -r ".parameters.resourceGroupName.value"`

echo -e "${C_BLUE3}${C_GREY85}
[Step #1] Enabling CBS deployment for selected subscription $subscriptionId:${NO_FORMAT}
"



AZURE_MARKETPLACE_PLAN_NAME=`echo $paramsJson | jq -r .parameters.azureMarketPlacePlanName.value`
if [ "$AZURE_MARKETPLACE_PLAN_NAME" = "null" ];
then
AZURE_MARKETPLACE_PLAN_NAME=`echo $bicep_raw | jq -r .templateJson | jq -r .parameters.azureMarketPlacePlanName.defaultValue`
fi

AZURE_MARKETPLACE_PUBLISHER=`echo $paramsJson | jq -r .parameters.azureMarketPlacePlanPublisher.value`
if [ "$AZURE_MARKETPLACE_PUBLISHER" = "null" ];
then
AZURE_MARKETPLACE_PUBLISHER=`echo $bicep_raw | jq -r .templateJson | jq -r .parameters.azureMarketPlacePlanPublisher.defaultValue`
fi

AZURE_MARKETPLACE_PLAN_OFFER=`echo $paramsJson | jq -r .parameters.azureMarketPlacePlanOffer.value`
if [ "$AZURE_MARKETPLACE_PLAN_OFFER" = "null" ];
then
AZURE_MARKETPLACE_PLAN_OFFER=`echo $bicep_raw | jq -r .templateJson | jq -r .parameters.azureMarketPlacePlanOffer.defaultValue`
fi

enablementOutput=$(az vm image terms accept \
--subscription $subscriptionId \
--publisher $AZURE_MARKETPLACE_PUBLISHER \
--offer $AZURE_MARKETPLACE_PLAN_OFFER \
--plan $AZURE_MARKETPLACE_PLAN_NAME)

accepted=`echo $enablementOutput | jq -r '.properties.outputs.accepted.value'`
if [ $accepted ]
then
echosuccess "[COMPLETED] Plan '$AZURE_MARKETPLACE_PLAN_NAME' enabled."
else
echoerr "[Step #1][FAILURE] Enablement failed - offer: $AZURE_MARKETPLACE_PLAN_OFFER, plan: $AZURE_MARKETPLACE_PLAN_NAME, publisher: $AZURE_MARKETPLACE_PUBLISHER"
echo $enablementOutput
exit 1;
fi

echo -e "${C_BLUE3}${C_GREY85}
[Step #2] Deploying CBS managed app:${NO_FORMAT}
"
echo "
Subscription Id: $subscriptionId
RG name: $resourceGroupName
Location: $location
"
# Deploy our infrastructure
output=$(az deployment group create \
--name "CBS-deploy-sh" \
--resource-group $resourceGroupName \
--subscription $subscriptionId \
--template-file "templates/cbs-managed-app.bicep" \
--parameters $parametersfilename
)
Expand All @@ -67,7 +99,7 @@ cbsiSCSIEndpointCT1=`echo $output | jq -r '.properties.outputs.cbsiSCSIEndpointC
echo ""
echo ""
echo ""
echosuccess "The deployment of CBS managed application has been completed."
echosuccess "[COMPLETED] The deployment of CBS managed application has been completed."
echo ""

echo " ******** Array parameters ********"
Expand Down
Loading

0 comments on commit de39523

Please sign in to comment.