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): Add RepositoryCredentials support #1

Closed
wants to merge 4 commits into from

Conversation

allisaurus
Copy link
Owner

@allisaurus allisaurus commented Mar 1, 2019

Implements #1737


Pull Request Checklist

  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
    • 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.

@allisaurus
Copy link
Owner Author

@SoManyHs & @rix0rrr - posting this for initial feedback. Suggested changes welcome. Thanks!

@rix0rrr
Copy link

rix0rrr commented Mar 1, 2019

Feel free to just post these PRs directly to the aws-cdk repository. It's actually easier for me to go over them there.

@@ -183,8 +183,8 @@ const taskDefinition = new ecs.TaskDefinition(this, 'TaskDef', {
Images supply the software that runs inside the container. Images can be
obtained from either DockerHub or from ECR repositories, or built directly from a local Dockerfile.

* `ecs.ContainerImage.fromDockerHub(imageName)`: use a publicly available image from
DockerHub.
* `ecs.ContainerImage.fromInternet(imageName, { credentials?: MY_SECRET })`: use a public or private image from
Copy link

Choose a reason for hiding this comment

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

I wouldn't write it like this, this isn't copy/pasteable user code. Just add a new line below to do something like:

ecs.ContainerImage.fromInternet(imageName, { credentials: mySecret }): use a private image that needs credentials.

/**
* Repository Credential resources
*/
export interface RepositoryCreds {
Copy link

Choose a reason for hiding this comment

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

What are your thoughts for this type? Future proofing? Because it's not strictly necessary today, right?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Correct, today we could potentially add a secret to ContainerImage directly but I want to minimize the need for rewiring if other resources or additional fields become valid in the future. Do you foresee issues with this approach?

/**
* Optional credentials for a private image registry
*/
public abstract readonly credentials?: RepositoryCreds;
Copy link

Choose a reason for hiding this comment

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

Does this need to be publicly accessible? Seems like renderRepositoryCredentials() is all that a consumer of this class should need from it, right?

Copy link
Owner Author

Choose a reason for hiding this comment

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

renderContainerDefinition() needs to see it to determine whether or not to call renderRepositoryCredentials(). ECS will fail to register the task definition if RepositoryCredentials is present but empty.

*/
public renderRepositoryCredentials(): CfnTaskDefinition.RepositoryCredentialsProperty {
return {
credentialsParameter: this.credentials ? this.credentials.secret.secretArn : ''
Copy link

Choose a reason for hiding this comment

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

To avoid breaking all existing integration tests, maybe return undefined for this whole object if we don't have credentials?

public renderRepositoryCredentials(): CfnTaskDefinition.RepositoryCredentialsProperty  | undefined {
  if (!this.credentials) { return undefined; }
  return {
    credentialsParameter: this.credentials.secret.secretArn
  } ;
}

Copy link

Choose a reason for hiding this comment

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

And in fact, this method could be abstract here and only be implemented in InternetHostedImage, since that's the only image type that actually has any credentials at all.

Copy link

Choose a reason for hiding this comment

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

Well the others would need to do a base implementation of undefined as well.

Copy link
Owner Author

Choose a reason for hiding this comment

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

To avoid breaking all existing integration tests...

Ah, the conditional here can probably be removed b/c this func should only be called if credentials is populated. See renderContainerDefinition(). Currently, the existing integ tests all pass.

...this method could be abstract here and be implemented in InternetHostedImage...

I tried returning undefined from this method before (as you show) and got yelled at by the compiler b/c it wasn't a return value of type RepositoryCredentialsProperty. So since I have to return a RepositoryCredentialsProperty obj regardless, I'd prefer to consolidate it into one func on ContainerImage. Is there a way around having to return an RepositoryCredentialsProperty in some cases?

Copy link

Choose a reason for hiding this comment

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

got yelled at by the compiler

It's hard to see the change in the code I pasted because it scrolls off the side of the comment box, but you should have written the return type as:

CfnTaskDefinition.RepositoryCredentialsProperty  | undefined

That would have allowed you to return undefined.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah, I totally missed that, thanks for pointing it out! In that case I'll update it per the above.

@rix0rrr
Copy link

rix0rrr commented Mar 4, 2019

BTW, is it still possible to merge this PR into aws#1737 ?

@allisaurus
Copy link
Owner Author

@rix0rrr sure! I'll address the above feedback and add it to awslabs#1737

@allisaurus
Copy link
Owner Author

was merged as aws#1737

@allisaurus allisaurus closed this Mar 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants