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

Use cdk-cli-lib to synthesize CDK application #170

Merged
merged 12 commits into from
Nov 1, 2024
Merged

Conversation

corymhall
Copy link
Contributor

@corymhall corymhall commented Oct 7, 2024

This PR introduces a breaking change to the API changes the entrypoint of the application from the Stack construct to the App component.

Previous API

class MyStack extends pulumicdk.Stack {
  constructor(id: string, props: pulumicdk.StackProps) {
      super(id, props);
          const bucket = new s3.Bucket(this, 'Bucket');
          this.synth();
  }
}

New API

new pulumicdk.App('app', (scope: pulumicdk.App) => {
    const stack = new pulumicdk.Stack(scope, 'stack');
    const bucket = new s3.Bucket(this, 'Bucket');
});

This will allow for a couple of benefits

  1. No longer need to subclass pulumicdk.Stack and call the protected synth method.
  2. Will enable multiple stacks
  3. Allows for native use of CDK Context and Lookups

For a more detailed breakdown on why we are making this change, i've included and ADR based on the internal doc.

closes #153

examples/lookups/index.ts Outdated Show resolved Hide resolved
examples/lookups/index.ts Outdated Show resolved Hide resolved
/** @internal */
registerOutput(outputId: string, output: any) {
this.stack.outputs[outputId] = pulumi.output(output);
async produce(context: Record<string, any>): Promise<string> {
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 is what will get executed multiple times.

Copy link
Member

Choose a reason for hiding this comment

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

This sounds like piece-de-resistane in this PR. So it's calling app.synth() and returning dir.

So couple of low-level questions here perhaps.

  1. if this method fails, are we OK? do we expect it to fail or we don't expect it to regularly fail?
  2. if app.synth() creates temp dirs with assets, what cleans it up? is it something to worry about?
  3. the state of this is modified this.assemblyDir = dir and this.stacks[child.artifactId] = child - do we need to worry about something concurrently accessing the partial state before the framework is done calling us repeatedly or it all works out as needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if this method fails, are we OK? do we expect it to fail or we don't expect it to regularly fail?

This is called when we call cli.synth() as part of initialize and we do catch errors there.

if app.synth() creates temp dirs with assets, what cleans it up? is it something to worry about?

Maybe? It will create it as a system tmp dir which gets cleaned up whenever the computer restarts.

the state of this is modified this.assemblyDir = dir and this.stacks[child.artifactId] = child - do we need to worry about something concurrently accessing the partial state before the framework is done calling us repeatedly or it all works out as needed?

We shouldn't need to worry about it. This is called in blocking code as part of initialize.

Copy link
Member

Choose a reason for hiding this comment

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

System temp dir should be fine, yes. All good then.

*/
outputs: { [outputId: string]: pulumi.Output<any> } = {};
public static isPulumiStack(x: any): x is Stack {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

instanceOf doesn't work for constructs...

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 test didn't really test anything. It appears to test lookups, but it doesn't actually.

@@ -44,8 +44,8 @@ jobs:
test:
name: acceptance-test
concurrency:
group: acceptance-test-${{ matrix.index }} # TODO: concurrent tests across PRs can cause problems
cancel-in-progress: false
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.index }} # TODO: concurrent tests across PRs can cause problems
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we've fixed the concurrency issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied most of the doc here so it can live in the repo.

@corymhall corymhall marked this pull request as ready for review October 29, 2024 18:09
@corymhall corymhall requested review from t0yv0 and flostadler October 29, 2024 18:09
@corymhall corymhall force-pushed the corymhall/cdk-cli-v3 branch from bfa47d5 to 42df90a Compare October 29, 2024 18:16
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
adr/cdk-cli-lib.md Show resolved Hide resolved
adr/cdk-cli-lib.md Show resolved Hide resolved
examples/s3-object-lambda/index.ts Show resolved Hide resolved
src/stack.ts Show resolved Hide resolved
src/stack.ts Show resolved Hide resolved
src/stack.ts Show resolved Hide resolved
@t0yv0
Copy link
Member

t0yv0 commented Oct 31, 2024

Quick question on the API.

new pulumicdk.App('app', (scope: pulumicdk.App) => {
    const stack = new pulumicdk.Stack(scope, 'stack');
    const bucket = new s3.Bucket(this, 'Bucket');
});

What is this refer to? Is this some JavaScript magic binding this in the callback? Can we have something explicit instead?

Will users always create exactly one stack as the first thing in the callback? Or it is possible to have more than one or not have one? Ah "Will enable multiple stacks" - got this. This is by design.

@@ -1,12 +1,22 @@
# Pulumi CDK Adapter (preview)

The Pulumi CDK Adapter is a library that enables [Pulumi](https://github.com/pulumi/pulumi) programs to use [AWS CDK](https://github.com/aws/aws-cdk) constructs.
The Pulumi CDK Adapter is a library that enables
Copy link
Member

Choose a reason for hiding this comment

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

Is this change necessary? Looks like Emacs fil-paragraph got applied. I think we prefer to have the previous form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, I kind of prefer the 80 line length limit. It makes looking/editing so much easier. It's also the default in most markdown linters, (e.g. markdownlint

Copy link
Member

Choose a reason for hiding this comment

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

AH nice, one of those things that'd just nice to have a standard. We can adopt it in the project. I'll setup column width 80 in Emacs.

@@ -81,99 +94,111 @@ Try the workshop at https://apprunnerworkshop.com
Read the docs at https://docs.aws.amazon.com/apprunner
```

## Getting Started

### Bootstrapping
Copy link
Member

Choose a reason for hiding this comment

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

We now auto-bootstrap? Perhaps still worth a mention that it does this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some docs around bootstrapping and what resources we create for you.

@corymhall
Copy link
Contributor Author

@t0yv0

What is this refer to? Is this some JavaScript magic binding this in the callback? Can we have something explicit instead?

This is actually a mistake on my part so good catch! This should say stack instead.

@t0yv0 t0yv0 self-requested a review October 31, 2024 17:52
Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

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

Looking good at a glance. Sorry for a rather shallow review, I need to get better at this codebase.

@corymhall corymhall requested a review from flostadler October 31, 2024 19:31
@t0yv0
Copy link
Member

t0yv0 commented Oct 31, 2024

:shipit:

Copy link
Contributor

@flostadler flostadler left a comment

Choose a reason for hiding this comment

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

LGTM!

@corymhall corymhall merged commit 8be5049 into main Nov 1, 2024
8 checks passed
@corymhall corymhall deleted the corymhall/cdk-cli-v3 branch November 1, 2024 11:37
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v1.0.0.

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.

Use cdk-cli-lib to synthesize cdk app
4 participants