Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: implement env subst #200

Merged
merged 16 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ workflows:
- orb-tools/review:
filters: *filters
- shellcheck/check:
exclude: SC2148,SC2038,SC2086,SC2002,SC2016
filters: *filters
- orb-tools/continue:
orb_name: aws-ecs
Expand Down
4 changes: 2 additions & 2 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ workflows:
filters: *filters
requires:
- codedeploy_fargate_test-update_service-command
aws_region: AWS_REGION
region: AWS_REGION
family: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service"
cluster: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster"
container_image_name_updates: "container=${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service,image-and-tag=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}:${CIRCLE_SHA1}"
Expand Down Expand Up @@ -709,7 +709,7 @@ workflows:
filters: *filters
requires:
- codedeploy_fargate_test-update_service-job
aws_region: AWS_REGION
region: AWS_REGION
family: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service"
cluster: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster"
container_image_name_updates: "container=${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service,image-and-tag=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}:${CIRCLE_SHA1}"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/deploy_ecs_scheduled_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ steps:
- run:
name: Deploy rule with updated task definition
environment:
ECS_PARAM_RULE_NAME: <<parameters.rule_name>>
ORB_EVAL_RULE_NAME: <<parameters.rule_name>>
command: <<include(scripts/deploy_ecs_scheduled_task.sh)>>
6 changes: 3 additions & 3 deletions src/commands/install_ecs_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ steps:
- run:
name: Install AWS ECS CLI
environment:
ECS_PARAM_VERSION: <<parameters.version>>
ECS_PARAM_INSTALL_DIR: <<parameters.install_dir>>
ECS_PARAM_OVERRIDE_INSTALLED: <<parameters.override_installed>>
ORB_EVAL_VERSION: <<parameters.version>>
ORB_EVAL_INSTALL_DIR: <<parameters.install_dir>>
ORB_VAL_OVERRIDE_INSTALLED: <<parameters.override_installed>>
command: <<include(scripts/install_ecs_cli.sh)>>
42 changes: 21 additions & 21 deletions src/commands/run_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ parameters:
profile_name:
description: AWS profile name to be configured.
type: string
default: ''
default: "default"
run_task_output:
description: |
Specifies a local json file to save the output logs from the aws ecs run_task command. Use tools like JQ to read and parse this information such as "task-arns" and "task-ids"
Expand All @@ -123,23 +123,23 @@ steps:
name: Run Task
command: <<include(scripts/run_task.sh)>>
environment:
ECS_PARAM_CLUSTER_NAME: <<parameters.cluster>>
ECS_PARAM_TASK_DEF: <<parameters.task_definition>>
ECS_PARAM_COUNT: <<parameters.count>>
ECS_PARAM_STARTED_BY: <<parameters.started_by>>
ECS_PARAM_GROUP: <<parameters.group>>
ECS_PARAM_PLACEMENT_CONSTRAINTS: <<parameters.placement_constraints>>
ECS_PARAM_PLACEMENT_STRATEGY: <<parameters.placement_strategy>>
ECS_PARAM_LAUNCH_TYPE: <<parameters.launch_type>>
ECS_PARAM_PLATFORM_VERSION: <<parameters.platform_version>>
ECS_PARAM_AWSVPC: <<parameters.awsvpc>>
ECS_PARAM_SUBNET_ID: <<parameters.subnet_ids>>
ECS_PARAM_SEC_GROUP_ID: <<parameters.security_group_ids>>
ECS_PARAM_ASSIGN_PUB_IP: <<parameters.assign_public_ip>>
ECS_PARAM_OVERRIDES: <<parameters.overrides>>
ECS_PARAM_TAGS: <<parameters.tags>>
ECS_PARAM_ENABLE_ECS_MANAGED_TAGS: <<parameters.enable_ecs_managed_tags>>
ECS_PARAM_PROPAGATE_TAGS: <<parameters.propagate_tags>>
ECS_PARAM_CD_CAPACITY_PROVIDER_STRATEGY: <<parameters.capacity_provider_strategy>>
ECS_PARAM_PROFILE_NAME: <<parameters.profile_name>>
ECS_PARAM_RUN_TASK_OUTPUT: <<parameters.run_task_output>>
ORB_EVAL_CLUSTER_NAME: <<parameters.cluster>>
ORB_EVAL_TASK_DEF: <<parameters.task_definition>>
ORB_VAL_COUNT: <<parameters.count>>
ORB_EVAL_STARTED_BY: <<parameters.started_by>>
ORB_EVAL_GROUP: <<parameters.group>>
ORB_EVAL_PLACEMENT_CONSTRAINTS: <<parameters.placement_constraints>>
ORB_EVAL_PLACEMENT_STRATEGY: <<parameters.placement_strategy>>
ORB_VAL_LAUNCH_TYPE: <<parameters.launch_type>>
ORB_EVAL_PLATFORM_VERSION: <<parameters.platform_version>>
ORB_VAL_AWSVPC: <<parameters.awsvpc>>
ORB_EVAL_SUBNET_ID: <<parameters.subnet_ids>>
ORB_EVAL_SEC_GROUP_ID: <<parameters.security_group_ids>>
ORB_VAL_ASSIGN_PUB_IP: <<parameters.assign_public_ip>>
ORB_EVAL_OVERRIDES: <<parameters.overrides>>
ORB_EVAL_TAGS: <<parameters.tags>>
ORB_VAL_ENABLE_ECS_MANAGED_TAGS: <<parameters.enable_ecs_managed_tags>>
ORB_VAL_PROPAGATE_TAGS: <<parameters.propagate_tags>>
ORB_EVAL_CD_CAPACITY_PROVIDER_STRATEGY: <<parameters.capacity_provider_strategy>>
ORB_EVAL_PROFILE_NAME: <<parameters.profile_name>>
ORB_EVAL_RUN_TASK_OUTPUT: <<parameters.run_task_output>>
36 changes: 18 additions & 18 deletions src/commands/update_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ parameters:
profile_name:
description: AWS profile name to be configured.
type: string
default: ''
default: "default"
codedeploy_capacity_provider_name:
description: >
The name of AWS Capacity Provider to be added to CodeDeploy deployment.
Expand Down Expand Up @@ -230,17 +230,17 @@ steps:
no_output_timeout: << parameters.verification_timeout >>
environment:
DEPLOYMENT_CONTROLLER: <<parameters.deployment_controller>>
ECS_PARAM_CD_APP_NAME: <<parameters.codedeploy_application_name>>
ECS_PARAM_CD_DEPLOY_GROUP_NAME: <<parameters.codedeploy_deployment_group_name>>
ECS_PARAM_CD_LOAD_BALANCED_CONTAINER_NAME: <<parameters.codedeploy_load_balanced_container_name>>
ECS_PARAM_CD_LOAD_BALANCED_CONTAINER_PORT: <<parameters.codedeploy_load_balanced_container_port>>
ECS_PARAM_VERIFY_REV_DEPLOY: <<parameters.verify_revision_is_deployed>>
ECS_PARAM_PROFILE_NAME: <<parameters.profile_name>>
ECS_PARAM_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>>
ECS_PARAM_CD_CAPACITY_PROVIDER_NAME: <<parameters.codedeploy_capacity_provider_name>>
ECS_PARAM_CD_CAPACITY_PROVIDER_WEIGHT: <<parameters.codedeploy_capacity_provider_weight>>
ECS_PARAM_CD_CAPACITY_PROVIDER_BASE: <<parameters.codedeploy_capacity_provider_base>>
ECS_PARAM_CD_DEPLOYMENT_CONFIG_NAME: <<parameters.deployment_config_name>>
ORB_EVAL_CD_APP_NAME: <<parameters.codedeploy_application_name>>
ORB_EVAL_CD_DEPLOY_GROUP_NAME: <<parameters.codedeploy_deployment_group_name>>
ORB_EVAL_CD_LOAD_BALANCED_CONTAINER_NAME: <<parameters.codedeploy_load_balanced_container_name>>
ORB_VAL_CD_LOAD_BALANCED_CONTAINER_PORT: <<parameters.codedeploy_load_balanced_container_port>>
ORB_VAL_VERIFY_REV_DEPLOY: <<parameters.verify_revision_is_deployed>>
ORB_EVAL_PROFILE_NAME: <<parameters.profile_name>>
ORB_VAL_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>>
ORB_EVAL_CD_CAPACITY_PROVIDER_NAME: <<parameters.codedeploy_capacity_provider_name>>
ORB_EVAL_CD_CAPACITY_PROVIDER_WEIGHT: <<parameters.codedeploy_capacity_provider_weight>>
ORB_EVAL_CD_CAPACITY_PROVIDER_BASE: <<parameters.codedeploy_capacity_provider_base>>
ORB_EVAL_CD_DEPLOYMENT_CONFIG_NAME: <<parameters.deployment_config_name>>

