From e2eedfa5b2f6fb34a7fa4f2cb3af80fd7a6e6693 Mon Sep 17 00:00:00 2001 From: "jurijs.solovjovs" <87270384+jsaivrr@users.noreply.github.com> Date: Fri, 15 Sep 2023 23:25:20 +0300 Subject: [PATCH 01/12] At least one of memory or memoryReservation must be specified. --- ecs-deploy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs-deploy b/ecs-deploy index 7b3504b..6153cd5 100755 --- a/ecs-deploy +++ b/ecs-deploy @@ -371,7 +371,7 @@ function createNewTaskDefJson() { fi # Default JQ filter for new task definition - NEW_DEF_JQ_FILTER="family: .family, volumes: .volumes, containerDefinitions: .containerDefinitions, placementConstraints: .placementConstraints" + NEW_DEF_JQ_FILTER="family: .family, memory: .memory, volumes: .volumes, containerDefinitions: .containerDefinitions, placementConstraints: .placementConstraints" # 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. From 33b14a188d1fa03afeadb38bdef80cfb6f8dbba0 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:21:01 -0700 Subject: [PATCH 02/12] update tests to include a task-level memory attribute --- test.bats | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test.bats b/test.bats index 698daf8..7353323 100755 --- a/test.bats +++ b/test.bats @@ -234,6 +234,7 @@ setup() { "status": "ACTIVE", "networkMode": "bridge", "family": "app-task-def", + "memory": 128, "requiresAttributes": [ { "name": "com.amazonaws.ecs.capability.ecr-auth" @@ -276,7 +277,7 @@ setup() { } 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" }' + expected='{ "family": "app-task-def", "memory": 128, "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 .)" ] @@ -342,7 +343,7 @@ EOF } 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" }' + expected='{ "family": "app-task-def", "memory": null, "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 .)" ] @@ -426,7 +427,7 @@ EOF } 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" }' + expected='{ "family": "app-task-def", "memory": null, "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 .)" ] @@ -483,7 +484,7 @@ EOF } EOF ) - expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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" }' + expected='{ "family": "app-task-def", "memory": null, "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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 .)" ] @@ -567,7 +568,7 @@ EOF } EOF ) - expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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" }' + expected='{ "family": "app-task-def", "memory": null, "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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 .)" ] @@ -664,7 +665,7 @@ EOF } 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:newtag", "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:newtag", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 6376, "hostPort": 10376 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] } ], "placementConstraints": null, "networkMode": "bridge" }' + expected='{ "family": "app-task-def", "memory": null, "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:newtag", "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:newtag", "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 echo $output [ ! -z $status ] From d814d983316f65708b7537ed0a3378e85e66fd73 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:43:20 -0700 Subject: [PATCH 03/12] Revert "Merge pull request #283 from jsaivrr/develop" This reverts commit 3480864ebdb45bde6b44deeef3cfad1389dfd7df, reversing changes made to 907dcb738ab467dc4cf7bcedb2d6601c006a9eca. --- ecs-deploy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs-deploy b/ecs-deploy index 3d10c0c..39338f1 100755 --- a/ecs-deploy +++ b/ecs-deploy @@ -370,7 +370,7 @@ function createNewTaskDefJson() { fi # Default JQ filter for new task definition - NEW_DEF_JQ_FILTER="family: .family, memory: .memory, volumes: .volumes, containerDefinitions: .containerDefinitions, placementConstraints: .placementConstraints" + NEW_DEF_JQ_FILTER="family: .family, volumes: .volumes, containerDefinitions: .containerDefinitions, placementConstraints: .placementConstraints" # 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. From 7a12167669de5dacaebc19f244b2981326dd73f4 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:43:25 -0700 Subject: [PATCH 04/12] Revert "update tests to include a task-level memory attribute" This reverts commit 33b14a188d1fa03afeadb38bdef80cfb6f8dbba0. --- test.bats | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test.bats b/test.bats index 7353323..698daf8 100755 --- a/test.bats +++ b/test.bats @@ -234,7 +234,6 @@ setup() { "status": "ACTIVE", "networkMode": "bridge", "family": "app-task-def", - "memory": 128, "requiresAttributes": [ { "name": "com.amazonaws.ecs.capability.ecr-auth" @@ -277,7 +276,7 @@ setup() { } EOF ) - expected='{ "family": "app-task-def", "memory": 128, "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" }' + 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 .)" ] @@ -343,7 +342,7 @@ EOF } EOF ) - expected='{ "family": "app-task-def", "memory": null, "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" }' + 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 .)" ] @@ -427,7 +426,7 @@ EOF } EOF ) - expected='{ "family": "app-task-def", "memory": null, "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" }' + 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 .)" ] @@ -484,7 +483,7 @@ EOF } EOF ) - expected='{ "family": "app-task-def", "memory": null, "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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" }' + expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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 .)" ] @@ -568,7 +567,7 @@ EOF } EOF ) - expected='{ "family": "app-task-def", "memory": null, "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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" }' + expected='{ "family": "app-task-def", "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "111222333444.dkr.ecr.eu-west-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 .)" ] @@ -665,7 +664,7 @@ EOF } EOF ) - expected='{ "family": "app-task-def", "memory": null, "volumes": [], "containerDefinitions": [ { "environment": [ { "name": "KEY", "value": "value" } ], "name": "API", "links": [], "mountPoints": [], "image": "121212345678.dkr.ecr.us-east-1.amazonaws.com/acct/repo:newtag", "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:newtag", "essential": true, "portMappings": [ { "protocol": "tcp", "containerPort": 6376, "hostPort": 10376 } ], "entryPoint": [], "memory": 128, "command": [ "/data/run.sh" ], "cpu": 200, "volumesFrom": [] } ], "placementConstraints": null, "networkMode": "bridge" }' + 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:newtag", "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:newtag", "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 echo $output [ ! -z $status ] From 0f787e4eeb1946592b8ea2d3b39a675de5c2577a Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Thu, 14 Mar 2024 18:23:06 -0400 Subject: [PATCH 05/12] Convert to Actions --- .github/workflows/build-and-publish.yml | 40 +++++++++++++++++++++++++ README.md | 2 +- action-services.yml | 10 +++++++ codeship-services.yml | 6 ---- codeship-steps.yml | 21 ------------- dockercfg.encrypted | 2 -- 6 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/build-and-publish.yml create mode 100644 action-services.yml delete mode 100644 codeship-services.yml delete mode 100644 codeship-steps.yml delete mode 100644 dockercfg.encrypted diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..02fe580 --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,40 @@ +name: Build and Publish + +on: + push: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run tests + run: docker-compose -f action-services.yml run test + + build-and-publish: + name: Build and Publish + needs: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ vars.DOCKER_ORG }}/ecs-deploy + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md index b44564d..26bab16 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ecs-deploy ================= -[ ![Codeship Status for silinternational/ecs-deploy](https://app.codeship.com/projects/393a91e0-da8d-0134-6603-1e487e818871/status?branch=master)](https://app.codeship.com/projects/203720) +![Status for silinternational/ecs-deploy](https://github.com/silinternational/ecs-deploy/actions/workflows/build-and-deploy.yml/badge.svg?branch=master) This script uses the Task Definition and Service entities in Amazon's ECS to instigate an automatic blue/green deployment. diff --git a/action-services.yml b/action-services.yml new file mode 100644 index 0000000..9db03e3 --- /dev/null +++ b/action-services.yml @@ -0,0 +1,10 @@ +version: "2" + +services: + test: + build: . + command: ["/run-tests.sh"] + volumes: + - ./ecs-deploy:/ecs-deploy + - ./run-tests.sh:/run-tests.sh + - ./test.bats:/test.bats diff --git a/codeship-services.yml b/codeship-services.yml deleted file mode 100644 index ebe2c33..0000000 --- a/codeship-services.yml +++ /dev/null @@ -1,6 +0,0 @@ -ecsdeploy: - build: - image: silintl/ecs-deploy - dockerfile_path: ./Dockerfile - entrypoint: bash - command: /run-tests.sh diff --git a/codeship-steps.yml b/codeship-steps.yml deleted file mode 100644 index f3ff14f..0000000 --- a/codeship-steps.yml +++ /dev/null @@ -1,21 +0,0 @@ -- name: test - service: ecsdeploy - command: /run-tests.sh - -- name: push_branch_tag - service: ecsdeploy - type: push - image_name: silintl/ecs-deploy - image_tag: "{{.Branch}}" - exclude: master - registry: https://index.docker.io/v1/ - encrypted_dockercfg_path: dockercfg.encrypted - -- name: push_latest_tag - service: ecsdeploy - type: push - image_name: silintl/ecs-deploy - image_tag: "latest" - tag: master - registry: https://index.docker.io/v1/ - encrypted_dockercfg_path: dockercfg.encrypted diff --git a/dockercfg.encrypted b/dockercfg.encrypted deleted file mode 100644 index 9b7a03f..0000000 --- a/dockercfg.encrypted +++ /dev/null @@ -1,2 +0,0 @@ -cloudbees:v1 -zDdKfbfu3yVguuUU1hjCG4LSaACQUEDI8BUCwWzqIKnAA+XS3GqqIZMlTPP0BphleYDj9QKaVJOmJvyUi9hxhVZQ1LtHMDE0t3+Ab6d13tAVVOnKyTYOnSid4Joh4Thq24xWbwew4qCrJL6kn+5OtXKg0b5CTXFwlP5nKPq6KuAVY/nxRmRlXlj6rIbB2zO4mnUC/48kgow8TZ634kitNjTp0s0G1/ywjD1OtUr9CD9Xf8DDFwxOfXNQqQM3BEjkcJe8N9u0JtI4aqAcL+TychvJEFwCiQwiO9a7Y85Fd/IxIoseLTObCTTv2O8H \ No newline at end of file From ea5a2c8f39c5f3572cc6e9086b1353e19d028726 Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Sat, 16 Mar 2024 14:43:34 -0400 Subject: [PATCH 06/12] use entrypoint instead of command --- action-services.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/action-services.yml b/action-services.yml index 9db03e3..4e58821 100644 --- a/action-services.yml +++ b/action-services.yml @@ -1,10 +1,6 @@ -version: "2" +version: "3" services: test: build: . - command: ["/run-tests.sh"] - volumes: - - ./ecs-deploy:/ecs-deploy - - ./run-tests.sh:/run-tests.sh - - ./test.bats:/test.bats + entrypoint: ["/run-tests.sh"] From 214ea6bfb5f256d5f11afc33f376127d6c4ea64c Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Mon, 18 Mar 2024 10:58:58 -0400 Subject: [PATCH 07/12] update environment variable section --- README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 26bab16..b8de3a0 100644 --- a/README.md +++ b/README.md @@ -172,19 +172,16 @@ 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 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 -ability to revert/rollback changes by just selecting a previous task definition and -updating the service. We plan to add a revert command/option to ecs-deploy to simplify this further. +For example, we want to use a unique docker image/tag for each task definition. This +gives us the ability to revert/rollback changes by just selecting a previous task +definition and updating the service. -Using the ```-e``` argument you can provide the name of an environment variable that -holds the value you wish to use for the tag. On Codeship they set an env var named CI_TIMESTAMP. +Using the `-e` argument you can provide the name of an environment variable that +holds the value you wish to use for the tag. -So we use ```ecs-deploy``` like this: +For example: - ecs-deploy -c production1 -n doorman-api -i my.private.repo/doorman-api -e CI_TIMESTAMP + ecs-deploy -c CLUSTERNAME -n SERVICENAME -i my.private.repo.com/frontend_container:latest -e CI_TIMESTAMP AWS IAM Policy Configuration ------------------------------------------- From 2be8a27b6f5759acd79938ec054a481100fdedd2 Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Mon, 18 Mar 2024 11:04:22 -0400 Subject: [PATCH 08/12] update name of workflow --- .github/workflows/{build-and-publish.yml => ci.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{build-and-publish.yml => ci.yml} (97%) diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/ci.yml similarity index 97% rename from .github/workflows/build-and-publish.yml rename to .github/workflows/ci.yml index 02fe580..629a6b0 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Build and Publish +name: Continuous Integration on: push: From ced6378c0a7ce0682c887c306e08f128249ad91b Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Mon, 18 Mar 2024 11:34:40 -0400 Subject: [PATCH 09/12] remove tag from -e example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8de3a0..4f9ff1b 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ holds the value you wish to use for the tag. For example: - ecs-deploy -c CLUSTERNAME -n SERVICENAME -i my.private.repo.com/frontend_container:latest -e CI_TIMESTAMP + ecs-deploy -c CLUSTERNAME -n SERVICENAME -i my.private.repo.com/frontend_container -e CI_TIMESTAMP AWS IAM Policy Configuration ------------------------------------------- From b96967cd2d84b242b4b9b49bc86b9c6a1f9e3494 Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Mon, 18 Mar 2024 14:50:47 -0400 Subject: [PATCH 10/12] reformat to basic markdown --- README.md | 62 ++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 4f9ff1b..5721b19 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,16 @@ -ecs-deploy -================= +# ecs-deploy ![Status for silinternational/ecs-deploy](https://github.com/silinternational/ecs-deploy/actions/workflows/build-and-deploy.yml/badge.svg?branch=master) This script uses the Task Definition and Service entities in Amazon's ECS to instigate an automatic blue/green deployment. -NOTE: Maintenance Only ----------------------- +## NOTE: Maintenance Only `ecs-deploy` is now in maintenance mode. In other words, we are considering it "feature complete" and will generally only consider PRs if they are bugfixes or are to add support for new AWS CLI features. -Usage ------ +## Usage One of the following is required: -n | --service-name Name of service to deploy @@ -87,21 +84,19 @@ Usage Notes: - If a tag is not found in image and an ENV var is not used via -e, it will default the tag to "latest" -Installation ------------- +## Installation + +- Install and configure [aws-cli](http://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html#install-cli) +- Install [jq](https://github.com/stedolan/jq/wiki/Installation) +- Install ecs-deploy: -* Install and configure [aws-cli](http://docs.aws.amazon.com/cli/latest/userguide/tutorial-ec2-ubuntu.html#install-cli) -* Install [jq](https://github.com/stedolan/jq/wiki/Installation) -* Install ecs-deploy: ``` curl https://raw.githubusercontent.com/silinternational/ecs-deploy/master/ecs-deploy | sudo tee /usr/bin/ecs-deploy sudo chmod +x /usr/bin/ecs-deploy ``` - -How it works ------------- +## How it works _Note: Some nouns in the next paragraphs are capitalized to indicate that they are words which have specific meanings in AWS_ @@ -129,11 +124,11 @@ _Naturally, enough computing resources must be available in the ECS cluster for Consequently, all that is needed to deploy a new version of an application is to update the Service which is running its Tasks to point at a new version of the Task Definition. `ecs-deploy` uses the python `aws` utility to do this. It, - * Pulls the JSON representation of the in-use Task Definition; or the most recently created if using `--use-latest-task-def` - * Edits it - * Defines a new version, with the changes - * Updates the Service to use the new version - * Waits, querying Amazon's API to make sure that the Service has been able to create a new Task +- Pulls the JSON representation of the in-use Task Definition; or the most recently created if using `--use-latest-task-def` +- Edits it +- Defines a new version, with the changes +- Updates the Service to use the new version +- Waits, querying Amazon's API to make sure that the Service has been able to create a new Task The second step merits more explanation: since a Task Definition [may] define multiple containers, the question arises, "what must be changed to create a new revision?" Empirically, the surprising answer is nothing; Amazon allows you to create a new @@ -169,8 +164,8 @@ Or perhaps just obtain read the docker tag from another file in your development In any case, just make sure your process builds, tags, and pushes the docker image you use to the repository before running this script. -Use Environment Variable for tag name value -------------------------------------------- +## 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 example, we want to use a unique docker image/tag for each task definition. This gives us the ability to revert/rollback changes by just selecting a previous task @@ -183,8 +178,8 @@ For example: ecs-deploy -c CLUSTERNAME -n SERVICENAME -i my.private.repo.com/frontend_container -e CI_TIMESTAMP -AWS IAM Policy Configuration -------------------------------------------- +## AWS IAM Policy Configuration + Here's an example of a suitable custom policy for [AWS IAM](https://aws.amazon.com/documentation/iam/): ```json @@ -212,15 +207,15 @@ Here's an example of a suitable custom policy for [AWS IAM](https://aws.amazon.c } ``` -Troubleshooting ---------------- - - You must provide AWS credentials in one of the supported formats. If you do - not, you'll see some error output from the AWS CLI, something like: +## Troubleshooting - You must specify a region. You can also configure your region by running "aws configure". +- You must provide AWS credentials in one of the supported formats. If you do + not, you'll see some error output from the AWS CLI, something like: + + You must specify a region. You can also configure your region by running "aws configure". + +## Testing -Testing -------- Automated tests are performed using [bats](https://github.com/sstephenson/bats). The goal of testing is to ensure that updates/changes do not break core functionality. Unfortunately not all of `ecs-deploy` is testable since portions interact with @@ -229,9 +224,10 @@ is tested. Any new functionality and pull requests should come with tests as well (if possible). -Github Actions Support -------- -Github Actions support is available. Add a code block similar to that below to your actions yaml file. Parameters are passed to the ecs-deploy tool under 'with' section. For each parameter, the parameter name followed by _cmd must be called with the appropriate parameter option like '--aws-access-key' in addition to supplying the parameter aws_access_key with the appropriate value. +## Github Actions Support + +Github Actions support is available. Add a code block similar to that below to your actions yaml file. Parameters are passed to the ecs-deploy tool under 'with' section. For each parameter, the parameter name followed by \_cmd must be called with the appropriate parameter option like '--aws-access-key' in addition to supplying the parameter aws_access_key with the appropriate value. + ``` deploy_to_ecs: name: 'Deploy updated container image via blue/green deployment to ECS service.' From f97e9a8c9a501e32fa10ff2ce39a2c3b4131ef9f Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Mon, 18 Mar 2024 14:53:38 -0400 Subject: [PATCH 11/12] use more generic names --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5721b19..fb00ba2 100644 --- a/README.md +++ b/README.md @@ -63,19 +63,19 @@ are to add support for new AWS CLI features. Examples: Simple deployment of a service (Using env vars for AWS settings): - ecs-deploy -c production1 -n doorman-service -i docker.repo.com/doorman:latest + ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container:latest All options: - ecs-deploy -k ABC123 -s SECRETKEY -r us-east-1 -c production1 -n doorman-service -i docker.repo.com/doorman -m 50 -M 100 -t 240 -D 2 -e CI_TIMESTAMP -v + ecs-deploy -k ABC123 -s SECRETKEY -r us-east-1 -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -m 50 -M 100 -t 240 -D 2 -e CI_TIMESTAMP -v Updating a task definition with a new image: - ecs-deploy -d open-door-task -i docker.repo.com/doorman:17 + ecs-deploy -d my-task-definition -i my.private.repo.com/frontend_container:17 Using profiles (for STS delegated credentials, for instance): - ecs-deploy -p PROFILE -c production1 -n doorman-service -i docker.repo.com/doorman -t 240 -e CI_TIMESTAMP -v + ecs-deploy -p my-profile -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -t 240 -e CI_TIMESTAMP -v Update just the tag on whatever image is found in ECS Task (supports multi-container tasks): @@ -147,7 +147,7 @@ be an unlikely use case._ This behavior allows two possible process to specify which images, and therefore which configurations, to deploy. First, you may set the tag to always be `latest` (or some other static value), like so: - ecs-deploy -c CLUSTERNAME -n SERVICENAME -i my.private.repo.com/frontend_container:latest + ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container:latest This will result in identical new versions of the Task Definition being created, but the Service will still do a blue/green deployment, and will so will pull down the latest version (if you previously pushed it into the registry). @@ -155,11 +155,11 @@ deployment, and will so will pull down the latest version (if you previously pus Alternatively, you may specify some other means of obtaining the tag, since the script `eval`s the image string. You could use git tags as a map to docker tags: - ecs-deploy -c CLUSTERNAME -n SERVICENAME -i 'my.private.repo.com/frontend_container:`git describe`' + ecs-deploy -c my-cluster-name -n my-service-name -i 'my.private.repo.com/frontend_container:`git describe`' Or perhaps just obtain read the docker tag from another file in your development: - ecs-deploy -c CLUSTERNAME -n SERVICENAME -i 'my.private.repo.com/frontend_container:$(< VERSION)' + ecs-deploy -c my-cluster-name -n my-service-name -i 'my.private.repo.com/frontend_container:$(< VERSION)' In any case, just make sure your process builds, tags, and pushes the docker image you use to the repository before running this script. @@ -176,7 +176,7 @@ holds the value you wish to use for the tag. For example: - ecs-deploy -c CLUSTERNAME -n SERVICENAME -i my.private.repo.com/frontend_container -e CI_TIMESTAMP + ecs-deploy -c my-cluster-name -n my-service-name -i my.private.repo.com/frontend_container -e CI_TIMESTAMP ## AWS IAM Policy Configuration From 7896b6e36051b13b3a0cfc03da9eca369d3ae731 Mon Sep 17 00:00:00 2001 From: Jason Jackson Date: Mon, 18 Mar 2024 15:20:50 -0400 Subject: [PATCH 12/12] update version to 3.10.17 --- ecs-deploy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs-deploy b/ecs-deploy index 39338f1..25478cc 100755 --- a/ecs-deploy +++ b/ecs-deploy @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Setup default values for variables -VERSION="3.10.16" +VERSION="3.10.17" CLUSTER=false SERVICE=false TASK_DEFINITION=false