Created
December 11, 2018 04:53
-
-
Save jcyuyi/3adfe1574f1e756798300c0dc2fd5ea3 to your computer and use it in GitHub Desktop.
Deploy Hugo to S3 with CloudFront invalidation
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 | |
if [[ "$#" -ne 3 ]]; then | |
echo "Illegal number of parameters" | |
echo "Usage: deploy BASE_URL S3_URL DISTRIBUTION_ID" | |
exit 1 | |
fi | |
# Base URL | |
BASE_URL=$1 | |
# S3 URL | |
S3_URL=$2 | |
# CloudFront DISTRIBUTION ID | |
DISTRIBUTION_ID=$3 | |
echo "Building ${BASE_URL}..." | |
# The command `hugo` renders your site into `public/` dir and is ready to be deployed to your web server. | |
hugo --baseURL ${BASE_URL} | |
echo "Uploading ${S3_URL}..." | |
aws s3 cp public ${S3_URL} --recursive | |
echo "Refreshing ${DISTRIBUTION_ID}..." | |
aws cloudfront create-invalidation \ | |
--distribution-id ${DISTRIBUTION_ID} \ | |
--paths '/*' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment