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

feat(codedeploy): CodeDeploy deployment construct for ECS #22455

Closed
wants to merge 4 commits into from

Conversation

cplee
Copy link
Contributor

@cplee cplee commented Oct 11, 2022

Extends #22295 by adding support for creating Deployments for ECS Deployment Groups.


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 11, 2022

@github-actions github-actions bot added p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Oct 11, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team October 11, 2022 07:26
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@cplee
Copy link
Contributor Author

cplee commented Oct 19, 2022

This PR is showing a failure in PR Linter due to the fact that the prlint tool is not paginating files in the PR. This is fixed in #22555

mergify bot pushed a commit that referenced this pull request Oct 19, 2022
Currently, the `prlint` tool lists the files on a PR to enforce new integration tests are created for `feat` changes. The tool is not using pagination for list files and is using the default of `30` files per page. This means a PR could be incorrectly flagged for missing integration tests if the test files occur after the first 30 files in the PR.

Example of this can be seen in #22455 

This PR enables pagination on the `listFiles` call to ensure the validation rules are looking at all files in the PR, not just the first 30.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@Naumel
Copy link
Contributor

Naumel commented Oct 19, 2022

Hi, the referenced PR has been merged, I'd say fix the conflicts, try again!
We'll start a review as soon as the work is no longer a draft.

And, as always, thank you for contributing!

@aws-cdk-automation aws-cdk-automation dismissed their stale review October 19, 2022 14:54

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@cplee cplee force-pushed the ecs-deployment branch 2 times, most recently from e2bc0d7 to 894f36d Compare October 19, 2022 16:56
@cplee cplee marked this pull request as ready for review October 19, 2022 18:01
@cplee
Copy link
Contributor Author

cplee commented Oct 19, 2022

@Naumel - thanks, ready for review!

Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cplee thanks for the PR! This round I've only focused on the deployment provider.

@@ -0,0 +1,116 @@
import { Logger } from '@aws-lambda-powertools/logger';
import { CodeDeploy } from '@aws-sdk/client-codedeploy';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now lets not introduce any new dependencies. I think we should be able to just use the libraries that come built in with the lambda runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It'll take a bit of time to rewrite all the tests to use the older style of mocks though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes have been completed and are ready to review.

});
// cancel deployment and rollback
try {
const resp = await codedeployClient.stopDeployment({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we first look to see if the deployment with the given deploymentId is in process? If it isn't then there is nothing to do.

If there is an in progress deployment that we stop, I think we should then track the progress of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we first look to see if the deployment with the given deploymentId is in process? If it isn't then there is nothing to do.

This can be unreliable in the event of race conditions. Better to try to stop and handle situations where there isn't a deployment in progress as a success and final event.

If there is an in progress deployment that we stop, I think we should then track the progress of that.

This is already properly handled in the is-complete.ts handler.

});
switch (event.RequestType) {
case 'Create':
case 'Update': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we create a deployment while there is one in progress? I don't think we should just create a new one on top.

Should we look for an existing deployment and if there is one:

  • throw an error to fail the stack operation?
  • start tracking that one instead of creating a new one?
  • something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CodeDeploy service will throw an error if a deployment is already in progress. I'd rather rely on the service to own enforcing this.

RequestType: string;

/**
* The physical resource id. Could be undefined for 'Create' events.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsComplete should be called with the results of the on-event right? So the physicalResourceId should never be undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I will update the comments to clarify.

*/
export interface IsCompleteResponse {
/**
* True iff the deployment is in a final state.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* True iff the deployment is in a final state.
* True if the deployment is in a final state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intended to say iff...will replace with longer version of if and only if

} catch (e) {
logger.error('Unable to determine deployment status', e as Error);
if (event.RequestType === 'Delete') {
logger.warn('Ignoring error - nothing to do', { complete: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do want to fail under certain scenarios. If there is still a deployment in process there is some error deleting it, but we make this resource as successfully deleted we might run into errors trying to delete downstream resources (can you delete a deployment group while a deployment is in process?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is asking for trouble. Raising errors from custom resources during delete events is the quickest way to get a stack into a state in which it can't be updated or rolled back cleanly and the only resort is to terminate and start over.

logger.warn('Ignoring error', e as Error);
}

return {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to return some data here in order for it to be processed by the IsComplete handler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine without it, but I'll add it anyway.

* The properties of the CodeDeploy Deployment to create
*/
interface DeploymentProperties {
description: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add docstrings for all the properties in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@corymhall corymhall self-assigned this Oct 21, 2022
cplee added a commit to cplee/aws-cdk that referenced this pull request Oct 24, 2022
@mergify mergify bot dismissed corymhall’s stale review October 24, 2022 04:56

Pull request has been modified.

@cplee
Copy link
Contributor Author

cplee commented Oct 24, 2022

@corymhall - I've addressed a few of the comments and also replied to a couple that could use more discussion. I've completed the redo of the unit tests. I'd be interested in hearing your feedback on some of the comments I made.

Thanks!

mrgrain pushed a commit to mrgrain/aws-cdk that referenced this pull request Oct 24, 2022
Currently, the `prlint` tool lists the files on a PR to enforce new integration tests are created for `feat` changes. The tool is not using pagination for list files and is using the default of `30` files per page. This means a PR could be incorrectly flagged for missing integration tests if the test files occur after the first 30 files in the PR.

Example of this can be seen in aws#22455 

This PR enables pagination on the `listFiles` call to ensure the validation rules are looking at all files in the PR, not just the first 30.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
cplee added a commit to cplee/aws-cdk that referenced this pull request Oct 24, 2022
@cplee cplee force-pushed the ecs-deployment branch 2 times, most recently from e1b3979 to 32575ad Compare October 25, 2022 05:30
@cplee cplee mentioned this pull request Oct 27, 2022
@cplee
Copy link
Contributor Author

cplee commented Oct 28, 2022

@corymhall - this PR has been rebased since #22295 was merged to main. What needs to be done with this PR?

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@corymhall corymhall removed their assignment Nov 2, 2022
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: b5002f2
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the BUILD FAILING state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Dec 19, 2022
@cplee
Copy link
Contributor Author

cplee commented Dec 27, 2022

This PR was abandoned in favor of creating a new CDK construct on Construct Hub to provide this functionality:

@cdklabs/cdk-ecs-codedeploy

declare const deploymentGroup: codeDeploy.IEcsDeploymentGroup;
declare const taskDefinition: ecs.ITaskDefinition;

new EcsDeployment({
  deploymentGroup,
  targetService: {
    taskDefinition,
    containerName: 'mycontainer',
    containerPort: 80,
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants