From ccaddc87579ee5a78d016ebe11cf8fc7d81fd90a Mon Sep 17 00:00:00 2001 From: marboledacci Date: Wed, 2 Oct 2024 11:17:55 -0500 Subject: [PATCH] Feature: job parameter region for all the commands and jobs (#224) * 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 --- .circleci/test-deploy.yml | 6 ++++-- src/commands/deploy_ecs_scheduled_task.yml | 5 +++++ src/commands/run_task.yml | 5 +++++ src/commands/update_service.yml | 7 ++++++- src/commands/update_task_definition.yml | 6 ++++++ src/commands/update_task_definition_from_json.yml | 5 +++++ src/commands/verify_revision_is_deployed.yml | 5 +++++ src/examples/deploy_ecs_scheduled_task.yml | 8 +++++--- src/examples/deploy_service_update.yml | 7 ++++--- src/examples/run_task_ec2.yml | 5 +++-- src/examples/run_task_fargate.yml | 3 ++- src/examples/run_task_fargate_spot.yml | 3 ++- src/examples/update_service.yml | 5 +++-- src/examples/update_task_definition_from_json.yml | 5 +++-- src/examples/verify_revision_deployment.yml | 5 +++-- src/jobs/deploy_service_update.yml | 2 +- src/jobs/run_task.yml | 3 ++- src/jobs/update_task_definition.yml | 4 +++- src/jobs/update_task_definition_from_json.yml | 4 +++- src/scripts/deploy_ecs_scheduled_task.sh | 6 +++--- src/scripts/get_prev_task.sh | 3 ++- src/scripts/register_new_task_def.sh | 2 ++ src/scripts/run_task.sh | 5 +++-- src/scripts/update_bluegreen_service_via_task_def.sh | 6 ++++-- src/scripts/update_service_via_task_def.sh | 2 ++ src/scripts/update_task_definition_from_json.sh | 2 ++ src/scripts/verify_revision_is_deployed.sh | 7 ++++--- 27 files changed, 92 insertions(+), 34 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 8540effa..f41ca1ac 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -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}" @@ -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}" @@ -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 diff --git a/src/commands/deploy_ecs_scheduled_task.yml b/src/commands/deploy_ecs_scheduled_task.yml index 8883c195..8b6425d5 100644 --- a/src/commands/deploy_ecs_scheduled_task.yml +++ b/src/commands/deploy_ecs_scheduled_task.yml @@ -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: <> + ORB_AWS_REGION: << parameters.region >> command: <> diff --git a/src/commands/run_task.yml b/src/commands/run_task.yml index 6e4dedf8..8e1e4dec 100755 --- a/src/commands/run_task.yml +++ b/src/commands/run_task.yml @@ -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 @@ -140,6 +144,7 @@ steps: ORB_STR_PLATFORM_VERSION: <> ORB_BOOL_AWSVPC: <> ORB_STR_SUBNET_ID: <> + ORB_AWS_REGION: << parameters.region >> ORB_STR_SEC_GROUP_ID: <> ORB_STR_ASSIGN_PUB_IP: <> ORB_STR_OVERRIDES: <> diff --git a/src/commands/update_service.yml b/src/commands/update_service.yml index 1ccf54e1..f8ea1b2c 100644 --- a/src/commands/update_service.yml +++ b/src/commands/update_service.yml @@ -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: @@ -222,7 +223,8 @@ steps: aws ecs tag-resource \ --resource-arn ${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN} \ --tags <> \ - --profile=<< parameters.profile_name >> + --profile=<< parameters.profile_name >> \ + --region << parameters.region >> - when: condition: equal: @@ -241,6 +243,7 @@ steps: ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT: <> ORB_BOOL_VERIFY_REV_DEPLOY: <> ORB_STR_PROFILE_NAME: <> + ORB_AWS_REGION: << parameters.region >> ORB_BOOL_ENABLE_CIRCUIT_BREAKER: <> ORB_STR_CD_CAPACITY_PROVIDER_NAME: <> ORB_STR_CD_CAPACITY_PROVIDER_WEIGHT: <> @@ -261,6 +264,7 @@ steps: ORB_STR_FAMILY: <> ORB_BOOL_FORCE_NEW_DEPLOY: <> ORB_STR_CLUSTER_NAME: <> + ORB_AWS_REGION: << parameters.region >> ORB_STR_PROFILE_NAME: <> ORB_BOOL_ENABLE_CIRCUIT_BREAKER: <> @@ -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 >> diff --git a/src/commands/update_task_definition.yml b/src/commands/update_task_definition.yml index 294156cc..8d745208 100644 --- a/src/commands/update_task_definition.yml +++ b/src/commands/update_task_definition.yml @@ -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 @@ -76,6 +80,7 @@ steps: ORB_SCRIPT_GET_TASK_DFN_VAL: <> ORB_STR_PROFILE_NAME: <> ORB_STR_PREVIOUS_REVISION_NUMBER: <> + ORB_AWS_REGION: << parameters.region >> ORB_STR_CONTAINER_SECRET_UPDATES: <> ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES: << parameters.container_docker_label_updates >> - run: @@ -84,3 +89,4 @@ steps: environment: ORB_STR_FAMILY: <> ORB_STR_PROFILE_NAME: <> + ORB_AWS_REGION: << parameters.region >> diff --git a/src/commands/update_task_definition_from_json.yml b/src/commands/update_task_definition_from_json.yml index 8dd775cc..fbaa8dcb 100644 --- a/src/commands/update_task_definition_from_json.yml +++ b/src/commands/update_task_definition_from_json.yml @@ -8,6 +8,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: Register new task definition @@ -15,3 +19,4 @@ steps: environment: ORB_STR_TASK_DEFINITION_JSON: <> ORB_STR_PROFILE_NAME: <> + ORB_AWS_REGION: << parameters.region >> diff --git a/src/commands/verify_revision_is_deployed.yml b/src/commands/verify_revision_is_deployed.yml index 1a447454..f1418635 100644 --- a/src/commands/verify_revision_is_deployed.yml +++ b/src/commands/verify_revision_is_deployed.yml @@ -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 @@ -46,6 +50,7 @@ steps: ORB_STR_TASK_DEF_ARN: <> ORB_VAL_MAX_POLL_ATTEMPTS: <> ORB_STR_CLUSTER_NAME: <> + ORB_AWS_REGION: << parameters.region >> ORB_VAL_POLL_INTERVAL: <> ORB_VAL_FAIL_ON_VERIFY_TIMEOUT: <> ORB_STR_PROFILE_NAME: <> diff --git a/src/examples/deploy_ecs_scheduled_task.yml b/src/examples/deploy_ecs_scheduled_task.yml index 3c1c7d9e..2b0f46fb 100644 --- a/src/examples/deploy_ecs_scheduled_task.yml +++ b/src/examples/deploy_ecs_scheduled_task.yml @@ -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: @@ -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: diff --git a/src/examples/deploy_service_update.yml b/src/examples/deploy_service_update.yml index 9bd0f148..b5d607f5 100644 --- a/src/examples/deploy_service_update.yml +++ b/src/examples/deploy_service_update.yml @@ -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: @@ -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' diff --git a/src/examples/run_task_ec2.yml b/src/examples/run_task_ec2.yml index 0dd573b1..918f021f 100644 --- a/src/examples/run_task_ec2.yml +++ b/src/examples/run_task_ec2.yml @@ -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: @@ -15,6 +15,7 @@ usage: - aws-ecs/run_task: cluster: cluster1 task_definition: myapp + region: us-east-1 awsvpc: false launch_type: EC2 workflows: diff --git a/src/examples/run_task_fargate.yml b/src/examples/run_task_fargate.yml index c3e74036..b5b54069 100644 --- a/src/examples/run_task_fargate.yml +++ b/src/examples/run_task_fargate.yml @@ -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: @@ -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 diff --git a/src/examples/run_task_fargate_spot.yml b/src/examples/run_task_fargate_spot.yml index efeac459..c0ab01fb 100644 --- a/src/examples/run_task_fargate_spot.yml +++ b/src/examples/run_task_fargate_spot.yml @@ -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: @@ -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 diff --git a/src/examples/update_service.yml b/src/examples/update_service.yml index 74064569..3b0c2908 100644 --- a/src/examples/update_service.yml +++ b/src/examples/update_service.yml @@ -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: @@ -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: diff --git a/src/examples/update_task_definition_from_json.yml b/src/examples/update_task_definition_from_json.yml index 5e36ff3c..5307473c 100644 --- a/src/examples/update_task_definition_from_json.yml +++ b/src/examples/update_task_definition_from_json.yml @@ -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: @@ -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: diff --git a/src/examples/verify_revision_deployment.yml b/src/examples/verify_revision_deployment.yml index 58a12dd9..06b540ea 100644 --- a/src/examples/verify_revision_deployment.yml +++ b/src/examples/verify_revision_deployment.yml @@ -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: @@ -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: diff --git a/src/jobs/deploy_service_update.yml b/src/jobs/deploy_service_update.yml index 9c00520c..7c5832c2 100644 --- a/src/jobs/deploy_service_update.yml +++ b/src/jobs/deploy_service_update.yml @@ -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: diff --git a/src/jobs/run_task.yml b/src/jobs/run_task.yml index 807b1585..00963249 100755 --- a/src/jobs/run_task.yml +++ b/src/jobs/run_task.yml @@ -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: @@ -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 >> diff --git a/src/jobs/update_task_definition.yml b/src/jobs/update_task_definition.yml index 7d4d6956..6c1feea6 100644 --- a/src/jobs/update_task_definition.yml +++ b/src/jobs/update_task_definition.yml @@ -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: @@ -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 >> @@ -106,3 +107,4 @@ steps: steps: - deploy_ecs_scheduled_task: rule_name: <> + region: << parameters.region >> diff --git a/src/jobs/update_task_definition_from_json.yml b/src/jobs/update_task_definition_from_json.yml index 70053997..b88f6a40 100644 --- a/src/jobs/update_task_definition_from_json.yml +++ b/src/jobs/update_task_definition_from_json.yml @@ -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: @@ -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: <> steps: - deploy_ecs_scheduled_task: rule_name: <> + region: << parameters.region >> diff --git a/src/scripts/deploy_ecs_scheduled_task.sh b/src/scripts/deploy_ecs_scheduled_task.sh index fc0a9461..c969b9e9 100644 --- a/src/scripts/deploy_ecs_scheduled_task.sh +++ b/src/scripts/deploy_ecs_scheduled_task.sh @@ -1,6 +1,6 @@ #!/bin/bash td_arn=$CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN - +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -z "$td_arn" ]; then echo "Updated task definition not found. Please run update-task-definition command before deploy-ecs-scheduled-task" exit 1 @@ -16,7 +16,7 @@ fi CLI_OUTPUT_FILE=$(mktemp cli-output.json.XXXX) CLI_INPUT_FILE=$(mktemp cli-input.json.XXXX) -aws events list-targets-by-rule --rule "$ORB_STR_RULE_NAME" --output json > "$CLI_OUTPUT_FILE" +aws events list-targets-by-rule --rule "$ORB_STR_RULE_NAME" --output json --region "$ORB_AWS_REGION" > "$CLI_OUTPUT_FILE" if < "$CLI_OUTPUT_FILE" jq ' .Targets[] | has("EcsParameters")' | grep "false"; then echo "Invalid ECS Rule. $ORB_STR_RULE_NAME does not contain EcsParameters key. Please create a valid ECS Rule and try again" @@ -24,4 +24,4 @@ if < "$CLI_OUTPUT_FILE" jq ' .Targets[] | has("EcsParameters")' | grep "false"; fi < "$CLI_OUTPUT_FILE" jq --arg td_arn "$td_arn" '.Targets[].EcsParameters.TaskDefinitionArn |= $td_arn' > "$CLI_INPUT_FILE" -aws events put-targets --rule "$ORB_STR_RULE_NAME" --cli-input-json "$(cat "$CLI_INPUT_FILE")" +aws events put-targets --rule "$ORB_STR_RULE_NAME" --cli-input-json "$(cat "$CLI_INPUT_FILE")" --region "$ORB_AWS_REGION" diff --git a/src/scripts/get_prev_task.sh b/src/scripts/get_prev_task.sh index a3ec9842..7a90a93f 100644 --- a/src/scripts/get_prev_task.sh +++ b/src/scripts/get_prev_task.sh @@ -9,6 +9,7 @@ ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_STR_CONTAINER_SECRET_UPDATES="$(circleci env subst "$ORB_STR_CONTAINER_SECRET_UPDATES")" ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES="$(circleci env subst "$ORB_STR_CONTAINER_DOCKER_LABEL_UPDATES")" ORB_STR_PREVIOUS_REVISION_NUMBER="$(circleci env subst "$ORB_STR_PREVIOUS_REVISION_NUMBER")" +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -z "${ECS_PARAM_PREVIOUS_REVISION}" ]; then ECS_TASK_DEFINITION_NAME="$ORB_STR_FAMILY" @@ -17,7 +18,7 @@ else fi # shellcheck disable=SC2034 -PREVIOUS_TASK_DEFINITION="$(aws ecs describe-task-definition --task-definition "${ECS_TASK_DEFINITION_NAME}" --include TAGS --profile "${ORB_STR_PROFILE_NAME}" --region "${AWS_DEFAULT_REGION}" "$@")" +PREVIOUS_TASK_DEFINITION="$(aws ecs describe-task-definition --task-definition "${ECS_TASK_DEFINITION_NAME}" --include TAGS --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_AWS_REGION}" "$@")" # Prepare script for updating container definitions diff --git a/src/scripts/register_new_task_def.sh b/src/scripts/register_new_task_def.sh index 112963c7..894d5050 100644 --- a/src/scripts/register_new_task_def.sh +++ b/src/scripts/register_new_task_def.sh @@ -4,6 +4,7 @@ set -o noglob # These variables are evaluated so the config file may contain and pass in environment variables to the parameters. ORB_STR_FAMILY="$(circleci env subst "$ORB_STR_FAMILY")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -n "${CCI_ORB_AWS_ECS_TASK_ROLE}" ]; then set -- "$@" --task-role-arn "${CCI_ORB_AWS_ECS_TASK_ROLE}" @@ -69,6 +70,7 @@ REVISION=$(aws ecs register-task-definition \ --profile "${ORB_STR_PROFILE_NAME}" \ "$@" \ --output text \ + --region "${ORB_AWS_REGION}" \ --query 'taskDefinition.taskDefinitionArn') echo "Registered task definition: ${REVISION}" diff --git a/src/scripts/run_task.sh b/src/scripts/run_task.sh index 2de66d41..5d90828d 100644 --- a/src/scripts/run_task.sh +++ b/src/scripts/run_task.sh @@ -13,6 +13,7 @@ ORB_STR_CD_CAPACITY_PROVIDER_STRATEGY="$(circleci env subst "$ORB_STR_CD_CAPACIT ORB_STR_RUN_TASK_OUTPUT="$(circleci env subst "$ORB_STR_RUN_TASK_OUTPUT")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_STR_ASSIGN_PUB_IP="$(circleci env subst "$ORB_STR_ASSIGN_PUB_IP")" +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [[ "$ORB_STR_OVERRIDES" == *"\${"* ]]; then ORB_STR_OVERRIDES="$(echo "${ORB_STR_OVERRIDES}" | circleci env subst)" @@ -99,10 +100,10 @@ set -- "$@" --cluster "$ORB_STR_CLUSTER_NAME" if [ -n "${ORB_STR_RUN_TASK_OUTPUT}" ]; then set -x - aws ecs run-task --profile "${ORB_STR_PROFILE_NAME}" "$@" | tee "${ORB_STR_RUN_TASK_OUTPUT}" + aws ecs run-task --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_AWS_REGION}" "$@" | tee "${ORB_STR_RUN_TASK_OUTPUT}" set +x else set -x - aws ecs run-task --profile "${ORB_STR_PROFILE_NAME}" "$@" + aws ecs run-task --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_AWS_REGION}" "$@" set +x fi diff --git a/src/scripts/update_bluegreen_service_via_task_def.sh b/src/scripts/update_bluegreen_service_via_task_def.sh index c6d85e5f..2230ec63 100644 --- a/src/scripts/update_bluegreen_service_via_task_def.sh +++ b/src/scripts/update_bluegreen_service_via_task_def.sh @@ -10,6 +10,7 @@ ORB_STR_CD_CAPACITY_PROVIDER_BASE="$(circleci env subst "$ORB_STR_CD_CAPACITY_PR ORB_STR_CD_DEPLOYMENT_CONFIG_NAME="$(circleci env subst "$ORB_STR_CD_DEPLOYMENT_CONFIG_NAME")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT="$(circleci env subst "$ORB_INT_CD_LOAD_BALANCED_CONTAINER_PORT")" +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" DEPLOYED_REVISION="${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" @@ -39,6 +40,7 @@ DEPLOYMENT_ID=$(aws deploy create-deployment \ --profile "$ORB_STR_PROFILE_NAME" \ --query deploymentId \ --revision "${REVISION}" \ + --region "${ORB_AWS_REGION}" \ "$@" \ --output text) @@ -46,11 +48,11 @@ echo "Created CodeDeploy deployment: $DEPLOYMENT_ID" if [ "$ORB_BOOL_VERIFY_REV_DEPLOY" == "1" ]; then echo "Waiting for deployment to succeed." - if aws deploy wait deployment-successful --deployment-id "${DEPLOYMENT_ID}" --profile "${ORB_STR_PROFILE_NAME}"; then + if aws deploy wait deployment-successful --deployment-id "${DEPLOYMENT_ID}" --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_AWS_REGION}"; then echo "Deployment succeeded." elif [ "$ORB_BOOL_ENABLE_CIRCUIT_BREAKER" == "1" ]; then echo "Deployment failed. Rolling back." - aws deploy stop-deployment --deployment-id "${DEPLOYMENT_ID}" --auto-rollback-enabled --profile "${ORB_STR_PROFILE_NAME}" + aws deploy stop-deployment --deployment-id "${DEPLOYMENT_ID}" --auto-rollback-enabled --profile "${ORB_STR_PROFILE_NAME}" --region "${ORB_AWS_REGION}" else echo "Deployment failed. Exiting." exit 1 diff --git a/src/scripts/update_service_via_task_def.sh b/src/scripts/update_service_via_task_def.sh index 55d00091..8f7eb3f3 100644 --- a/src/scripts/update_service_via_task_def.sh +++ b/src/scripts/update_service_via_task_def.sh @@ -6,6 +6,7 @@ ORB_STR_FAMILY="$(circleci env subst "$ORB_STR_FAMILY")" ORB_STR_CLUSTER_NAME="$(circleci env subst "$ORB_STR_CLUSTER_NAME")" ORB_STR_SERVICE_NAME="$(circleci env subst "$ORB_STR_SERVICE_NAME")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ -z "${ORB_STR_SERVICE_NAME}" ]; then ORB_STR_SERVICE_NAME="$ORB_STR_FAMILY" @@ -25,6 +26,7 @@ DEPLOYED_REVISION=$(aws ecs update-service \ --service "${ORB_STR_SERVICE_NAME}" \ --task-definition "${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" \ --output text \ + --region "${ORB_AWS_REGION}" \ --query service.taskDefinition \ "$@") echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> "$BASH_ENV" diff --git a/src/scripts/update_task_definition_from_json.sh b/src/scripts/update_task_definition_from_json.sh index 8d2f1481..5ade8e20 100644 --- a/src/scripts/update_task_definition_from_json.sh +++ b/src/scripts/update_task_definition_from_json.sh @@ -1,6 +1,7 @@ #!/bin/bash ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" ORB_STR_TASK_DEFINITION_JSON="$(circleci env subst "$ORB_STR_TASK_DEFINITION_JSON")" +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ "${ORB_STR_TASK_DEFINITION_JSON:0:1}" != "/" ]; then ORB_STR_TASK_DEFINITION_JSON="$(pwd)/${ORB_STR_TASK_DEFINITION_JSON}" @@ -10,6 +11,7 @@ REVISION=$(aws ecs register-task-definition \ --profile "${ORB_STR_PROFILE_NAME}" \ --cli-input-json file://"${ORB_STR_TASK_DEFINITION_JSON}" \ --output text \ + --region "${ORB_AWS_REGION}" \ --query 'taskDefinition.taskDefinitionArn' \ "$@") echo "Registered task definition: ${REVISION}" diff --git a/src/scripts/verify_revision_is_deployed.sh b/src/scripts/verify_revision_is_deployed.sh index fe3082d8..8ac9b326 100644 --- a/src/scripts/verify_revision_is_deployed.sh +++ b/src/scripts/verify_revision_is_deployed.sh @@ -5,6 +5,7 @@ ORB_STR_SERVICE_NAME="$(circleci env subst "$ORB_STR_SERVICE_NAME")" ORB_STR_CLUSTER_NAME="$(circleci env subst "$ORB_STR_CLUSTER_NAME")" ORB_STR_TASK_DEF_ARN="$(circleci env subst "$ORB_STR_TASK_DEF_ARN")" ORB_STR_PROFILE_NAME="$(circleci env subst "$ORB_STR_PROFILE_NAME")" +ORB_AWS_REGION="$(circleci env subst "$ORB_AWS_REGION")" if [ "$ORB_STR_TASK_DEF_ARN" = "" ]; then echo "Invalid task-definition-arn parameter value: $ORB_STR_TASK_DEF_ARN" @@ -27,7 +28,7 @@ do --profile "${ORB_STR_PROFILE_NAME}" \ --cluster "$ORB_STR_CLUSTER_NAME" \ --services "${ORB_STR_SERVICE_NAME}" \ - --region "${AWS_DEFAULT_REGION}" \ + --region "${ORB_AWS_REGION}" \ --output text \ --query 'services[0].deployments[].[taskDefinition, status]' \ "$@") @@ -35,7 +36,7 @@ do --profile "${ORB_STR_PROFILE_NAME}" \ --cluster "$ORB_STR_CLUSTER_NAME" \ --services "${ORB_STR_SERVICE_NAME}" \ - --region "${AWS_DEFAULT_REGION}" \ + --region "${ORB_AWS_REGION}" \ --output text \ --query 'length(services[0].deployments)' \ "$@") @@ -43,7 +44,7 @@ do --profile "${ORB_STR_PROFILE_NAME}" \ --cluster "$ORB_STR_CLUSTER_NAME" \ --services "${ORB_STR_SERVICE_NAME}" \ - --region "${AWS_DEFAULT_REGION}" \ + --region "${ORB_AWS_REGION}" \ --output text \ --query "services[0].deployments[?taskDefinition==\`$ORB_STR_TASK_DEF_ARN\` && runningCount == desiredCount && (status == \`PRIMARY\` || status == \`ACTIVE\`)][taskDefinition]" \ "$@")