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(cli): skip bundling for operations where stack is not needed #9889

Merged
merged 25 commits into from
Sep 21, 2020

Conversation

jogold
Copy link
Contributor

@jogold jogold commented Aug 21, 2020

By default asset bundling is skipped for cdk list and cdk destroy. For cdk deploy, cdk diff
and cdk synthesize the default is to bundle assets for all stacks unless exclusively is specified.
In this case, only the listed stacks will have their assets bundled.

Closes #9540


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

@jogold jogold marked this pull request as ready for review August 21, 2020 11:59
@shivlaks shivlaks requested a review from rix0rrr August 26, 2020 07:10
@@ -63,10 +63,13 @@ async function parseCommandLineArguments() {
.option('output', { type: 'string', alias: 'o', desc: 'Emits the synthesized cloud assembly into a directory (default: cdk.out)', requiresArg: true })
.option('no-color', { type: 'boolean', desc: 'Removes colors and other style from console output', default: false })
.command(['list [STACKS..]', 'ls [STACKS..]'], 'Lists all stacks in the app', yargs => yargs
.option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }),
.option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' })
.option('bundling', { type: 'array', default: [], alias: 'b', desc: 'Run bundling only for given stacks (defaults to no stacks)' }),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we even need a CLI option for this after all? I don't see why someone would override the defaults here...

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, seems confusing. my initial idea was to support this as a global feature with a "smart default" so that users will be able to override this behavior if they want.

@jogold
Copy link
Contributor Author

jogold commented Sep 2, 2020

@eladb have you seen this?

eladb
eladb previously requested changes Sep 2, 2020
@@ -63,10 +63,13 @@ async function parseCommandLineArguments() {
.option('output', { type: 'string', alias: 'o', desc: 'Emits the synthesized cloud assembly into a directory (default: cdk.out)', requiresArg: true })
.option('no-color', { type: 'boolean', desc: 'Removes colors and other style from console output', default: false })
.command(['list [STACKS..]', 'ls [STACKS..]'], 'Lists all stacks in the app', yargs => yargs
.option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' }),
.option('long', { type: 'boolean', default: false, alias: 'l', desc: 'Display environment information for each stack' })
.option('bundling', { type: 'array', default: [], alias: 'b', desc: 'Run bundling only for given stacks (defaults to no stacks)' }),
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, seems confusing. my initial idea was to support this as a global feature with a "smart default" so that users will be able to override this behavior if they want.

@mergify mergify bot dismissed eladb’s stale review September 2, 2020 09:51

Pull request has been modified.

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.

Is this small are of effect even worth it?

How does this work in conjunction with Docker assets? Feels like we wouldn't do staging but we WOULD do build? Isn't that going to break?

if (BUNDLING_COMMANDS.includes(argv._[0])) {
// If we deploy, diff or synth a list of stacks exclusively we skip
// bundling for all other stacks.
bundlingStacks = argv.exclusively
Copy link
Contributor

Choose a reason for hiding this comment

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

This stringly-typed coupling to the yargs configuration in a completely different file is making me very nervous.

Can we at least add these to the definition of Arguments?

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 I type the first element of _,

export type Arguments = {
  readonly [name: string]: unknown,
  readonly _: [Command, ...string[]],
};

Then I'm not sure how I can make the TS compiler happy here?

const configuration = new Configuration(argv);

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, the typing of _ might be tricky.

But for example, exclusively can be added, and TSC knows the type of argv (that it has an exclusively: boolean | undefined field).

Copy link
Contributor

Choose a reason for hiding this comment

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

Also if you wanted to force it to accept your definition of _ you could do something like this:

const configuration = new Configuration({
  ...argv,
  _: argv._ as [Command, ...string[]]
});

(Which is a wacko type, btw. I didn't even know you could do that :) )

@jogold
Copy link
Contributor Author

jogold commented Sep 11, 2020

Is this small are of effect even worth it?

Yes, for apps with lots of bundled assets (Lambda functions) it's really painful to wait for bundling of all assets before seeing the output of cdk ls for example. And when deploying with -e you usually don't want to wait for assets belonging to other stacks to be bundled.

How does this work in conjunction with Docker assets? Feels like we wouldn't do staging but we WOULD do build? Isn't that going to break?

I think it has no impact. Docker assets cannot currently be bundled:

export interface DockerImageAssetOptions extends assets.FingerprintOptions {

and so are never staged with bundling specified:

const staging = new assets.Staging(this, 'Staging', {
...props,
exclude,
sourcePath: dir,
extraHash: Object.keys(extraHash).length === 0
? undefined
: JSON.stringify(extraHash),
});

@shivlaks shivlaks removed their assignment Sep 15, 2020
@mergify
Copy link
Contributor

mergify bot commented Sep 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
Copy link
Contributor

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 44b401b
  • 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 28cee39 into aws:master Sep 21, 2020
@jogold jogold deleted the skip-bundling branch September 24, 2020 09:43
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.

[cli, lambda] skip expensive bundling during "cdk list" and other operations where the stack is not needed
5 participants