My personal homepage.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

deploy.sh 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. distribution_id="E1B9KWNF6O30FL" # Cloudfront distribution ID
  3. bucket_name="kim-grytoyr-io" # S3 bucket name
  4. # Clean the public folder, Hugo doesn't do this for you
  5. echo "Cleaning public folder.."
  6. rm -rf ./public
  7. # Build the website
  8. echo "Building website.."
  9. hugo >/dev/null
  10. # Sync with S3 bucket. Delete from S3 if necessary, and only use file size for matching files
  11. echo "Deploying to S3 bucket $bucket_name.."
  12. aws s3 sync ./public s3://$bucket_name --delete --size-only > .sync.log
  13. # Truncate temporary files
  14. echo "Creating list of changed files.."
  15. > .changed-files
  16. > .paths
  17. # Parse the log from S3 sync and remove everything but paths
  18. while read -r line
  19. do
  20. echo $line | sed "s/^.*$bucket_name//" | tr -d '[:blank:]' >> .changed-files
  21. done < .sync.log
  22. # Replace the newlines with spaces for --path flag
  23. tr '\r\n' ' ' < .changed-files > .paths
  24. # Check if .paths is empty
  25. if [ ! -s .paths ]
  26. then
  27. # No changes made
  28. echo "No changes, nothing to invalidate.."
  29. else
  30. # Changes made. Invalidate changed paths in Cloudfront
  31. echo "Invalidating cache.."
  32. aws cloudfront create-invalidation --distribution-id $distribution_id --paths $(cat .paths) /index.html >/dev/null
  33. fi
  34. echo "Deployed!"