Last active
April 8, 2018 15:16
-
-
Save bacongobbler/b1a99656d78d5330cb7ff123971700a6 to your computer and use it in GitHub Desktop.
Uploading static site assets to Azure Blob Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eo pipefail | |
# Print a usage message and exit. | |
usage() { | |
cat >&2 <<-'EOF' | |
Usage: ./release.sh | |
To run, I need: | |
- to be provided with the name of the resource group these assets live in, in environment variable AZURE_RG_NAME | |
- to be provided with Azure credentials for the container, in environment variables AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_KEY | |
EOF | |
exit 1 | |
} | |
[ "$AZURE_RG_NAME" ] || usage | |
[ "$AZURE_STORAGE_ACCOUNT" ] || usage | |
[ "$AZURE_STORAGE_KEY" ] || usage | |
echo "Building site with hugo" | |
hugo | |
dir="public" | |
if [ ! -d "${dir}" ]; then | |
echo "Something went wrong. ${dir}/ should exist." | |
fi | |
files=$(ls -p ${dir}) | |
# upload the files at the root directory to the root container | |
for i in $(echo "${files}" | grep -v /); do | |
az storage blob upload -f "${dir}/$i" -n "$i" -c '$root' | |
done | |
# upload the rest to their respective containers | |
for i in $(echo "${files}" | grep /); do | |
AZURE_CONTAINER="$(echo $i | sed 's:/*$::')" | |
az storage blob upload-batch --source "${dir}/$i" --destination "${AZURE_CONTAINER}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment