Last active
October 4, 2018 14:41
-
-
Save antonioned/49387010183760fa6b275ca3297c0b46 to your computer and use it in GitHub Desktop.
Custom Codeship script for deployment to Elastic Beanstalk
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
#!/bin/sh | |
#for app label I am using the last commit on github, but because spaces pose a problem in S3, replace SPACE with an underscore _ | |
export APP_VERSION=`git log --oneline -n 1 | cut -c 1-90 | sed 's/ /_/g'` | |
pip install awscli | |
# clean build artifacts and create the application archive (also ignore any files named .git* in any folder) | |
git clean -fd | |
# precompile assets, ... | |
# zip the application | |
zip -x *.git* -r "${AWS_APP_NAME}-${APP_VERSION}.zip" . | |
# delete any version with the same name (based on the short revision) - optional | |
aws elasticbeanstalk delete-application-version --application-name "${AWS_APP_NAME}" --version-label "${APP_VERSION}" --delete-source-bundle | |
# upload to S3 | |
aws s3 cp ${AWS_APP_NAME}-${APP_VERSION}.zip s3://${AWS_S3_BUCKET}/${AWS_APP_NAME}-${APP_VERSION}.zip | |
# create a new version and update the environment to use this version | |
aws elasticbeanstalk create-application-version --application-name "${AWS_APP_NAME}" --version-label "${APP_VERSION}" --source-bundle S3Bucket="${AWS_S3_BUCKET}",S3Key="${AWS_APP_NAME}-${APP_VERSION}.zip" | |
aws elasticbeanstalk update-environment --environment-name "${AWS_APP_ENVIRONMENT}" --version-label "${APP_VERSION}" | |
Don't forget to put AWS_APP_NAME, AWS_S3_BUCKET and AWS_APP_ENVIRONMENT variables in your Codeship environment. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An addition to this, would be an automated process of a blue/green environment deployment method. A small modification of the last command and adding 3 additional lines at the end will do the job:
Those sleep commands аre needed as the
aws elasticbeanstalk update-environment
command does not wait for the deploy to finish, it finishes in the CLI almost immediately. Because of that we do not want for theswap-environment-cnames
command to fail because of that, as the deployment needs at least 3-4 minutes to finish (depending of the deployment method used in Beanstalk: all at once, immutable or rolling).