Created
January 22, 2017 23:56
-
-
Save aray12/cb29d893bc189b370316d28f9a21adbf to your computer and use it in GitHub Desktop.
Deploy using github as the source of your revision
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
#!/usr/bin/env bash | |
APPLICATION_NAME="YOUR_APP_NAME" | |
DEPLOYMENT_GROUP="YOUR_DEPLOY_GROUP_NAME" | |
REGION="us-west-2" | |
REPOSITORY="your/github-repo" | |
# Install jq if not already installed | |
# We use jq to parse the json return by the AWS API's | |
# If you don't know about jq, it is dope. Learn more here: https://stedolan.github.io/jq/ | |
jqStatus=$(dpkg-query -W -f='${Status} ${Version}\n' jq); | |
if [[ $jqStatus != *"install ok installed"* ]]; then | |
sudo apt-get install -y jq | |
fi | |
deploymentId=$(aws deploy create-deployment \ | |
--region "$REGION"\ | |
--application-name "$APPLICATION_NAME" \ | |
--deployment-group-name "$DEPLOYMENT_GROUP" \ | |
--github-location commitId="$CIRCLE_SHA1",repository="$REPOSITORY" \ | |
| jq -r '.deploymentId') | |
status="InProgress" | |
while [ "$status" = "InProgress" ] | |
do | |
printf '\e[1;33mDeployment Status: %s\e[0m\n\n' "$status" | |
sleep 10 | |
response=$(aws deploy get-deployment \ | |
--deployment-id "$deploymentId" \ | |
--region "$REGION") | |
status=$(echo "$response" | jq -r '.deploymentInfo.status') | |
done | |
if [ "$status" = "Succeeded" ]; then | |
printf '\e[1;32mDeployment %s\e[0m\n\n' "$status" | |
exit 0 | |
fi | |
printf '\e[1;31mDeployment %s\e[0m\n\n' "$status" | |
printf '\e[1;31mAWS Reponse:\n\e[0m' | |
printf '\e[41;97m%s\e[0m\n\n' "$response" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to deploy automatically to commits to
master
after CI using CircleCI. CircleCi has built in scripts for using CodeDeploy, but they only support using S3 for the revisions. I couldn't get that to work and I enjoyed using GitHub for revisions anyway... If you provide your AWS credentials to CircleCI, they load whether you use CircleCI's automation scripts or not. Furthermore, they have preinstalled the AWS CLI as well.We use Ubuntu for everything, so obviously this wouldn't work with OS X