@@ -52,6 +52,7 @@ expected_container_definition='[\n {\n "essential": true,\n "image": "hel
5252 export BUILDKITE_PLUGIN_ECS_DEPLOY_TASK_FAMILY=hello-world
5353 export BUILDKITE_PLUGIN_ECS_DEPLOY_IMAGE_0=hello-world:llamas
5454 export BUILDKITE_PLUGIN_ECS_DEPLOY_IMAGE_1=hello-world:alpacas
55+
5556 export BUILDKITE_PLUGIN_ECS_DEPLOY_TASK_DEFINITION=examples/multiple-images.json
5657
5758 expected_multiple_container_definition=' [\n {\n "essential": true,\n "image": "hello-world:llamas",\n "memory": 100,\n "name": "sample",\n "portMappings": [\n {\n "containerPort": 80,\n "hostPort": 80\n }\n ]\n },\n {\n "essential": true,\n "image": "hello-world:alpacas",\n "memory": 100,\n "name": "sample",\n "portMappings": [\n {\n "containerPort": 80,\n "hostPort": 80\n }\n ]\n }\n]'
@@ -77,6 +78,45 @@ expected_container_definition='[\n {\n "essential": true,\n "image": "hel
7778 unset BUILDKITE_PLUGIN_ECS_DEPLOY_IMAGE_1
7879}
7980
81+ @test " Add env vars on multiple images" {
82+ export BUILDKITE_BUILD_NUMBER=1
83+ export BUILDKITE_PLUGIN_ECS_DEPLOY_CLUSTER=my-cluster
84+ export BUILDKITE_PLUGIN_ECS_DEPLOY_SERVICE=my-service
85+ export BUILDKITE_PLUGIN_ECS_DEPLOY_TASK_FAMILY=hello-world
86+ export BUILDKITE_PLUGIN_ECS_DEPLOY_IMAGE_0=hello-world:llamas
87+ export BUILDKITE_PLUGIN_ECS_DEPLOY_IMAGE_1=hello-world:alpacas
88+ export BUILDKITE_PLUGIN_ECS_DEPLOY_ENV_0=" FOO=bar"
89+ export BUILDKITE_PLUGIN_ECS_DEPLOY_ENV_1=" BAZ=bing"
90+
91+ export BUILDKITE_PLUGIN_ECS_DEPLOY_TASK_DEFINITION=examples/multiple-images.json
92+
93+ # first command stubbed saves the container definition to ${_TMP_DIR}/container_definition for later review and manipulation
94+ stub aws \
95+ " ecs register-task-definition --family hello-world --container-definitions '*' : echo \"\$ 6\" > ${_TMP_DIR} /container_definition ; echo '{\" taskDefinition\" :{\" revision\" :1}}'"
96+
97+ run " $PWD /hooks/command"
98+
99+ # there is no assert_success because we are just checking that the definition was updated accordingly
100+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[0].environment[0].name' ) ' FOO'
101+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[0].environment[0].value' ) ' bar'
102+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[1].environment[0].name' ) ' FOO'
103+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[1].environment[0].value' ) ' bar'
104+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[0].environment[1].name' ) ' BAZ'
105+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[0].environment[1].value' ) ' bing'
106+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[1].environment[1].name' ) ' BAZ'
107+ assert_equal $( cat ${_TMP_DIR} /container_definition | jq -r ' .[1].environment[1].value' ) ' bing'
108+
109+ # as the aws command is called more times than stubbed, it is unstubbed automatically
110+ # unstub aws
111+ unset BUILDKITE_PLUGIN_ECS_DEPLOY_CLUSTER
112+ unset BUILDKITE_PLUGIN_ECS_DEPLOY_SERVICE
113+ unset BUILDKITE_PLUGIN_ECS_DEPLOY_TASK_DEFINITION
114+ unset BUILDKITE_PLUGIN_ECS_DEPLOY_IMAGE_0
115+ unset BUILDKITE_PLUGIN_ECS_DEPLOY_IMAGE_1
116+ unset BUILDKITE_PLUGIN_ECS_DEPLOY_ENV_0
117+ unset BUILDKITE_PLUGIN_ECS_DEPLOY_ENV_1
118+ }
119+
80120@test " Run a deploy when service does not exist" {
81121 export BUILDKITE_BUILD_NUMBER=1
82122 export BUILDKITE_PLUGIN_ECS_DEPLOY_CLUSTER=my-cluster
0 commit comments