Created
January 24, 2017 15:43
-
-
Save ceccode/7c64db8d8f7c27dd2d3b5b9acbb2bd5d to your computer and use it in GitHub Desktop.
Bash script for deploy dist folder in production branch and on AWS S3 (optional)
This file contains hidden or 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 sh | |
| # Use AWS cli | |
| # Thanks to https://zellwk.com/blog/deploy-static-site/ | |
| DIST_FOLDER="dist" | |
| AWS_CLI_PROFILE="your-profile-name" | |
| AWS_BUCKET="your bucket name/" | |
| PRODUCTION_BRANCH_NAME="your-production-branch" | |
| function deployS3 { | |
| aws s3 cp ${DIST_FOLDER} s3://${AWS_BUCKET} --recursive --profile=${AWS_CLI_PROFILE} | |
| } | |
| echo "::> Start deploy" | |
| set -e # Prevents script from running if there are any errors. | |
| git stash save # Stashes everything away incase you didn't commit them | |
| npm run production # insert your build script here | |
| echo "::> Would you like to deploy ${DIST_FOLDER} on S3 bucket ${AWS_BUCKET} with profile ${AWS_CLI_PROFILE}? yes or wyw" | |
| read deploy_to_s3 | |
| if [ $deploy_to_s3 = "yes" ]; then | |
| echo "::> Start deploy on S3" | |
| deployS3 | |
| fi | |
| REV=`git rev-parse HEAD` # Gets commit hash as message | |
| git checkout ${BRANCH_NAME} | |
| git rm -rf . | |
| git checkout master -- .gitignore | |
| cp -rf ${DIST_FOLDER}/* . && rm -rf ${DIST_FOLDER} | |
| echo "::> Pushing in ${BRANCH_NAME}" | |
| git add --all . | |
| git commit -m "deployed $REV" | |
| git push --all | |
| echo "::> Well done!" | |
| git checkout master | |
| git stash pop | |
| exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment