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(ecs): allow ECS to be used declaratively #1745

Merged
merged 2 commits into from
Feb 13, 2019
Merged

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Feb 12, 2019

Minor changes to the ECS APIs so that they can be instantiated via a declarative
template (see deCDK #1618).

Merge IContainerImage and the base ContainerImage into an abstract class
so it's now an "enum-like" class with static methods. It also improves discoverability
for all other users and more aligned with how other constructs expose union types
(e.g. lambda.Code).

Normalize the ctor of ContainerDefinition to "scope, id, props" so that it can
be instantiated as a deCDK resource.


Pull Request Checklist

  • Testing
    • Unit test added
    • CLI change?: coordinate update of integration tests with team
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
  • Title and Description
    • Change type: title prefixed with fix, feat will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

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

Minor changes to the ECS APIs so that they can be instantiated via a declarative
template (see deCDK #1618).

Merge `IContainerImage` and the base `ContainerImage` into an abstract class
so it's now an "enum-like" class with static methods. It also improves discoverability
for all other users and more aligned with how other constructs expose union types
(e.g. `lambda.Code`).

Normalize the ctor of `ContainerDefinition` to "scope, id, props" so that it can
be instantiated as a deCDK resource.
@eladb eladb requested a review from a team as a code owner February 12, 2019 14:12
packages/@aws-cdk/aws-ecs/lib/container-definition.ts Outdated Show resolved Hide resolved
this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined;

props.image.bind(this);
if (props.logging) { props.logging.bind(this); }
props.task._linkContainer(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you devise syntax to call the add()er in deCDK?


/**
* Constructs for types of container images
*/
export class ContainerImage {
export abstract class ContainerImage {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I agree with this change, nor that it is strictly necessary for deCDK. Surely you could implement some heuristics around this.

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 have an idea how we can do this (convert "add"s to prop arrays) but that's not implemented. Also, this approach doesn't rely on the fact that users call add to associate a container to the task definition, they can either use add or "new" the ContainerDefinition themselves, and it will "register" itself on the task definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regardless of deCDK, I think this is a better API because it's easier to discover the various options from the type of the options. It is also more aligned with other APIs like lambda.Code and lambda.Runtime. Any reason to insist on using an interface instead of an abstract class?

Copy link
Contributor

Choose a reason for hiding this comment

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

Interfaces give us more flexibility to make implementation choices, classes lock us into a single-inheritance model that at some point is not going to fit whatever we want to do.

I know this is wishy-washy, I don't have a hard example to convince you right now. So fine, I guess.

I also question the necessity of making this change right this instant. When are we productizing deCDK?

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 reason I need this is in order for the deCDKs prototype which I would like to release to include an ECS example.

I think standardizing on how we implement these “unions” pattern will be useful because it’s reoccurring. I understand the benefit of using interfaces and maybe that should be the pattern but I also find the discoverability when using these a bit problematic. Using a class with a bunch of static methods/properties is closer to enums in discoverability so that’s where the value is in my mind.

Perhaps we can enforce via awslint that the jsdoc will include some information about possible implementations?

@eladb eladb merged commit 2480f0f into master Feb 13, 2019
@eladb eladb deleted the benisrae/ecs-declarative branch February 13, 2019 09:37
@fulghum fulghum added the effort/small Small work item – less than a day of effort label Feb 18, 2019
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 23, 2019
@mergify
Copy link
Contributor

mergify bot commented Sep 23, 2019

Thanks so much for taking the time to contribute to the AWS CDK ❤️

We will shortly assign someone to review this pull request and help get it
merged. In the meantime, please take a minute to make sure you follow this
checklist
:

  • PR title type(scope): text
    • type: fix, feat, refactor go into CHANGELOG, chore is hidden
    • scope: name of module without aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
    • text: use all lower-case, do not end with a period, do not include issue refs
  • PR Description
    • Rationale: describe rationale of change and approach taken
    • Issues: indicate issues fixed via: fixes #xxx or closes #xxx
    • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Testing
    • Unit test added. Prefer to add a new test rather than modify existing tests
    • CLI or init templates change? Re-run/add CLI integration tests
  • Documentation
    • README: update module README to describe new features
    • API docs: public APIs must be documented. Copy from official AWS docs when possible
    • Design: for significant features, follow design process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants