diff --git a/.circleci/config.yml b/.circleci/config.yml index ad1d11f9..371f6583 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -625,6 +625,21 @@ workflows: service-name: "${AWS_RESOURCE_NAME_PREFIX_FARGATE}-service" cluster-name: "${AWS_RESOURCE_NAME_PREFIX_FARGATE}-cluster" + - aws-ecs/deploy-service-update: + name: fargate_test-update-service-skip-registration + docker-image-for-job: circleci/python:3.4.9 + requires: + - fargate_test-update-service-job + aws-access-key-id: "${AWS_ACCESS_KEY_ID}" + aws-region: "${AWS_DEFAULT_REGION}" + family: "${AWS_RESOURCE_NAME_PREFIX_FARGATE}-service" + cluster-name: "${AWS_RESOURCE_NAME_PREFIX_FARGATE}-cluster" + # test skipping registration of a new task definition + skip-task-definition-registration: true + verify-revision-is-deployed: true + max-poll-attempts: 40 + poll-interval: 10 + - aws-ecs/deploy-service-update: name: codedeploy_fargate_test-update-service-job docker-image-for-job: circleci/python:3.4.9 @@ -666,7 +681,7 @@ workflows: - tear-down-test-env: name: fargate_tear-down-test-env requires: - - fargate_test-update-service-job + - fargate_test-update-service-skip-registration aws-resource-name-prefix: ${AWS_RESOURCE_NAME_PREFIX_FARGATE} terraform-config-dir: "tests/terraform_setup/fargate" diff --git a/dev-docs/README.md b/dev-docs/README.md index 799d64af..029ea8c8 100644 --- a/dev-docs/README.md +++ b/dev-docs/README.md @@ -12,15 +12,74 @@ The following [project environment variables](https://circleci.com/docs/2.0/env- | -------------------------------| --------------------------------------| | `AWS_ACCESS_KEY_ID` | Picked up by the AWS CLI | | `AWS_SECRET_ACCESS_KEY` | Picked up by the AWS CLI | -| `AWS_DEFAULT_REGION` | Picked up by the AWS CLI | +| `AWS_DEFAULT_REGION` | Picked up by the AWS CLI. Set to `us-east-1`. | | `AWS_ACCOUNT_ID` | AWS account id | | `CIRCLECI_API_KEY` | Used by the `queue` orb | -| `AWS_RESOURCE_NAME_PREFIX_EC2` | Prefix used to name AWS resources for EC2 launch type integration tests | -| `AWS_RESOURCE_NAME_PREFIX_FARGATE` | Prefix used to name AWS resources for Fargate launch type integration tests | -| `AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE` | Prefix used to name AWS resources for Fargate launch type integration tests that use CodeDeploy | +| `AWS_RESOURCE_NAME_PREFIX_EC2` | Prefix used to name AWS resources for EC2 launch type integration tests. Set to `ecs-orb-ec2-1`. | +| `AWS_RESOURCE_NAME_PREFIX_FARGATE` | Prefix used to name AWS resources for Fargate launch type integration tests. Set to `ecs-orb-fg-1`. | +| `AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE` | Prefix used to name AWS resources for Fargate launch type integration tests that use CodeDeploy. Set to `ecs-orb-cdfg-1`. | | `SKIP_TEST_ENV_CREATION` | Whether to skip test env setup | | `SKIP_TEST_ENV_TEARDOWN` | Whether to skip test env teardown | +## Setting up / tearing down test infra locally + +You can also set up the same test infrastructure set up by the build pipeline, +by running terraform locally. + +This is also useful when you need to tear down infra manually after the pipeline failed. (For the ec2 and fargate tests, you can also tear down the infrastructure by going to the CloudFormation page on the AWS console and deleting the stacks prefixed with `ecs-orb`) + +Set up AWS credentials and `AWS_DEFAULT_REGION`: + +``` +AWS_ACCESS_KEY_ID=... +AWS_SECRET_ACCESS_KEY=... +AWS_ACCOUNT_ID=... +AWS_DEFAULT_REGION=us-east-1 +``` + +Then set `AWS_RESOURCE_PREFIX` to the correct value: + +*For EC2 tests* + +``` +AWS_RESOURCE_PREFIX=ecs-orb-ec2-1 +cd tests/terraform_setup/ec2 +``` + +*For Fargate tests* + +``` +AWS_RESOURCE_PREFIX=ecs-orb-fg-1 +cd tests/terraform_setup/fargate +``` + +*For CodeDeploy tests* + +``` +AWS_RESOURCE_PREFIX=ecs-orb-cdfg-1 +cd tests/terraform_setup/fargate_codedeploy +``` + +### Infra setup/teardown steps (for all) + +``` +terraform apply \ + -var "aws_access_key=${AWS_ACCESS_KEY_ID}" \ + -var "aws_secret_key=${AWS_SECRET_ACCESS_KEY}" \ + -var "aws_region=${AWS_DEFAULT_REGION}" \ + -var "aws_account_id=${AWS_ACCOUNT_ID}" \ + -var "aws_resource_prefix=${AWS_RESOURCE_PREFIX}" +``` + +``` +terraform destroy \ + -var "aws_access_key=${AWS_ACCESS_KEY_ID}" \ + -var "aws_secret_key=${AWS_SECRET_ACCESS_KEY}" \ + -var "aws_region=${AWS_DEFAULT_REGION}" \ + -var "aws_account_id=${AWS_ACCOUNT_ID}" \ + -var "aws_resource_prefix=${AWS_RESOURCE_PREFIX}" +``` + ### Required Context and Context Environment Variables The `orb-publishing` context is referenced in the build. In particular, the following [context environment variables](https://circleci.com/docs/2.0/env-vars/#setting-an-environment-variable-in-a-context) must be set in the `orb-publishing` context, before the project can be built successfully. diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 56c3d753..3eed55d7 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -295,6 +295,11 @@ jobs: Only in use when verify-revision-is-deployed is set to true. type: boolean default: true + skip-task-definition-registration: + description: | + Whether to skip registration of a new task definition. + type: boolean + default: false steps: - aws-cli/install - aws-cli/configure: @@ -317,6 +322,7 @@ jobs: max-poll-attempts: << parameters.max-poll-attempts >> poll-interval: << parameters.poll-interval >> fail-on-verification-timeout: << parameters.fail-on-verification-timeout >> + skip-task-definition-registration: << parameters.skip-task-definition-registration >> update-task-definition: docker: - image: << parameters.docker-image-for-job >> @@ -929,11 +935,30 @@ commands: Only in use when verify-revision-is-deployed is set to true. type: boolean default: true + skip-task-definition-registration: + description: | + Whether to skip registration of a new task definition. + type: boolean + default: false steps: - - update-task-definition: - family: << parameters.family >> - container-image-name-updates: << parameters.container-image-name-updates >> - container-env-var-updates: << parameters.container-env-var-updates >> + - unless: + condition: << parameters.skip-task-definition-registration >> + steps: + - update-task-definition: + family: << parameters.family >> + container-image-name-updates: << parameters.container-image-name-updates >> + container-env-var-updates: << parameters.container-env-var-updates >> + - when: + condition: << parameters.skip-task-definition-registration >> + steps: + - run: + name: Retrieve previous task definition + command: | + TASK_DEFINITION_ARN=$(aws ecs describe-task-definition \ + --task-definition << parameters.family >> \ + --output text \ + --query 'taskDefinition.taskDefinitionArn') + echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV - run: name: Update service with registered task definition command: |