Skip to content

Commit

Permalink
Merge pull request silinternational#140 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 3.4.0 - Adding assume role support
  • Loading branch information
fillup authored Apr 3, 2018
2 parents 5471225 + 61d515a commit 6f3b085
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Usage
silintl/mariadb:latest, private.registry.com:8000/repo/image:tag

Optional arguments:
-a | --assume-role ARN for AWS Role to assume for ecs-deploy operations.
-D | --desired-count The number of instantiations of the task to place and keep running in your service.
-m | --min minumumHealthyPercent: The lower limit on the number of running tasks during a deployment. (default: 100)
-M | --max maximumPercent: The upper limit on the number of running tasks during a deployment. (default: 200)
Expand Down Expand Up @@ -136,7 +137,7 @@ this script.
Use Environment Variable for tag name value
-------------------------------------------
In some cases you may want to use an environment variable for the tag name of your image.
For instance, we use Codeship for continous integration and deployment. In their Docker
For instance, we use Codeship for continuous integration and deployment. In their Docker
environment they can build images and tag them with different variables, such as
the current unix timestamp. We want to use these unique and changing values for image tags
so that each task definition refers to a unique docker image/tag. This gives us the
Expand Down
41 changes: 40 additions & 1 deletion ecs-deploy
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bash

# Setup default values for variables
VERSION="3.3.0"
VERSION="3.4.0"
CLUSTER=false
SERVICE=false
TASK_DEFINITION=false
MAX_DEFINITIONS=0
AWS_ASSUME_ROLE=false
IMAGE=false
MIN=false
MAX=false
Expand Down Expand Up @@ -40,6 +41,7 @@ Required arguments:
--aws-instance-profile Use the IAM role associated with this instance
Optional arguments:
-a | --assume-role ARN for AWS Role to assume for ecs-deploy operations.
-D | --desired-count The number of instantiations of the task to place and keep running in your service.
-m | --min minumumHealthyPercent: The lower limit on the number of running tasks during a deployment.
-M | --max maximumPercent: The upper limit on the number of running tasks during a deployment.
Expand Down Expand Up @@ -83,6 +85,9 @@ EOM
exit 3
}




# Check requirements
function require() {
command -v "$1" > /dev/null 2>&1 || {
Expand All @@ -92,6 +97,25 @@ function require() {
}
}

function assumeRole() {

temp_role=$(aws sts assume-role \
--role-arn "${AWS_ASSUME_ROLE}" \
--role-session-name "$(date +"%s")")

export AWS_ACCESS_KEY_ID=$(echo $temp_role | jq .Credentials.AccessKeyId | xargs)
export AWS_SECRET_ACCESS_KEY=$(echo $temp_role | jq .Credentials.SecretAccessKey | xargs)
export AWS_SESSION_TOKEN=$(echo $temp_role | jq .Credentials.SessionToken | xargs)
}


function assumeRoleClean() {
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
}


# Check that all required variables/combinations are set
function assertRequiredArgumentsSet() {

Expand Down Expand Up @@ -455,6 +479,10 @@ if [ "$BASH_SOURCE" == "$0" ]; then
echo "--aws-instance-profile is not yet in use"
AWS_IAM_ROLE=true
;;
-a|--aws-assume-role)
AWS_ASSUME_ROLE="$2"
shift
;;
-c|--cluster)
CLUSTER="$2"
shift # past argument
Expand Down Expand Up @@ -521,9 +549,15 @@ if [ "$BASH_SOURCE" == "$0" ]; then
set -x
fi


# Check that required arguments are provided
assertRequiredArgumentsSet

if [[ "$AWS_ASSUME_ROLE" != false ]]; then
assumeRole
fi


# Determine image name
parseImageName
echo "Using image name: $useImage"
Expand All @@ -548,6 +582,11 @@ if [ "$BASH_SOURCE" == "$0" ]; then
waitForGreenDeployment
fi

if [[ "$AWS_ASSUME_ROLE" != false ]]; then
assumeRoleClean
fi


exit 0

fi
Expand Down

0 comments on commit 6f3b085

Please sign in to comment.