Skip to content

Commit

Permalink
Merge pull request #193 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 3.7.0 - Upgrade Alpine, support executionRoleArn, fix unbound variable errors
  • Loading branch information
fillup authored Aug 30, 2019
2 parents 2470057 + 91934c9 commit 799c1cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.5
FROM alpine:3.8

# Install packges needed
RUN apk --no-cache add ca-certificates curl bash jq py2-pip && \
Expand Down
31 changes: 20 additions & 11 deletions ecs-deploy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Setup default values for variables
VERSION="3.4.0"
VERSION="3.7.0"
CLUSTER=false
SERVICE=false
TASK_DEFINITION=false
Expand Down Expand Up @@ -206,6 +206,10 @@ function parseImageName() {
fi
else
tag=${BASH_REMATCH[1]}
domain=""
port=""
repo=""
img=""
fi
else
# check if using root level repo with format like mariadb or mariadb:latest
Expand All @@ -217,6 +221,12 @@ function parseImageName() {
exit 12
fi
tag=${BASH_REMATCH[2]}

# for root level repo, initialize unused variables for checks when rebuilding image below
domain=""
port=""
repo=""

else
echo "Unable to parse image name: $IMAGE, check the format and try again"
exit 13
Expand All @@ -236,28 +246,27 @@ function parseImageName() {
fi

# Reassemble image name
useImage=""
if [[ "x$TAGONLY" == "x" ]]; then

if [[ ! -z ${domain+undefined-guard} ]]; then
if [[ ! -z "$domain" ]]; then
useImage="$domain"
fi
if [[ ! -z ${port} ]]; then
if [[ ! -z "$port" ]]; then
useImage="$useImage:$port"
fi
if [[ ! -z ${repo+undefined-guard} ]]; then
if [[ ! "x$repo" == "x" ]]; then
if [[ ! -z "$repo" ]]; then
useImage="$useImage/$repo"
fi
fi
if [[ ! -z ${img+undefined-guard} ]]; then
if [[ "x$useImage" == "x" ]]; then
if [[ ! -z "$img" ]]; then
if [[ -z "$useImage" ]]; then
useImage="$img"
else
useImage="$useImage/$img"
fi
fi
imageWithoutTag="$useImage"
if [[ ! -z ${tag+undefined-guard} ]]; then
if [[ ! -z "$tag" ]]; then
useImage="$useImage:$tag"
fi

Expand Down Expand Up @@ -313,7 +322,7 @@ function createNewTaskDefJson() {

# Some options in task definition should only be included in new definition if present in
# current definition. If found in current definition, append to JQ filter.
CONDITIONAL_OPTIONS=(networkMode taskRoleArn placementConstraints)
CONDITIONAL_OPTIONS=(networkMode taskRoleArn placementConstraints executionRoleArn)
for i in "${CONDITIONAL_OPTIONS[@]}"; do
re=".*${i}.*"
if [[ "$DEF" =~ $re ]]; then
Expand All @@ -323,7 +332,7 @@ function createNewTaskDefJson() {

# Updated jq filters for AWS Fargate
REQUIRES_COMPATIBILITIES=$(echo "${DEF}" | jq -r '. | select(.requiresCompatibilities != null) | .requiresCompatibilities[]')
if [[ "${REQUIRES_COMPATIBILITIES}" == 'FARGATE' ]]; then
if `echo ${REQUIRES_COMPATIBILITIES[@]} | grep -q "FARGATE"`; then
FARGATE_JQ_FILTER='executionRoleArn: .executionRoleArn, requiresCompatibilities: .requiresCompatibilities, cpu: .cpu, memory: .memory'
NEW_DEF_JQ_FILTER="${NEW_DEF_JQ_FILTER}, ${FARGATE_JQ_FILTER}"
fi
Expand Down
10 changes: 5 additions & 5 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ EOF
expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value * " } ], "name": "API", "links": [], "mountPoints": [], "image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 80, "hostPort": 10080 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] } ], "placementConstraints": null, "networkMode": "bridge" }'
run createNewTaskDefJson
[ ! -z $status ]
[ $(echo "$output" | jq) == $(echo "$expected" | jq) ]
[ "$(echo "$output" | jq .)" == "$(echo "$expected" | jq .)" ]
}

@test "test createNewTaskDefJson with single container in definition for AWS Fargate" {
Expand Down Expand Up @@ -345,7 +345,7 @@ EOF
expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 80, "hostPort": 10080 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] } ], "placementConstraints": null, "networkMode": "awsvpc", "executionRoleArn": "arn:aws:iam::121212345678:role/ecsTaskExecutionRole", "requiresCompatibilities": [ "FARGATE" ], "cpu": "256", "memory": "512" }'
run createNewTaskDefJson
[ ! -z $status ]
[ $(echo "$output" | jq) == $(echo "$expected" | jq) ]
[ "$(echo "$output" | jq .)" == "$(echo "$expected" | jq .)" ]
}

@test "test createNewTaskDefJson with multiple containers in definition" {
Expand Down Expand Up @@ -429,7 +429,7 @@ EOF
expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 80, "hostPort": 10080 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] }, { "environment": [ { "name": "KEY", "value": "value" } ], "name": "cache", "links": [], "mountPoints": [], "image": "redis:latest", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 6376, "hostPort": 10376 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] } ], "placementConstraints": null, "networkMode": "bridge" }'
run createNewTaskDefJson
[ ! -z $status ]
[ $(echo "$output" | jq) == $(echo "$expected" | jq) ]
[ "$(echo "$output" | jq .)" == "$(echo "$expected" | jq .)" ]
}

@test "test parseImageName with tagonly option" {
Expand All @@ -441,7 +441,7 @@ EOF
run parseImageName

[ ! -z $status ]
[ $(echo "$output" | jq) == $(echo "$expected" | jq) ]
[ "$(echo "$output" | jq .)" == "$(echo "$expected" | jq .)" ]
}

@test "test createNewTaskDefJson with multiple containers in definition and replace only tags" {
Expand Down Expand Up @@ -527,5 +527,5 @@ EOF
run createNewTaskDefJson
echo $output
[ ! -z $status ]
[ $(echo "$output" | jq) == $(echo "$expected" | jq) ]
[ "$(echo "$output" | jq .)" == "$(echo "$expected" | jq .)" ]
}

0 comments on commit 799c1cd

Please sign in to comment.