Created
January 25, 2017 23:53
-
-
Save steveh/21f2518e61f517a54e07c0f360685be8 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
set -ex | |
APPLICATION="telemetry" # TODO | |
REPO="FlickElectric/$APPLICATION" | |
PROFILE="flick" | |
OPSWORKS_REGION="us-east-1" | |
CODEDEPLOY_REGION="ap-southeast-2" | |
ENVIRONMENT="$1" | |
if [ -z "$ENVIRONMENT" ]; then | |
echo "Usage: script/deploy <environment> [identifier]" | |
exit 1 | |
fi | |
IDENTIFIER="$2" | |
if [ -z "$IDENTIFIER" ]; then | |
if [ $ENVIRONMENT == "uat" ]; then | |
IDENTIFIER="uat" | |
else | |
echo "Usage: script/deploy <environment> <identifier>" | |
exit 1 | |
fi | |
fi | |
DEPLOYMENT_GROUP_NAME="$APPLICATION-$ENVIRONMENT" | |
DEPLOYMENT_CONFIG_NAME="CodeDeployDefault.AllAtOnce" | |
DESCRIPTION="script/deploy/$IDENTIFIER" | |
COMMIT=`git ls-remote --heads [email protected]:$REPO.git $IDENTIFIER | cut -f1` | |
GITHUB_LOCATION="repository=$REPO,commitId=$COMMIT" | |
STACK_QUERY="Stacks[?Name==\`$ENVIRONMENT\`][StackId]" | |
APP_QUERY="Apps[?Shortname==\`$APPLICATION\`][AppId]" | |
STACK_ID=`aws --profile $PROFILE --region $OPSWORKS_REGION opsworks describe-stacks --query $STACK_QUERY --output text` | |
APP_ID=`aws --profile $PROFILE --region $OPSWORKS_REGION opsworks describe-apps --stack-id $STACK_ID --query $APP_QUERY --output text` | |
COMMAND="{\"Name\":\"deploy\",\"Args\":{\"migrate\":[\"true\"]}}" | |
echo "Deploying $IDENTIFIER to $APPLICATION $ENVIRONMENT ($COMMIT)..." | |
aws --profile $PROFILE --region $OPSWORKS_REGION opsworks create-deployment \ | |
--stack-id $STACK_ID \ | |
--app-id $APP_ID \ | |
--command $COMMAND | |
aws --profile $PROFILE --region $CODEDEPLOY_REGION deploy create-deployment \ | |
--application-name $APPLICATION \ | |
--deployment-group-name $DEPLOYMENT_GROUP_NAME \ | |
--deployment-config-name $DEPLOYMENT_CONFIG_NAME \ | |
--description $DESCRIPTION \ | |
--github-location $GITHUB_LOCATION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment