Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
if [ -z "$AWS_ACCESS_KEY_ID" -o -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo 'Please define AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY' >&2
exit 127;
fi
if [ -z "$BUILDER_APP_ID" -o -z "$BUILDER_STACK_ID" ]; then
echo 'Please define the application and stack for builder using BUILDER_APP_ID and BUILDER_STACK_ID' >&2
exit 127;
fi
if ! type jq >/dev/null; then
echo 'jq utility is required and can be downloaded from http://stedolan.github.com/jq' >&2
exit 127;
fi
set -euo pipefail
opsworks() {
aws opsworks --region us-east-1 "$@"
}
deployment_status() {
declare deployment=$1
local status=$(opsworks describe-deployments --deployment-ids $deployment | jq -r .Deployments[0].Status)
}
create_deployment() {
declare app_id=$1 stack_id=$2
local payload=$(jq -n '.Name = "deploy"')
opsworks create-deployment --app-id $app_id --stack-id $stack_id --command "$payload" \
| jq -r .DeploymentId
}
main() {
local deployment=$(create_deployment $BUILDER_APP_ID $BUILDER_STACK_ID)
while sleep 10; do
case $(deployment_status $deployment) in
"successful")
break;
;;
"pending" | "running")
;;
"failed")
echo "Build failed" >&2
return 1;
;;
"*")
echo "Error communicating with opsworks" >&2
return 2
;;
esac
done
while read -r NAME APP_ID STACK_ID; do
if [ -z "$APP_ID" -o -z "$STACK_ID" ]; then
echo "Invalid application deployment: $1" >&2
return 3;
fi
echo -n "Releasing $NAME: "
create_deployment $APP_ID $STACK_ID
echo
done
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.