Skip to content

Commit

Permalink
Merge pull request #168 from CircleCI-Public/implement-deploy-schedul…
Browse files Browse the repository at this point in the history
…ed-tasks

feat: added deploy-ecs-scheduled-task command
  • Loading branch information
brivu authored Jun 24, 2022
2 parents 0f2434b + 422cf18 commit c2bedd2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/commands/deploy-ecs-scheduled-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
description: |
Deploy an ECS Scheduled Task Rule after updating a task definition. The update-task-definition command must be run first.
parameters:
rule-name:
description: The name of the scheduled task's rule to update.
type: string
steps:
- run:
name: Deploy rule with updated task definition
environment:
ECS_PARAM_RULE_NAME: <<parameters.rule-name>>
command: <<include(scripts/deploy-ecs-scheduled-task.sh)>>
13 changes: 13 additions & 0 deletions src/jobs/update-task-definition-from-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ parameters:
description: |
Location of your .json task definition file (relative or absolute).
type: string
deploy-scheduled-task:
description: >
Set this parameter to true to deploy updated task definition to a scheduled task rule.
type: boolean
default: false
rule-name:
description: The name of the scheduled task's rule to update. Must be a valid ECS Rule.
type: string
steps:
- aws-cli/setup:
aws-access-key-id: << parameters.aws-access-key-id >>
Expand All @@ -38,3 +46,8 @@ steps:
- update-task-definition-from-json:
task-definition-json: << parameters.task-definition-json >>
profile-name: << parameters.profile-name >>
- when:
condition: <<parameters.deploy-scheduled-task>>
steps:
- deploy-ecs-scheduled-task:
rule-name: <<parameters.rule-name>>
13 changes: 13 additions & 0 deletions src/jobs/update-task-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ parameters:
Values should not contain commas.
type: string
default: ''
deploy-scheduled-task:
description: >
Set this parameter to true to deploy updated task definition to a scheduled task rule.
type: boolean
default: false
rule-name:
description: The name of the scheduled task's rule to update. Must be a valid ECS Rule.
type: string
steps:
- aws-cli/setup:
aws-access-key-id: << parameters.aws-access-key-id >>
Expand All @@ -76,3 +84,8 @@ steps:
container-image-name-updates: << parameters.container-image-name-updates >>
container-env-var-updates: << parameters.container-env-var-updates >>
profile-name: << parameters.profile-name >>
- when:
condition: <<parameters.deploy-scheduled-task>>
steps:
- deploy-ecs-scheduled-task:
rule-name: <<parameters.rule-name>>
19 changes: 19 additions & 0 deletions src/scripts/deploy-ecs-scheduled-task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
td_arn=$CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN

if [ -z "$td_arn" ]; then
echo "Updated task definition not found. Please run update-task-definition command before deploy-ecs-scheduled-task"
exit 1
fi

CLI_OUTPUT_FILE=$(mktmp cli-output.json.XXXX)
CLI_INPUT_FILE=$(mktmp cli-input.json.XXXX)

aws events list-targets-by-rule --rule "$ECS_PARAM_RULE_NAME" --output json > "$CLI_OUTPUT_FILE"

if < "$CLI_OUTPUT_FILE" jq ' .Targets[] | has("EcsParameters")' | grep "false"; then
echo "Invalid ECS Rule. $ECS_PARAM_RULE_NAME does not contain EcsParameters key. Please create a valid ECS Rule and try again"
exit 1
fi

< "$CLI_OUTPUT_FILE" jq --arg td_arn "$td_arn" '.Targets[].EcsParameters.TaskDefinitionArn |= $td_arn' > "$CLI_INPUT_FILE"
aws events put-targets --cli-input-json "$(cat "$CLI_INPUT_FILE")"
2 changes: 1 addition & 1 deletion src/scripts/update-bluegreen-service-via-task-def.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ECS_PARAM_CD_LOAD_BALANCED_CONTAINER_NAME=$(eval echo "$ECS_PARAM_CD_LOAD_BALANC
DEPLOYED_REVISION="${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}"

if [ "$ECS_PARAM_ENABLE_CIRCUIT_BREAKER" == "1" ] && [ "$ECS_PARAM_VERIFY_REV_DEPLOY" == "0" ]; then
echo "enable-circuit-breaker is set to true, but verify-revision-deploy is set to false. verfiy-revision-deploy is must be set to true to use enable-circuit-breaker."
echo "enable-circuit-breaker is set to true, but verify-revision-deploy is set to false. verfiy-revision-deploy must be set to true to use enable-circuit-breaker."
exit 1
fi

Expand Down

0 comments on commit c2bedd2

Please sign in to comment.