- when:
condition:
Expand All @@ -252,12 +252,12 @@ steps:
name: Update service with registered task definition
command: <<include(scripts/update_service_via_task_def.sh)>>
environment:
ECS_PARAM_SERVICE_NAME: <<parameters.service_name>>
ECS_PARAM_FAMILY: <<parameters.family>>
ECS_PARAM_FORCE_NEW_DEPLOY: <<parameters.force_new_deployment>>
ECS_PARAM_CLUSTER_NAME: <<parameters.cluster>>
ECS_PARAM_PROFILE_NAME: <<parameters.profile_name>>
ECS_PARAM_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>>
ORB_EVAL_SERVICE_NAME: <<parameters.service_name>>
ORB_EVAL_FAMILY: <<parameters.family>>
ORB_VAL_FORCE_NEW_DEPLOY: <<parameters.force_new_deployment>>
ORB_EVAL_CLUSTER_NAME: <<parameters.cluster>>
ORB_EVAL_PROFILE_NAME: <<parameters.profile_name>>
ORB_VAL_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>>

- when:
condition:
Expand Down
20 changes: 10 additions & 10 deletions src/commands/update_task_definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ parameters:
profile_name:
description: AWS profile name to be configured.
type: string
default: ''
default: "default"
previous_revision_number:
description: Optional previous task's revision number
type: string
Expand All @@ -69,18 +69,18 @@ steps:
name: Retrieve previous task definition and prepare new task definition values
command: <<include(scripts/get_prev_task.sh)>>
environment:
ECS_PARAM_FAMILY: <<parameters.family>>
ECS_PARAM_CONTAINER_IMAGE_NAME_UPDATES: <<parameters.container_image_name_updates>>
ECS_PARAM_CONTAINER_ENV_VAR_UPDATES: <<parameters.container_env_var_updates>>
ORB_EVAL_FAMILY: <<parameters.family>>
ORB_EVAL_CONTAINER_IMAGE_NAME_UPDATES: <<parameters.container_image_name_updates>>
ORB_EVAL_CONTAINER_ENV_VAR_UPDATE: <<parameters.container_env_var_updates>>
ECS_SCRIPT_UPDATE_CONTAINER_DEFS: <<include(scripts/update_container_defs.py)>>
ECS_SCRIPT_GET_TASK_DFN_VAL: <<include(scripts/get_task_dfn_val.py)>>
ECS_PARAM_PROFILE_NAME: <<parameters.profile_name>>
ECS_PARAM_PREVIOUS_REVISION_NUMBER: <<parameters.previous_revision_number>>
ECS_PARAM_CONTAINER_SECRET_UPDATES: <<parameters.container_secret_updates>>
ECS_PARAM_CONTAINER_DOCKER_LABEL_UPDATES: << parameters.container_docker_label_updates >>
ORB_EVAL_PROFILE_NAME: <<parameters.profile_name>>
ORB_EVAL_PREVIOUS_REVISION_NUMBER: <<parameters.previous_revision_number>>
ORB_EVAL_CONTAINER_SECRET_UPDATES: <<parameters.container_secret_updates>>
ORB_EVAL_CONTAINER_DOCKER_LABEL_UPDATES: << parameters.container_docker_label_updates >>
- run:
name: Register new task definition
command: <<include(scripts/register_new_task_def.sh)>>
environment:
ECS_PARAM_FAMILY: <<parameters.family>>
ECS_PARAM_PROFILE_NAME: <<parameters.profile_name>>
ORB_EVAL_FAMILY: <<parameters.family>>
ORB_EVAL_PROFILE_NAME: <<parameters.profile_name>>
6 changes: 3 additions & 3 deletions src/commands/update_task_definition_from_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ parameters:
profile_name:
description: AWS profile name to be configured.
type: string
default: ''
default: "default"
steps:
- run:
name: Register new task definition
command: <<include(scripts/update_task_definition_from_json.sh)>>
environment:
ECS_PARAM_TASK_DEFINITION_JSON: <<parameters.task_definition_json>>
ECS_PARAM_PROFILE_NAME: <<parameters.profile_name>>
ORB_EVAL_TASK_DEFINITION_JSON: <<parameters.task_definition_json>>
ORB_EVAL_PROFILE_NAME: <<parameters.profile_name>>
18 changes: 9 additions & 9 deletions src/commands/verify_revision_is_deployed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ parameters:
profile_name:
description: AWS profile name to be configured.
type: string
default: ''
default: "default"
steps:
- run:
name: Verify that the revision is deployed and older revisions are stopped
description: |
Poll the deployment status at intervals till the given task definition revision has reached its desired running task count and is the only one deployed for the service.
command: <<include(scripts/verify_revision_is_deployed.sh)>>
environment:
ECS_PARAM_SERVICE_NAME: <<parameters.service_name>>
ECS_PARAM_FAMILY: <<parameters.family>>
ECS_PARAM_TASK_DEF_ARN: <<parameters.task_definition_arn>>
ECS_PARAM_MAX_POLL_ATTEMPTS: <<parameters.max_poll_attempts>>
ECS_PARAM_CLUSTER_NAME: <<parameters.cluster>>
ECS_PARAM_POLL_INTERVAL: <<parameters.poll_interval>>
ECS_PARAM_FAIL_ON_VERIFY_TIMEOUT: <<parameters.fail_on_verification_timeout>>
ECS_PARAM_PROFILE_NAME: <<parameters.profile_name>>
ORB_EVAL_SERVICE_NAME: <<parameters.service_name>>
ORB_EVAL_FAMILY: <<parameters.family>>
ORB_EVAL_TASK_DEF_ARN: <<parameters.task_definition_arn>>
ORB_VAL_MAX_POLL_ATTEMPTS: <<parameters.max_poll_attempts>>
ORB_EVAL_CLUSTER_NAME: <<parameters.cluster>>
ORB_VAL_POLL_INTERVAL: <<parameters.poll_interval>>
ORB_VAL_FAIL_ON_VERIFY_TIMEOUT: <<parameters.fail_on_verification_timeout>>
ORB_EVAL_PROFILE_NAME: <<parameters.profile_name>>
2 changes: 1 addition & 1 deletion src/examples/deploy_ecs_scheduled_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ usage:
- aws-cli/setup:
# This example uses CircleCI's OpenID Connect Token to generate temporary AWS keys
role-arn: "arn:aws:iam::123456789012:role/OIDC_ARN"
aws_region: AWS_REGION
region: AWS_REGION
profile_name: "OIDC-PROFILE"
session-duration: 3600
role-session-name: "example-session-name"
Expand Down
2 changes: 1 addition & 1 deletion src/examples/update_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ usage:
- aws-cli/setup:
# This example uses CircleCI's OpenID Connect Token to generate temporary AWS keys
role-arn: "arn:aws:iam::123456789012:role/OIDC_ARN"
aws_region: AWS_REGION
region: AWS_REGION
profile_name: "OIDC-PROFILE"
session-duration: 3600
role-session-name: "example-session-name"
Expand Down
2 changes: 1 addition & 1 deletion src/examples/update_task_definition_from_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ usage:
- aws-cli/setup:
# This example uses CircleCI's OpenID Connect Token to generate temporary AWS keys
role-arn: "arn:aws:iam::123456789012:role/OIDC_ARN"
aws_region: AWS_REGION
region: AWS_REGION
profile_name: "OIDC-PROFILE"
session-duration: 3600
role-session-name: "example-session-name"
Expand Down
2 changes: 1 addition & 1 deletion src/examples/verify_revision_deplopyment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ usage:
- aws-cli/setup:
# This example uses CircleCI's OpenID Connect Token to generate temporary AWS keys
role-arn: "arn:aws:iam::123456789012:role/OIDC_ARN"
aws_region: AWS_REGION
region: AWS_REGION
profile_name: "OIDC-PROFILE"
session-duration: 3600
role-session-name: "example-session-name"
Expand Down
6 changes: 3 additions & 3 deletions src/jobs/deploy_service_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ parameters:
description: The docker image to be used for running this job on CircleCI.
type: string
default: 'cimg/python:3.10.4'
aws_region:
region:
description: AWS region to operate in. Set this to the name of the environment variable you will use to hold this value, i.e. AWS_DEFAULT_REGION.
type: env_var_name
default: AWS_DEFAULT_REGION
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
description: AWS profile name to be configured.
type: string
Expand Down
6 changes: 3 additions & 3 deletions src/jobs/run_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ parameters:
description: The docker image to be used for running this job on CircleCI.
type: string
default: 'cimg/python:3.10.4'
aws_region:
region:
description: AWS region to operate in. Set this to the name of the environment variable you will use to hold this value, i.e. AWS_DEFAULT_REGION.
type: env_var_name
default: AWS_DEFAULT_REGION
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
description: AWS profile name to be configured.
type: string
Expand Down
6 changes: 3 additions & 3 deletions src/jobs/update_task_definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ parameters:
description: The docker image to be used for running this job on CircleCI.
type: string
default: 'cimg/python:3.10.4'
aws_region:
region:
description: AWS region to operate in. Set this to the name of the environment variable you will use to hold this value, i.e. AWS_DEFAULT_REGION.
type: env_var_name
default: AWS_DEFAULT_REGION
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
description: AWS profile name to be configured.
type: string
Expand Down
6 changes: 3 additions & 3 deletions src/jobs/update_task_definition_from_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ parameters:
description: The docker image to be used for running this job on CircleCI.
type: string
default: 'cimg/python:3.10.4'
aws_region:
region:
description: AWS region to operate in. Set this to the name of the environment variable you will use to hold this value, i.e. AWS_DEFAULT_REGION.
type: env_var_name
default: AWS_DEFAULT_REGION
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
description: AWS profile name to be configured.
type: string
Expand Down
9 changes: 6 additions & 3 deletions src/scripts/deploy_ecs_scheduled_task.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
#!/bin/bash
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

ORB_EVAL_RULE_NAME="$(circleci env subst "${ORB_EVAL_RULE_NAME}")"

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

aws events list-targets-by-rule --rule "$ECS_PARAM_RULE_NAME" --output json > "$CLI_OUTPUT_FILE"
aws events list-targets-by-rule --rule "$ORB_EVAL_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"
echo "Invalid ECS Rule. $ORB_EVAL_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 --rule $ECS_PARAM_RULE_NAME --cli-input-json "$(cat "$CLI_INPUT_FILE")"
aws events put-targets --rule "$ORB_EVAL_RULE_NAME" --cli-input-json "$(cat "$CLI_INPUT_FILE")"
Loading