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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. # Copying signature files
  11. mkdir -p ./public/signed
  12. cp ./signed/*.txt ./public/signed/.
  13. # Sync with S3 bucket. Delete from S3 if necessary, and only use file size for matching files
  14. echo "Deploying to S3 bucket $bucket_name.."
  15. aws s3 sync ./public s3://$bucket_name --delete --size-only > .sync.log
  16. # Truncate temporary files
  17. echo "Creating list of changed files.."
  18. > .changed-files
  19. > .paths
  20. # Parse the log from S3 sync and remove everything but paths
  21. while read -r line
  22. do
  23. echo $line | sed "s/^.*$bucket_name//" | tr -d '[:blank:]' >> .changed-files
  24. done < .sync.log
  25. # Replace the newlines with spaces for --path flag
  26. tr '\r\n' ' ' < .changed-files > .paths
  27. # Check if .paths is empty
  28. if [ ! -s .paths ]
  29. then
  30. # No changes made
  31. echo "No changes, nothing to invalidate.."
  32. else
  33. # Changes made. Invalidate changed paths in Cloudfront
  34. echo "Invalidating cache.."
  35. aws cloudfront create-invalidation --distribution-id $distribution_id --paths $(cat .paths) /index.html >/dev/null
  36. fi
  37. echo "Deployed!"