Skip to content

Instantly share code, notes, and snippets.

@jldeen jldeen/azStorage.sh
Last active Sep 19, 2019

Embed
What would you like to do?
#!/bin/bash
set -eou pipefail
# Change varaibles below as needed
rg=myresourcegroup
location=eastus
blobStoreName=jdh3
containerName=helm
helmRepoName=jdhelm
# End variable declaration
# functions start
function azureUpload () {
az storage blob upload --container-name $containerName --file index.yaml --name index.yaml
az storage blob upload --container-name $containerName --file *.tgz --name *.tgz
}
function helmRepoSetup () {
echo ''
echo "Adding index.yaml now"
helm repo index --url https://$blobStoreName.blob.core.windows.net/helm/ .
echo "index.yaml added successfully"
sleep 1
echo ''
echo "Now creating helm package for upload"
helm package $chartPath
sleep 1
echo "Helm package created successfully"
echo ''
echo "Now uploading index.yaml and helm package to Azure Storage Containter $containerName"
echo ''
azureUpload
echo ''
echo "Index.yaml and helm package uploaded succesfully"
echo ''
echo "Now adding helm repo for local use"
helm repo add $helmRepoName https://$blobStoreName.blob.core.windows.net/helm/
sleep 1
helm repo list | grep "$helmRepoName" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "helm repo added successfully"
else
echo "Could not add helm repo. Please check your Helm configuration and try again."
fi
}
function helmSearch () {
chart=$1
echo ''
echo "Running helm search"
helm search $chart | grep "$helmRepoName/$chart"
if [ $? -eq 0 ]; then
echo "helm search completed successfully"
echo ''
echo "Your storage account has been created. Your blob store URL is: $blobStoreUrl"
echo ''
echo "You can now use your storage account and created container with Helm charts. Your full Helm chart url is: $helmChartStoreUrl"
else
echo "helm search did not complete successfully. please try again."
fi
}
function helmCreate () {
echo ''
echo "Making chart directory"
mkdir chart-test && cd chart-test
sleep 1
echo ''
echo "Creating helm chart"
helm create myfirstchart
sleep 1
echo ''
echo "Linting helm chart"
helm lint myfirstchart
sleep 1
chartPath=myfirstchart
helmRepoSetup
helmSearch $chartPath
exit
}
function newHelmChart () {
echo ''
while true; do
read -p "Would you like to create a blank helm chart to get started? y/n " yn
case $yn in
[Yy]* ) helmCreate;;
[Nn]* ) echo ''; echo "You will have to create your own helm chart and upload it before you can use your Azure Storage Container as a Helm repo. Your full Azure Storage Container URL is: $helmChartStoreUrl. This prompt will now exit."; exit;;
* ) echo "Please answer yes or no.";;
esac
done
}
function hasHelmChart () {
echo ''
echo "You selected you have a pre-existing Helm chart you would like to use to get started."
echo ''
read -p "Please enter the full path of where your Helm Chart is located. (Ensure the directory that stores your Chart.yaml is part of the path) " chartPath
while [ ! -f $chartPath/chart.yaml ]
do
echo ''
read -p "Valid Helm chart directory not found. Please enter the full path of where your Helm Chart is located. (Ensure the directory with your Chart.yaml is part of the path) " chartPath
done
cd $chartPath
echo ''
echo "Valid Helm chart directory found."
sleep 2
cd ..
helmRepoSetup
chartName=$(echo $chartPath | sed 's:.*/::')
helmSearch $chartName
exit
}
# functions end
az group create -n $rg -l $location
az storage account create \
-n $blobStoreName \
-g $rg \
-l $location \
--sku Standard_LRS \
--kind BlobStorage \
--access-tier Cool
# access-tier accepted values: Hot - Optimized for storing data that is accessed frequently. #Cool - Optimized for storing data that is infrequently accessed and stored for at least 30 days.
export AZURE_STORAGE_ACCOUNT=$blobStoreName
export AZURE_STORAGE_KEY=$(az storage account keys list --resource-group $rg --account-name $blobStoreName | grep -m 1 value | awk -F'"' '{print $4}')
# create container
az storage container create \
--name $containerName \
--public-access blob
# provide blob url to user
blobStoreUrl=$(az storage account show -g $rg -n $blobStoreName --query "primaryEndpoints.blob" -o tsv)
helmChartStoreUrl="$blobStoreUrl""$containerName"
echo ''
echo "Now setting up your Azure Storage account for Helm chart repo use..."
echo ''
sleep 4
while true; do
read -p "Do you have a Helm chart you would like to upload? y/n " yn
case $yn in
[Yy]* ) hasHelmChart;;
[Nn]* ) newHelmChart;;
* ) echo "Please answer yes or no.";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.