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

fix(codepipeline): cannot trigger on all tags anymore in EcrSourceAction #17270

Merged
merged 10 commits into from
Nov 25, 2021
Merged

fix(codepipeline): cannot trigger on all tags anymore in EcrSourceAction #17270

merged 10 commits into from
Nov 25, 2021

Conversation

sparten11740
Copy link
Contributor

@sparten11740 sparten11740 commented Nov 2, 2021

The EcrSourceAction could previously be used to trigger on changes to all tags of an image. As part of the fix #13818, the imageTag was defaulted to latest if not provided. Therefore it was no longer possible to call the underlying onCloudTrailImagePushed function with an undefined imageTag to watch changes on all tags.

Reintroduce triggering on all tags by passing an empty string as the imageTag.

Fixes #13818


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

…to EcrSourceAction

The EcrSourceAction could previously be used to trigger on changes to all tags of an image. As part of the fix #13818, the imageTag was defaulted to latest if not provided. Therefore it was no longer possible to call the underlying onCloudTrailImagePushed function with an undefined imageTag to watch changes on all tags.

Reintroduce triggering on all tags by passing an empty string as the imageTag.

Fixes #13818
@gitpod-io
Copy link

gitpod-io bot commented Nov 2, 2021

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

@sparten11740 thank you for the contribution, but I have to say, I'm having second thoughts on whether this change even makes sense 😜.

The CodePipeline documentation states:

ImageTag
Required: No

The tag used for the image.

Note
If a value for ImageTag is not specified, the value defaults to latest.

If that is true, then specifying '' here would trigger on a push to every tag, yes. But the image downloaded would always be for the 'latest' tag anyway! If that's the case, what's the point of triggering a deploy for a different tag, if it won't be used anyway, and 'latest' will be used (so basically, a no-op deployment)?

Can you elaborate on your usecase a little bit?

@sparten11740
Copy link
Contributor Author

@skinny85

You’re assuming that latest is used as a tag, which I’d like to avoid.

From my understanding the EcrSourceAction does not download any images but only provides metadata (as artifact or output variables) to the successor steps. When watching changes on latest, imageTag in the output variables will always be forwarded as latest. This is pretty much useless when deploying an image to a Fargate ECS cluster as infrastructure deployment. As a workaround we have to user either the imageDigest (or the imageUri which is also possible since it is a digest- and not tag-based image URI) to update the container image in our stack.

There are two minor disadvantages with this approach. First, looking at the container definition in the ECS console to find out what’s deployed, we’d always have to go to ECR first to see what image is actually hiding behind the image url (whereas if we used the e.g. commit hash or something else meaningful as dynamic tag this wouldn’t be the case). Second, creating a container image from a digest just feels a little clumsy.

Of course this works and is not a big deal, but I’d much rather not be forced to use the latest tag at all. Does that make sense?

@skinny85
Copy link
Contributor

skinny85 commented Nov 3, 2021

I mostly understand, but I have a few follow-up questions 🙂.

So, the ECR source Action produces a file with a bunch of metadata about the image. Among them is tag, imageDigest, and imageUri. You don't want to use tag. First question - can you expand on why don't you want to use tag? Is it because the tag needs to be the same for all Pipeline invocations, and you want to use different tags?

Second question. If we make the CloudWatch event react to every tag, like we do in this PR, does this mean that the metadata produced by the ECR source Action will be for whatever image was pushed that caused that Event to fire? So, even if the tag in the source Action will be undefined, which implies latest, you're saying here that if you push a different tag to the repository, the CloudWatch event will fire, and that will make the ECR source Action produce the imageDigest and imageUri of the just pushed image, instead of latest?

Third question: you wrote:

As a workaround we have to user either the imageDigest (or the imageUri which is also possible since it is a digest- and not tag-based image URI) to update the container image in our stack.

Can you explain how are you achieving this?

Thanks,
Adam

@sparten11740
Copy link
Contributor Author

