Skip to content

Commit

Permalink
Supported AWS Fargate
Browse files Browse the repository at this point in the history
  • Loading branch information
kakakakakku committed Dec 19, 2017
1 parent ac2b53c commit 3e3b592
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ecs-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ function createNewTaskDefJson() {
fi
done

# Updated jq filters for AWS Fargate
REQUIRES_COMPATIBILITIES=$(echo "${DEF}" | jq -r '. | select(.requiresCompatibilities != null) | .requiresCompatibilities[]')
if [[ "${REQUIRES_COMPATIBILITIES}" == '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

# Build new DEF with jq filter
NEW_DEF=$(echo $DEF | jq "{${NEW_DEF_JQ_FILTER}}")

Expand Down
66 changes: 66 additions & 0 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,72 @@ EOF
[ $output == $expected ]
}

@test "test createNewTaskDefJson with single container in definition for AWS Fargate" {
imageWithoutTag="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo"
useImage="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111"
TASK_DEFINITION=$(cat <<EOF
{
"taskDefinition": {
"status": "ACTIVE",
"networkMode": "awsvpc",
"family": "app-task-def",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
}
],
"volumes": [],
"taskDefinitionArn": "arn:aws:ecs:us-east-1:121212345678:task-definition/app-task-def:123",
"containerDefinitions": [
{
"environment": [
{
"name": "KEY",
"value": "value"
}
],
"name": "API",
"links": [],
"mountPoints": [],
"image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1487623908",
"essential": true,
"portMappings": [
{
"protocol": "tcp",
"containerPort": 80,
"hostPort": 10080
}
],
"entryPoint": [],
"memory": 128,
"command": [
"/data/run.sh"
],
"cpu": 200,
"volumesFrom": []
}
],
"revision": 123,
"executionRoleArn": "arn:aws:iam::121212345678:role/ecsTaskExecutionRole",
"compatibilities": [
"EC2",
"FARGATE"
],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "256",
"memory": "512"
}
}
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": [] } ], "networkMode": "awsvpc", "executionRoleArn": "arn:aws:iam::121212345678:role/ecsTaskExecutionRole", "requiresCompatibilities": [ "FARGATE" ], "cpu": "256", "memory": "512" }'
run createNewTaskDefJson
[ ! -z $status ]
[ $output == $expected ]
}

@test "test createNewTaskDefJson with multiple containers in definition" {
imageWithoutTag="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo"
useImage="121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:1111111111"
Expand Down

0 comments on commit 3e3b592

Please sign in to comment.