Skip to content

fix(pipelines): prevent self-mutation on asset updates #9183

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

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

njlynch
Copy link
Contributor

@njlynch njlynch commented Jul 21, 2020

Currently, changes to the asset hashes of content results in changes to the
definitions of the pipeline, causing the self-mutate state to trigger. This can
cause infinite loops for systems where build artifacts change on each build.

The cause for this looping is that the asset hash was embedded as the pipeline
action name. By replacing the asset hash with a simple asset counter (already
used for the action CloudFormation id), the pipeline definition should remain
stable on asset changes.

Testing: Due to the pipeline executing the current version of CDK within the
pipeline, it's impossible to actual verify that this corrects the issue. To
test + verify, created a sample app where the asset hash changed on each build.
Then ran subsequent 'cdk synth' commands and diff'ed the output. Prior to this
change, there were numerous changes related to the asset hash in the pipeline
stack. After, only the buildspec of the CodeBuild project that referenced the
hash changed. This does not change the definition of the CodePipeline itself.

fixes #9080


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

Currently, changes to the asset hashes of content results in changes to the
definitions of the pipeline, causing the self-mutate state to trigger. This can
cause infinite loops for systems where build artifacts change on each build.

The cause for this looping is that the asset hash was embedded as the pipeline
action name. By replacing the asset hash with a simple asset counter (already
used for the action CloudFormation id), the pipeline definition should remain
stable on asset changes.

_Testing:_ Due to the pipeline executing the current version of CDK within the
pipeline, it's impossible to actual verify that this corrects the issue. To
test + verify, created a sample app where the asset hash changed on each build.
Then ran subsequent 'cdk synth' commands and diff'ed the output. Prior to this
change, there were numerous changes related to the asset hash in the pipeline
stack. After, only the buildspec of the CodeBuild project that referenced the
hash changed. This does not change the definition of the CodePipeline itself.
@njlynch njlynch requested a review from a team July 21, 2020 11:33
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 21, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 180bbba
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Beautiful!

@mergify
Copy link
Contributor

mergify bot commented Jul 21, 2020

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).

@mergify mergify bot merged commit 05fc934 into master Jul 21, 2020
@@ -279,7 +279,7 @@ class AssetPublishing extends Construct {
const id = command.assetType === AssetType.FILE ? `FileAsset${this._fileAssetCtr++}` : `DockerAsset${this._dockerAssetCtr++}`;

action = this.publishers[command.assetId] = new PublishAssetsAction(this, id, {
actionName: command.assetId,
actionName: id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment explaining why we are using the ID for the action name

@mergify mergify bot deleted the njlynch/pipelines-assetloop branch July 21, 2020 12:49
@asterikx
Copy link
Contributor

Short question:

Imagine the case where a new asset is added to a CDK app and all other assets remained unchanged (same hash as before). This PR leads to all assets having to be published again (in the worst case), as assets might get assigned to a different publishing action as before. E.g. if the newly added asset gets assigned to publishing action No. 1 and the unchanged assets get "shifted" by one publishing action.

This might be a trade-off to accept though. Thanks for this PR @njlynch!

mergify bot pushed a commit that referenced this pull request Jul 21, 2020
)

Follow-on to #9183.

----

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

eladb commented Jul 21, 2020

Short question:

Imagine the case where a new asset is added to a CDK app and all other assets remained unchanged (same hash as before). This PR leads to all assets having to be published again (in the worst case), as assets might get assigned to a different publishing action as before. E.g. if the newly added asset gets assigned to publishing action No. 1 and the unchanged assets get "shifted" by one publishing action.

This might be a trade-off to accept though. Thanks for this PR @njlynch!

Since the asset hash of all other assets would not change, the publisher (cdk-assets publish) will succeed with no-op

Chriscbr pushed a commit to Chriscbr/aws-cdk that referenced this pull request Jul 23, 2020
Currently, changes to the asset hashes of content results in changes to the
definitions of the pipeline, causing the self-mutate state to trigger. This can
cause infinite loops for systems where build artifacts change on each build.

The cause for this looping is that the asset hash was embedded as the pipeline
action name. By replacing the asset hash with a simple asset counter (already
used for the action CloudFormation id), the pipeline definition should remain
stable on asset changes.

_Testing:_ Due to the pipeline executing the current version of CDK within the
pipeline, it's impossible to actual verify that this corrects the issue. To
test + verify, created a sample app where the asset hash changed on each build.
Then ran subsequent 'cdk synth' commands and diff'ed the output. Prior to this
change, there were numerous changes related to the asset hash in the pipeline
stack. After, only the buildspec of the CodeBuild project that referenced the
hash changed. This does not change the definition of the CodePipeline itself.

fixes aws#9080

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Chriscbr pushed a commit to Chriscbr/aws-cdk that referenced this pull request Jul 23, 2020
…s#9188)

Follow-on to aws#9183.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
curtiseppel pushed a commit to curtiseppel/aws-cdk that referenced this pull request Aug 11, 2020
Currently, changes to the asset hashes of content results in changes to the
definitions of the pipeline, causing the self-mutate state to trigger. This can
cause infinite loops for systems where build artifacts change on each build.

The cause for this looping is that the asset hash was embedded as the pipeline
action name. By replacing the asset hash with a simple asset counter (already
used for the action CloudFormation id), the pipeline definition should remain
stable on asset changes.

_Testing:_ Due to the pipeline executing the current version of CDK within the
pipeline, it's impossible to actual verify that this corrects the issue. To
test + verify, created a sample app where the asset hash changed on each build.
Then ran subsequent 'cdk synth' commands and diff'ed the output. Prior to this
change, there were numerous changes related to the asset hash in the pipeline
stack. After, only the buildspec of the CodeBuild project that referenced the
hash changed. This does not change the definition of the CodePipeline itself.

fixes aws#9080

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
curtiseppel pushed a commit to curtiseppel/aws-cdk that referenced this pull request Aug 11, 2020
…s#9188)

Follow-on to aws#9183.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[cdk-pipelines] Every asset update mutates the pipeline
4 participants