Skip to content

feat(core): make StackSynthesizer easier to subclass #22308

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 9 commits into from
Oct 3, 2022

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Sep 30, 2022

StackSynthesizers used to make heavy use of private APIs, which make it impossible for people outside the CDK core framework to implement their own Stack Synthesizers and modify the way assets are referenced. This question comes up more and more, so this PR opens up the facilities for doing that.

The changes are as follows:

  • Implement bind() in StackSynthesizer, and add a getter called boundStack which will return the bound stack.
  • Change synthesizeStackTemplate -> synthesizeTemplate, emitStackArtifact -> emitArtifact, both of which will implicitly operate on the bound stack.
  • Add addBootstrapVersionRule so that any subclass can choose to use this or not.
  • Expose AssetManifestBuilder, which stack synthesizers can use to build an asset manifest. Refactor the class to do less at the same time.
  • Expose cloudFormationLocationFrom...Asset functions to translate a published asset location into a CloudFormation location.
  • Document the contract of each method better.

The end result is that it will be easier to mix and match the different behaviors of the existing synthesizers together into new custom behavior.

Two new unit test files have been added to show how it is possible to write ONE intruction to the asset manifest (to upload assets to a given location) while returning a completely different instruction to the template (referencing the asset bucket using a CloudFormation parameter).


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

`StackSynthesizer`s used to make heavy use of private APIs, which make
it impossible for people outside the CDK core framework to implement
their own Stack Synthesizers and modify the way assets are referenced.
This question comes up more and more, so this PR opens up the facilities
for doing that.

The changes are as follows:

- Implement `bind()` in `StackSynthesizer`, and add a getter called
  `boundStack` which will return the bound stack.
- Change `synthesizeStackTemplate -> synthesizeTemplate`,
  `emitStackArtifact -> emitArtifact`, both of which will implicitly
  operate on the bound stack.
- Add `addBootstrapVersionRule` so that any subclass can choose to use
  this or not.
- Expose `AssetManifestBuilder`, which stack synthesizers can use to
  build an asset manifest. Refactor the class to do less at the same
  time.
- Expose `cloudFormationLocationFrom...Asset` functions to translate
  a published asset location into a CloudFormation location.
- Document the contract of each method better.

The end result is that it will be easier to mix and match the different
behaviors of the existing synthesizers together into new custom
behavior.

Two new unit test files have been added to show how it is possible
to write ONE intruction to the asset manifest (to upload assets to a
given location) while returning a completely different instruction to
the template (referencing the asset bucket using a CloudFormation
parameter).
@rix0rrr rix0rrr requested a review from a team September 30, 2022 12:45
@rix0rrr rix0rrr self-assigned this Sep 30, 2022
@gitpod-io
Copy link

gitpod-io bot commented Sep 30, 2022

@github-actions github-actions bot added the p2 label Sep 30, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team September 30, 2022 12:45
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 30, 2022
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The Pull Request Linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

@aws-cdk-automation aws-cdk-automation dismissed their stale review September 30, 2022 12:47

Pull Request updated. Dissmissing previous PRLinter Review.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The Pull Request Linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

@aws-cdk-automation aws-cdk-automation dismissed their stale review September 30, 2022 12:49

Pull Request updated. Dissmissing previous PRLinter Review.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The Pull Request Linter fails with the following errors:

❌ Features must contain a change to a README file.
❌ Features must contain a change to an integration test file and the resulting snapshot.

PRs must pass status checks before we can provide a meaningful review.

@rix0rrr rix0rrr added pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes labels Sep 30, 2022
@aws-cdk-automation aws-cdk-automation dismissed their stale review September 30, 2022 12:51

Pull Request updated. Dissmissing previous PRLinter Review.

@Naumel
Copy link
Contributor

Naumel commented Oct 3, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Oct 3, 2022

update

✅ Branch has been successfully updated

Copy link
Contributor

@Naumel Naumel 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, added the do-not-merge label in case you'd like another approval.

import { AssetManifestArtifact } from '@aws-cdk/cx-api';
import { DockerImageAsset } from '../lib';

// const DEMO_IMAGE_ASSET_HASH = '0a3355be12051c9984bf2b0b2bba4e6ea535968e5b6e7396449701732fe5ed14';
Copy link
Contributor

Choose a reason for hiding this comment

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

Left over or should have more context to be considered part of docs?

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: c11b609
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify
Copy link
Contributor

mergify bot commented Oct 3, 2022

Thank you for contributing! Your pull request will be updated from main 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 8b2b381 into main Oct 3, 2022
@mergify mergify bot deleted the huijbers/open-stack-synthesizers branch October 3, 2022 09:27
arewa pushed a commit to arewa/aws-cdk that referenced this pull request Oct 8, 2022
`StackSynthesizer`s used to make heavy use of private APIs, which make it impossible for people outside the CDK core framework to implement their own Stack Synthesizers and modify the way assets are referenced. This question comes up more and more, so this PR opens up the facilities for doing that.

The changes are as follows:

- Implement `bind()` in `StackSynthesizer`, and add a getter called `boundStack` which will return the bound stack.
- Change `synthesizeStackTemplate -> synthesizeTemplate`, `emitStackArtifact -> emitArtifact`, both of which will implicitly operate on the bound stack.
- Add `addBootstrapVersionRule` so that any subclass can choose to use this or not.
- Expose `AssetManifestBuilder`, which stack synthesizers can use to build an asset manifest. Refactor the class to do less at the same time.
- Expose `cloudFormationLocationFrom...Asset` functions to translate a published asset location into a CloudFormation location.
- Document the contract of each method better.

The end result is that it will be easier to mix and match the different behaviors of the existing synthesizers together into new custom behavior.

Two new unit test files have been added to show how it is possible to write ONE intruction to the asset manifest (to upload assets to a given location) while returning a completely different instruction to the template (referencing the asset bucket using a CloudFormation parameter).


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
homakk pushed a commit to homakk/aws-cdk that referenced this pull request Dec 1, 2022
`StackSynthesizer`s used to make heavy use of private APIs, which make it impossible for people outside the CDK core framework to implement their own Stack Synthesizers and modify the way assets are referenced. This question comes up more and more, so this PR opens up the facilities for doing that.

The changes are as follows:

- Implement `bind()` in `StackSynthesizer`, and add a getter called `boundStack` which will return the bound stack.
- Change `synthesizeStackTemplate -> synthesizeTemplate`, `emitStackArtifact -> emitArtifact`, both of which will implicitly operate on the bound stack.
- Add `addBootstrapVersionRule` so that any subclass can choose to use this or not.
- Expose `AssetManifestBuilder`, which stack synthesizers can use to build an asset manifest. Refactor the class to do less at the same time.
- Expose `cloudFormationLocationFrom...Asset` functions to translate a published asset location into a CloudFormation location.
- Document the contract of each method better.

The end result is that it will be easier to mix and match the different behaviors of the existing synthesizers together into new custom behavior.

Two new unit test files have been added to show how it is possible to write ONE intruction to the asset manifest (to upload assets to a given location) while returning a completely different instruction to the template (referencing the asset bucket using a CloudFormation parameter).


----

*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. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants