Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -o errexit
- set -o nounset
- set -o pipefail
- set -o noglob
- # This script will deploy studio to the given cloudfront distribution/s3 bucket.
- # This should only be called from the continuous deployment pipeline
- # Usage: bin/s3-deploy
- sync_s3() {
- bucket_name=${1}
- tag_name=${2}
- echo -e "Syncing assets..."
- aws s3 sync ./dist s3://${bucket_name}/${tag_name} --delete
- echo -e "${green}Done${reset}"
- }
- change_origin_path() {
- tag_name=${1}
- cloudfront_distribution_id=${2}
- echo -e "Changing cloudfront origin..."
- current_distribution_config=$(aws cloudfront get-distribution --id ${cloudfront_distribution_id})
- next_distribution_config=$(bin/lib/update-distribution ${tag_name} "${current_distribution_config}")
- etag=$(bin/lib/get-etag "${current_distribution_config}")
- aws cloudfront update-distribution --id ${cloudfront_distribution_id} --distribution-config ${next_distribution_config} --if-match ${etag}
- echo -e "${green}Done${reset}"
- }
- invalidate_cache() {
- cloudfront_distribution_id=${1}
- echo -e "Invalidating cloudfront cache..."
- aws cloudfront create-invalidation --distribution-id ${cloudfront_distribution_id} --paths /*
- echo -e "${green}Done${reset}"
- }
- deploy_to_git_tag() {
- tag_name=${1}
- cloudfront_distribution_id=${2}
- bucket_name=${3}
- echo -e "Deploying ${blue}${1}${reset}"
- sync_s3 ${bucket_name} ${tag_name}
- change_origin_path ${tag_name} ${cloudfront_distribution_id}
- invalidate_cache ${cloudfront_distribution_id}
- }
- main() {
- source bin/lib/colors
- cloudfront_distribution_id=${CLOUDFRONT_DISTRIBUTION_ID}
- bucket_name=${BUCKET_NAME}
- deploy_tag=$(git describe)
- if [ "${deploy_tag}" ]; then
- deploy_to_git_tag ${deploy_tag} ${cloudfront_distribution_id} ${bucket_name}
- echo -e "${green}Deploy success${reset}"
- else
- echo -e "${red}Deploy failure: no tag${reset}"
- fi
- }
- main "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement