@@ -17,22 +17,35 @@ if ! plugin_read_list_into_result "IMAGE"; then
17
17
fi
18
18
images=(" ${result[@]} " )
19
19
20
- # optional configurations
21
- desired_count=${BUILDKITE_PLUGIN_ECS_DEPLOY_DESIRED_COUNT:- " 1" }
22
- target_group=${BUILDKITE_PLUGIN_ECS_DEPLOY_TARGET_GROUP:- " " }
23
- load_balancer_name=${BUILDKITE_PLUGIN_ECS_DEPLOY_LOAD_BALANCER_NAME:- " " }
24
- target_container=${BUILDKITE_PLUGIN_ECS_DEPLOY_TARGET_CONTAINER_NAME:- " " }
25
- target_port=${BUILDKITE_PLUGIN_ECS_DEPLOY_TARGET_CONTAINER_PORT:- " " }
26
-
27
20
if [ -n " ${BUILDKITE_PLUGIN_ECS_DEPLOY_TASK_DEFINITION:- " " } " ]; then
28
21
echo " :boom: The task-definition parameter has been deprecated"
29
22
exit 1
30
23
fi
31
24
25
+ if [ -n " ${BUILDKITE_PLUGIN_ECS_DEPLOY_SERVICE_DEFINITION:- " " } " ]; then
26
+ echo " :boom: The service-definition parameter has been deprecated"
27
+ echo " Create the service outside of this plugin first (using CloudFormation or Terraform)"
28
+ exit 1
29
+ fi
30
+
31
+ for DEPRECATED_CONFIG in deployment-config deployment-configuration desired-count load-balancer-name target-container-name target-container-port target-group; do
32
+ VAR_NAME=" BUILDKITE_PLUGIN_ECS_DEPLOY_$( echo " ${DEPRECATED_CONFIG} " | tr ' a-z-' ' A-Z_' ) "
33
+
34
+ if [ -n " ${! VAR_NAME:- " " } " ]; then
35
+ echo " :warning: The ${DEPRECATED_CONFIG} parameter has been deprecated"
36
+ echo " Please configure the service outside of this plugin"
37
+ fi
38
+ done
39
+
40
+ aws_default_args=()
41
+ if [ -n " ${BUILDKITE_PLUGIN_ECS_DEPLOY_REGION:- } " ]; then
42
+ aws_default_args+=(--region " ${BUILDKITE_PLUGIN_ECS_DEPLOY_REGION} " )
43
+ fi
44
+
32
45
task_file=$( mktemp)
33
46
trap ' rm "${task_file}"' EXIT
34
47
35
- if ! aws ecs describe-task-definition --task-definition " ${task_family} " --query ' taskDefinition' > " ${task_file} " ; then
48
+ if ! aws ecs describe-task-definition " ${aws_default_args[@]+ " ${aws_default_args[@]} " } " --task-definition " ${task_family} " --query ' taskDefinition' > " ${task_file} " ; then
36
49
echo " Could not obtain existing task definition"
37
50
fi
38
51
56
69
env_vars=()
57
70
fi
58
71
59
- aws_default_args=()
60
- if [ -n " ${BUILDKITE_PLUGIN_ECS_DEPLOY_REGION:- } " ]; then
61
- aws_default_args+=(--region " ${BUILDKITE_PLUGIN_ECS_DEPLOY_REGION} " )
62
- fi
63
-
64
- # Resolve any runtime environment variables it has
65
- target_group=$( eval " echo $target_group " )
66
- load_balancer_name=$( eval " echo $load_balancer_name " )
67
-
68
72
# jq has no in-place edition https://github.com/jqlang/jq/issues/105
69
73
container_definitions_json=$( cat " ${container_definitions} " )
70
74
image_idx=0
166
170
task_revision=$( jq ' .taskDefinition.revision' <<< " $json_output" )
167
171
echo " Registered ${task_family} :${task_revision} "
168
172
169
- # Create service if it doesn't already exist
170
- aws_describe_service_args=(
171
- --cluster " $cluster "
172
- --service " $service_name "
173
- )
174
-
175
- aws_create_service_args=(
176
- --cluster " $cluster "
177
- --service-name " $service_name "
178
- --task-definition " ${task_family} :${task_revision} "
179
- --desired-count " $desired_count "
180
- )
181
-
182
- service_definition=${BUILDKITE_PLUGIN_ECS_DEPLOY_SERVICE_DEFINITION:- " " }
183
- if [[ -n " ${service_definition} " ]]; then
184
- service_definition_json=$( cat " ${service_definition} " )
185
- else
186
- service_definition_json=" {}"
187
- fi
188
-
189
- service_defined=$(
190
- aws ecs describe-services \
191
- " ${aws_default_args[@]+" ${aws_default_args[@]} " } " \
192
- " ${aws_describe_service_args[@]} " \
193
- --query " services[?status=='ACTIVE'].status" \
194
- --output text \
195
- | wc -l
196
- )
197
-
198
- deployment_config=${BUILDKITE_PLUGIN_ECS_DEPLOY_DEPLOYMENT_CONFIGURATION:- " 100/200" }
199
- IFS=" /" read -r -a min_max_percent <<< " ${deployment_config}"
200
- min_deploy_perc=${min_max_percent[0]}
201
- max_deploy_perc=${min_max_percent[1]}
202
-
203
- aws_create_service_args+=(--deployment-configuration " maximumPercent=${max_deploy_perc} ,minimumHealthyPercent=${min_deploy_perc} " )
204
-
205
- if [[ -n $target_container ]] && [[ -n $target_port ]]; then
206
- if [[ -n $target_group ]]; then
207
- load_balancer_ref=" targetGroupArn=${target_group} "
208
- elif [[ -n $load_balancer_name ]]; then
209
- load_balancer_ref=" loadBalancerName=${load_balancer_name} "
210
- else
211
- echo " +++ ^^^"
212
- echo ' +++ You must specify either target-group or load-balancer-name'
213
- exit 1
214
- fi
215
-
216
- aws_create_service_args+=(--load-balancers " ${load_balancer_ref} ,containerName=${target_container} ,containerPort=${target_port} " )
217
- fi
218
-
219
- if [[ $service_defined -eq 0 ]]; then
220
- echo " --- :ecs: Creating a Service $service_name in cluster $cluster "
221
-
222
- aws ecs create-service \
223
- " ${aws_default_args[@]+" ${aws_default_args[@]} " } " \
224
- " ${aws_create_service_args[@]} " \
225
- --cli-input-json " $service_definition_json "
226
- fi
227
-
228
- lb_config=$( aws ecs describe-services --cluster " $cluster " --services " $service_name " --query " services[?status=='ACTIVE']" | jq -r ' .[0].loadBalancers[0]' )
229
- error=" +++ ^^^
230
- +++ Cannot update a service to add/remove a load balancer. First delete the service and then run again, or rename the service to force a new one to be created"
231
-
232
- # No easy way to tell if the target group has changed, since describe-services only returns the load balancer name
233
- if [[ " $lb_config " == " null" ]]; then
234
- if [[ -n " $target_group " ]] || [[ -n " $load_balancer_name " ]]; then
235
- echo " $error . ELB configured but none set in container"
236
- exit 1
237
- fi
238
- fi
239
-
240
- if [[ " $lb_config " == " null" ]]; then
241
- # noop
242
- true
243
- elif [[ $( echo " $lb_config " | jq -r ' .containerName' ) != " $target_container " ]] || [[ $( echo " $lb_config " | jq -r ' .containerPort' ) -ne $target_port ]]; then
244
- echo " $error . Container config differs"
245
- exit 1
246
- elif [[ -n " $target_group " ]] && [[ $( echo " $lb_config " | jq -r ' .targetGroupArn' ) != " $target_group " ]]; then
247
- echo " $error . ALB config differs"
248
- exit 1
249
- elif [[ -n " $load_balancer_name " ]] && [[ $( echo " $lb_config " | jq -r ' .loadBalancerName' ) != " $load_balancer_name " ]]; then
250
- echo " $error . ELB config differs"
251
- exit 1
252
- fi
253
-
254
173
echo " --- :ecs: Updating service for ${service_name} "
255
174
aws ecs update-service \
256
175
${aws_default_args[@]+" ${aws_default_args[@]} " } \
@@ -270,7 +189,7 @@ aws ecs wait services-stable \
270
189
service_events=$( aws ecs describe-services \
271
190
${aws_default_args[@]+" ${aws_default_args[@]} " } \
272
191
--cluster " ${cluster} " \
273
- --service " ${service_name} " \
192
+ --services " ${service_name} " \
274
193
--query ' services[].events' --output text)
275
194
276
195
if [[ $deploy_exitcode -eq 0 ]]; then
0 commit comments