diff --git a/Dockerfile b/Dockerfile index 9c0f6ab..70416ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 && \ diff --git a/ecs-deploy b/ecs-deploy index 36925af..142f5bd 100755 --- a/ecs-deploy +++ b/ecs-deploy @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test.bats b/test.bats index 6fd9fec..8467e38 100755 --- a/test.bats +++ b/test.bats @@ -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" { @@ -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" { @@ -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" { @@ -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" { @@ -527,5 +527,5 @@ EOF run createNewTaskDefJson echo $output [ ! -z $status ] - [ $(echo "$output" | jq) == $(echo "$expected" | jq) ] + [ "$(echo "$output" | jq .)" == "$(echo "$expected" | jq .)" ] }