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(pipelines): stack-level steps #16215

Merged
merged 8 commits into from
Sep 8, 2021
Merged

feat(pipelines): stack-level steps #16215

merged 8 commits into from
Sep 8, 2021

Conversation

kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Aug 24, 2021

Stack-level steps are available via the legacy API but not the modern API. This PR introduces the stackSteps property to AddStageOpts, allowing the user to specify additional steps at the stack level rather than the stage level. You can specify a step using the pre, changeSet or post options. pre steps happen before stack.prepare. changeSet steps happen between stack.prepare and stack.deploy. post steps happen after stack.deploy.

A primary use case is to add a ManualApprovalStep in stackSteps.changeSet to verify changes to the stack before deployment.

Closes #16148.


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 Aug 24, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 24, 2021
@kaizencc kaizencc requested a review from rix0rrr August 24, 2021 22:19
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

I like where this is going!

packages/@aws-cdk/pipelines/README.md Outdated Show resolved Hide resolved
for (const approval of props.changeSetApproval) {
for (const stack of approval.stacks) {
// getStackByName will throw if stack does not exist
const stackArtifact = assembly.getStackByName(stack.stackName);
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 I'd rather select the stack by selecting by construct path, that's guaranteed to be unique while stackName is only likely to be unique.

stack.node.path is the path, not sure which assembly.getStack() you need to be using there. It might not exist, in which case you have to iterate over all artifacts, check only for the stack artifacts and compare the nodePath (or hierarchicalId) attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

am hoping that the change to assembly.getStackArtifact(stackstep.stack.artifactId) suffices.

packages/@aws-cdk/pipelines/lib/blueprint/step.ts Outdated Show resolved Hide resolved
@kaizencc kaizencc changed the title feat(pipelines): add changeset approval feature to pipelines feat(pipelines): add stack-level steps to pipelines Aug 25, 2021
packages/@aws-cdk/pipelines/README.md Show resolved Hide resolved

retGraph.add(stackGraph);

stackGraph.add(deployNode);
let firstDeployNode;
if (prepareNode) {
stackGraph.add(prepareNode);
deployNode.dependOn(prepareNode);
firstDeployNode = prepareNode;
if (preNodeChain) {
Copy link
Contributor

@rix0rrr rix0rrr Aug 26, 2021

Choose a reason for hiding this comment

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

I don't mind this tangle of ifs as a first pass to make it work, but I think there's more beautiful code in there that is more clear with less case analysis.

We want to express something like this:

if (changeSet && !prepare) { 
  throw error
}

// pre here
// prepare here
// changeset here
// deploy here
// post here

Feels that with a couple of properly-chosen helper functions (that deal transparently with undefineds or empty arrays) we could get the code to read a lot more straightforward.

WDYT?

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 may need more discussion. Agree that the ifs is ugly. With my latest attempt to remove the node chains, I've decided to utilize the existing addPrePost() and add my own addChangeSet() method. Now, the logic follows similarly to addWave and other areas where it looks more like this:

// prepare here
// deploy here
// pre/changeset/post here, if necessary

While I do think there is still opportunity to clean things up, you may have to elaborate more on the properly-chosen helper functions to achieve this.

}
for (const p of post) {
const postNode = this.addAndRecurse(p, parent);
postNode?.dependOn(...currentNodes.nodes);
}
return preNodes;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if modifying addPrePost() like this is acceptable. The alternative option is to reuse a lot of this code, since all I really want to do is return a NodeCollection to add stack-level dependencies on it later.

stackGraph.add(deployNode);

// node or node collection that represents first point of contact in each stack
let firstDeployNode;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it feels a little wrong to continue calling this firstDeployNode given that it could be a node collection, but I'm not sure if it is that big of a deal.

@kaizencc kaizencc requested a review from rix0rrr August 26, 2021 19:04
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

I like it!

@rix0rrr rix0rrr changed the title feat(pipelines): add stack-level steps to pipelines feat(pipelines): stack-level steps Sep 8, 2021
@mergify
Copy link
Contributor

mergify bot commented Sep 8, 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: 6184dd6
  • 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 d499c85 into aws:master Sep 8, 2021
@mergify
Copy link
Contributor

mergify bot commented Sep 8, 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).

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.

(pipelines): changeset approval steps
3 participants