Skip to content

Commit

Permalink
Feature: job parameter region for all the commands and jobs (#224)
Browse files Browse the repository at this point in the history
* Add explicit region parameter to all jobs, scripts and commands

* Remove region duplicates2

* Add debug

* Add debug

* Add debug

* Fix region on new task def

* Update region parameter description

* update examples
  • Loading branch information
marboledacci authored Oct 2, 2024
1 parent bb0bace commit ccaddc8
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 34 deletions.
6 changes: 4 additions & 2 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ workflows:
filters: *filters
requires:
- codedeploy_fargate_test-update_service-command
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 @@ -727,7 +727,7 @@ workflows:
filters: *filters
requires:
- codedeploy_fargate_test-update_service-job
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 @@ -880,6 +880,8 @@ executors:
mac:
macos:
xcode: 13.4.1
shell: bash -eox pipefail
linux:
docker:
- image: cimg/base:current
shell: bash -eox pipefail
5 changes: 5 additions & 0 deletions src/commands/deploy_ecs_scheduled_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ parameters:
rule_name:
description: The name of the scheduled task's rule to update.
type: string
region:
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: $AWS_DEFAULT_REGION
steps:
- run:
name: Deploy rule with updated task definition
environment:
ORB_STR_RULE_NAME: <<parameters.rule_name>>
ORB_AWS_REGION: << parameters.region >>
command: <<include(scripts/deploy_ecs_scheduled_task.sh)>>
5 changes: 5 additions & 0 deletions src/commands/run_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ parameters:
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"
type: string
default: ''
region:
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: $AWS_DEFAULT_REGION
steps:
- run:
name: Run Task
Expand All @@ -140,6 +144,7 @@ steps:
ORB_STR_PLATFORM_VERSION: <<parameters.platform_version>>
ORB_BOOL_AWSVPC: <<parameters.awsvpc>>
ORB_STR_SUBNET_ID: <<parameters.subnet_ids>>
ORB_AWS_REGION: << parameters.region >>
ORB_STR_SEC_GROUP_ID: <<parameters.security_group_ids>>
ORB_STR_ASSIGN_PUB_IP: <<parameters.assign_public_ip>>
ORB_STR_OVERRIDES: <<parameters.overrides>>
Expand Down
7 changes: 6 additions & 1 deletion src/commands/update_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ steps:
container_secret_updates: << parameters.container_secret_updates >>
container_docker_label_updates: << parameters.container_docker_label_updates >>
profile_name: << parameters.profile_name >>
region: << parameters.region >>
- when:
condition: << parameters.skip_task_definition_registration >>
steps:
Expand All @@ -222,7 +223,8 @@ steps:
aws ecs tag-resource \
--resource-arn ${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN} \
--tags <<parameters.task_definition_tags>> \
--profile=<< parameters.profile_name >>
--profile=<< parameters.profile_name >> \
--region << parameters.region >>
- when:
condition:
equal:
Expand All @@ -241,6 +243,7 @@ steps:
ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT: <<parameters.codedeploy_load_balanced_container_port>>
ORB_BOOL_VERIFY_REV_DEPLOY: <<parameters.verify_revision_is_deployed>>
ORB_STR_PROFILE_NAME: <<parameters.profile_name>>
ORB_AWS_REGION: << parameters.region >>
ORB_BOOL_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>>
ORB_STR_CD_CAPACITY_PROVIDER_NAME: <<parameters.codedeploy_capacity_provider_name>>
ORB_STR_CD_CAPACITY_PROVIDER_WEIGHT: <<parameters.codedeploy_capacity_provider_weight>>
Expand All @@ -261,6 +264,7 @@ steps:
ORB_STR_FAMILY: <<parameters.family>>
ORB_BOOL_FORCE_NEW_DEPLOY: <<parameters.force_new_deployment>>
ORB_STR_CLUSTER_NAME: <<parameters.cluster>>
ORB_AWS_REGION: << parameters.region >>
ORB_STR_PROFILE_NAME: <<parameters.profile_name>>
ORB_BOOL_ENABLE_CIRCUIT_BREAKER: <<parameters.enable_circuit_breaker>>

Expand All @@ -279,5 +283,6 @@ steps:
task_definition_arn: $CCI_ORB_AWS_ECS_DEPLOYED_REVISION
max_poll_attempts: << parameters.max_poll_attempts >>
poll_interval: << parameters.poll_interval >>
region: << parameters.region >>
fail_on_verification_timeout: << parameters.fail_on_verification_timeout >>
profile_name: << parameters.profile_name >>
6 changes: 6 additions & 0 deletions src/commands/update_task_definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ parameters:
description: Optional previous task's revision number
type: string
default: ''
region:
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: $AWS_DEFAULT_REGION
steps:
- run:
name: Retrieve previous task definition and prepare new task definition values
Expand All @@ -76,6 +80,7 @@ steps:
ORB_SCRIPT_GET_TASK_DFN_VAL: <<include(scripts/get_task_dfn_val.py)>>
ORB_STR_PROFILE_NAME: <<parameters.profile_name>>
ORB_STR_PREVIOUS_REVISION_NUMBER: <<parameters.previous_revision_number>>
ORB_AWS_REGION: << parameters.region >>
ORB_STR_CONTAINER_SECRET_UPDATES: <<parameters.container_secret_updates>>
ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES: << parameters.container_docker_label_updates >>
- run:
Expand All @@ -84,3 +89,4 @@ steps:
environment:
ORB_STR_FAMILY: <<parameters.family>>
ORB_STR_PROFILE_NAME: <<parameters.profile_name>>
ORB_AWS_REGION: << parameters.region >>
5 changes: 5 additions & 0 deletions src/commands/update_task_definition_from_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ parameters:
description: AWS profile name to be configured.
type: string
default: "default"
region:
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: $AWS_DEFAULT_REGION
steps:
- run:
name: Register new task definition
command: <<include(scripts/update_task_definition_from_json.sh)>>
environment:
ORB_STR_TASK_DEFINITION_JSON: <<parameters.task_definition_json>>
ORB_STR_PROFILE_NAME: <<parameters.profile_name>>
ORB_AWS_REGION: << parameters.region >>
5 changes: 5 additions & 0 deletions src/commands/verify_revision_is_deployed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ parameters:
description: AWS profile name to be configured.
type: string
default: "default"
region:
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: $AWS_DEFAULT_REGION
steps:
- run:
name: Verify that the revision is deployed and older revisions are stopped
Expand All @@ -46,6 +50,7 @@ steps:
ORB_STR_TASK_DEF_ARN: <<parameters.task_definition_arn>>
ORB_VAL_MAX_POLL_ATTEMPTS: <<parameters.max_poll_attempts>>
ORB_STR_CLUSTER_NAME: <<parameters.cluster>>
ORB_AWS_REGION: << parameters.region >>
ORB_VAL_POLL_INTERVAL: <<parameters.poll_interval>>
ORB_VAL_FAIL_ON_VERIFY_TIMEOUT: <<parameters.fail_on_verification_timeout>>
ORB_STR_PROFILE_NAME: <<parameters.profile_name>>
8 changes: 5 additions & 3 deletions src/examples/deploy_ecs_scheduled_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: |
usage:
version: 2.1
orbs:
aws-cli: circleci/aws-cli@4.0
aws-ecs: circleci/aws-ecs@4.0
aws-cli: circleci/aws-cli@5.1.0
aws-ecs: circleci/aws-ecs@6.0.0
jobs:
deploy_scheduled_task:
docker:
Expand All @@ -14,14 +14,16 @@ 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"
region: AWS_REGION
region: us-east-1
profile_name: "OIDC-PROFILE"
session_duration: "3600"
role_session_name: "example-session-name"
- aws-ecs/update_task_definition_from_json:
task_definition_json: my-app-definition.json
region: us-east-1
- aws-ecs/deploy_ecs_scheduled_task:
rule_name: "example-rule"
region: us-east-1
workflows:
deploy:
jobs:
Expand Down
7 changes: 4 additions & 3 deletions src/examples/deploy_service_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: |
usage:
version: 2.1
orbs:
aws-ecr: circleci/aws-ecr@9.0
aws-ecs: circleci/aws-ecs@4.0
aws-ecr: circleci/aws-ecr@9.3.4
aws-ecs: circleci/aws-ecs@6.0.0
# Importing aws-cli orb is required for authentication
aws-cli: circleci/aws-cli@4.0
aws-cli: circleci/aws-cli@5.1.0
workflows:
build-and-deploy:
jobs:
Expand All @@ -31,6 +31,7 @@ usage:
role_arn: "arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE"
# Must use same profile configured in aws-cli/setup command
profile: "OIDC-USER"
region: us-east-1
requires:
- aws-ecr/build-and-push-image
family: '${MY_APP_PREFIX}-service'
Expand Down
5 changes: 3 additions & 2 deletions src/examples/run_task_ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ description: Start the run of an ECS task on EC2.
usage:
version: 2.1
orbs:
aws-ecs: circleci/aws-ecs@4.0
aws-cli: circleci/aws-cli@4.0
aws-ecs: circleci/aws-ecs@6.0.0
aws-cli: circleci/aws-cli@5.1.0
jobs:
run_task:
docker:
Expand All @@ -15,6 +15,7 @@ usage:
- aws-ecs/run_task:
cluster: cluster1
task_definition: myapp
region: us-east-1
awsvpc: false
launch_type: EC2
workflows:
Expand Down
3 changes: 2 additions & 1 deletion src/examples/run_task_fargate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description: Start the run of an ECS task on Fargate.
usage:
version: 2.1
orbs:
aws-ecs: circleci/aws-ecs@4.0
aws-ecs: circleci/aws-ecs@6.0.0
jobs:
run_task:
docker:
Expand All @@ -13,6 +13,7 @@ usage:
role_arn: "arn:aws:iam::123456789012:role/VALID_OIDC_ECS_ROLE"
- aws-ecs/run_task:
cluster: cluster1
region: us-east-1
task_definition: myapp
subnet_ids: '$SUBNET_ONE, $SUBNET_TWO'
security_group_ids: $SECURITY_GROUP_IDS
Expand Down
3 changes: 2 additions & 1 deletion src/examples/run_task_fargate_spot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >
usage:
version: 2.1
orbs:
aws-ecs: circleci/aws-ecs@4.0
aws-ecs: circleci/aws-ecs@6.0.0
jobs:
run_task:
docker:
Expand All @@ -18,6 +18,7 @@ usage:
cluster: $CLUSTER_NAME
capacity_provider_strategy: capacityProvider=FARGATE,weight=1 capacityProvider=FARGATE_SPOT,weight=1
launch_type: ""
region: us-east-1
task_definition: $My_Task_Def
subnet_ids: '$SUBNET_ONE, $SUBNET_TWO'
security_group_ids: $SECURITY_GROUP_IDS_FETCHED
Expand Down
5 changes: 3 additions & 2 deletions src/examples/update_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: |
usage:
version: 2.1
orbs:
aws-cli: circleci/aws-cli@4.0
aws-ecs: circleci/aws-ecs@4.0
aws-cli: circleci/aws-cli@5.1.0
aws-ecs: circleci/aws-ecs@6.0.0
jobs:
update-tag:
docker:
Expand All @@ -21,6 +21,7 @@ usage:
- aws-ecs/update_service:
family: '${MY_APP_PREFIX}-service'
cluster: '${MY_APP_PREFIX}-cluster'
region: us-east-1
container_image_name_updates: 'container=${MY_APP_PREFIX}-service,tag=stable'
workflows:
deploy:
Expand Down
5 changes: 3 additions & 2 deletions src/examples/update_task_definition_from_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ description: Use the AWS CLI and this orb to create a new ECS task definition ba
usage:
version: 2.1
orbs:
aws-cli: circleci/aws-cli@4.0
aws-ecs: circleci/aws-ecs@4.0
aws-cli: circleci/aws-cli@5.1.0
aws-ecs: circleci/aws-ecs@6.0.0
jobs:
update-tag:
docker:
Expand All @@ -17,6 +17,7 @@ usage:
session_duration: "3600"
role_session_name: "example-session-name"
- aws-ecs/update_task_definition_from_json:
region: us-east-1
task_definition_json: my-app-definition.json
workflows:
deploy:
Expand Down
5 changes: 3 additions & 2 deletions src/examples/verify_revision_deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ description: Verify the deployment of an ECS revision.
usage:
version: 2.1
orbs:
aws-cli: circleci/aws-cli@4.0
aws-ecs: circleci/aws-ecs@4.0
aws-cli: circleci/aws-cli@5.1.0
aws-ecs: circleci/aws-ecs@6.0.0
jobs:
verify-deployment:
docker:
Expand All @@ -30,6 +30,7 @@ usage:
- aws-ecs/verify_revision_is_deployed:
family: '${MY_APP_PREFIX}-service'
cluster: '${MY_APP_PREFIX}-cluster'
region: us-east-1
task_definition_arn: '${TASK_DEFINITION_ARN}'
workflows:
test-workflow:
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/deploy_service_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: >
parameters:
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.
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
Expand Down
3 changes: 2 additions & 1 deletion src/jobs/run_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: |
parameters:
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.
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
Expand Down Expand Up @@ -167,6 +167,7 @@ steps:
launch_type: << parameters.launch_type >>
platform_version: << parameters.platform_version >>
awsvpc: << parameters.awsvpc >>
region: << parameters.region >>
subnet_ids: << parameters.subnet_ids >>
security_group_ids: << parameters.security_group_ids >>
assign_public_ip: << parameters.assign_public_ip >>
Expand Down
4 changes: 3 additions & 1 deletion src/jobs/update_task_definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: |
parameters:
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.
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
Expand Down Expand Up @@ -98,6 +98,7 @@ steps:
family: << parameters.family >>
container_image_name_updates: << parameters.container_image_name_updates >>
container_env_var_updates: << parameters.container_env_var_updates >>
region: << parameters.region >>
container_secret_updates: << parameters.container_secret_updates >>
container_docker_label_updates: << parameters.container_docker_label_updates >>
profile_name: << parameters.profile_name >>
Expand All @@ -106,3 +107,4 @@ steps:
steps:
- deploy_ecs_scheduled_task:
rule_name: <<parameters.rule_name>>
region: << parameters.region >>
4 changes: 3 additions & 1 deletion src/jobs/update_task_definition_from_json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description: |
Install AWS CLI and a task definition from a json file.
parameters:
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.
description: AWS region to use. Defaults to AWS_DEFAULT_REGION environment variable.
type: string
default: ${AWS_DEFAULT_REGION}
profile_name:
Expand Down Expand Up @@ -36,8 +36,10 @@ steps:
- update_task_definition_from_json:
task_definition_json: << parameters.task_definition_json >>
profile_name: << parameters.profile_name >>
region: << parameters.region >>
- when:
condition: <<parameters.deploy_scheduled_task>>
steps:
- deploy_ecs_scheduled_task:
rule_name: <<parameters.rule_name>>
region: << parameters.region >>
Loading

0 comments on commit ccaddc8

Please sign in to comment.