First question - can you expand on why don't you want to use tag? Is it because the tag needs to be the same for all Pipeline invocations, and you want to use different tags?

That's correct. I would like to use tag but can't because it needs to be the same for all invocations.

Second question. If we make the CloudWatch event react to every tag, like we do in this PR, does this mean that the metadata produced by the ECR source Action will be for whatever image was pushed that caused that Event to fire?

If we do it like in this PR, this would be the case but only if we provide '' (empty string) as imageTag to the source action. The produced metadata will then be for the image that was pushed. The behaviour when providing undefined, latest or any other specific tag, remains unchanged.

Regarding your third question: The ECRSourceAction in our pipeline triggers on latest. The stack will be synthesized with imageDigest provided as env variable. Within the stack, imageDigest is used to instantiate a container image:

const containerImage = ContainerImage.fromDockerImageAsset({
  repository,
  imageUri: repository.repositoryUriForDigest(imageDigest),
  assetHash: imageDigest,
  node: repository.node,
});

If tag could be used, this would shrink to:

ContainerImage.fromEcrRepository(repository, imageTag);

I hope this could make it a little clearer.

@skinny85
Copy link
Contributor

skinny85 commented Nov 4, 2021

OK, thanks for the answers. I feel like this is all a little bit fragile - from relying on the undocumented behavior of the ECR CodePipeline source Action with regards to ignoring the tag, and just including whatever metadata of the image was just pushed, to the way you implement a DockerImageAsset inline inside the ContainerImage.fromDockerImageAsset() call. It feels like this should all be simpler than this 😜. But kudos to you for figuring all of this out.

I don't have any more philosophical objections to this PR. Let me do another round of reviews.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks good @sparten11740, just a few minor changes!

@skinny85 skinny85 changed the title fix(codepipeline-actions): reintroduce option to trigger on all tags … fix(codepipeline): reintroduce option to trigger on all tags to EcrSourceAction Nov 4, 2021
@github-actions github-actions bot added the @aws-cdk/aws-codepipeline Related to AWS CodePipeline label Nov 4, 2021
@mergify mergify bot dismissed skinny85’s stale review November 4, 2021 21:30

Pull request has been modified.

@skinny85 skinny85 changed the title fix(codepipeline): reintroduce option to trigger on all tags to EcrSourceAction fix(codepipeline): cannot trigger on all tags anymore in EcrSourceAction Nov 5, 2021
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Awesome, thanks so much for the contribution @sparten11740!

One last tiny comment before we merge this in.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @sparten11740!

@mergify
Copy link
Contributor

mergify bot commented Nov 24, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: da03f37
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 39fe11b into aws:master Nov 25, 2021
@mergify
Copy link
Contributor

mergify bot commented Nov 25, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

beezly pushed a commit to beezly/aws-cdk that referenced this pull request Nov 29, 2021
…ion (aws#17270)

The EcrSourceAction could previously be used to trigger on changes to all tags of an image. As part of the fix aws#13818, the imageTag was defaulted to latest if not provided. Therefore it was no longer possible to call the underlying onCloudTrailImagePushed function with an undefined imageTag to watch changes on all tags.

Reintroduce triggering on all tags by passing an empty string as the imageTag.

Fixes aws#13818


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…ion (aws#17270)

The EcrSourceAction could previously be used to trigger on changes to all tags of an image. As part of the fix aws#13818, the imageTag was defaulted to latest if not provided. Therefore it was no longer possible to call the underlying onCloudTrailImagePushed function with an undefined imageTag to watch changes on all tags.

Reintroduce triggering on all tags by passing an empty string as the imageTag.

Fixes aws#13818


----

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

rix0rrr commented Jun 28, 2022

As reported in #20594, this change does not actually work as advertised. I looked at the ECR Source Action source code and will always substitute in the value "default" if imageTag is unspecified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(CodePipeline-Actions): Event created from ECR-Action does not use the default value the ECR-Action is using
4 participants