Skip to content

Commit

Permalink
Merge pull request #88 from Xheno/pr-85
Browse files Browse the repository at this point in the history
Set an optional parameter on whether to run update-task-definition in update-service.
  • Loading branch information
lokst authored Jun 4, 2020
2 parents 585892f + d4c06d6 commit 5e26c58
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 9 deletions.
17 changes: 16 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down
67 changes: 63 additions & 4 deletions dev-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 29 additions & 4 deletions src/orb.yml.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 >>
Expand Down Expand Up @@ -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: |
Expand Down

0 comments on commit 5e26c58

Please sign in to comment.