Skip to content

Commit

Permalink
chore(cli): make the "new" bootstrapping the default in V2 (aws#13918)
Browse files Browse the repository at this point in the history
Make the "new" bootstrapping
(that adds additional resources beyond the S3 bucket to the template,
like an ECR repository, and IAM roles)
the default.
Allow using the "old" bootstrapping by setting the `CDK_LEGACY_BOOTSTRAP`
environment variable.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
skinny85 authored Apr 12, 2021
1 parent d9546b7 commit 5cf56fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 20 deletions.
61 changes: 43 additions & 18 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,7 @@ async function initCommandLine() {
});

case 'bootstrap':
// Use new bootstrapping if it's requested via environment variable, or if
// new style stack synthesis has been configured in `cdk.json`.
//
// In code it's optimistically called "default" bootstrapping but that is in
// anticipation of flipping the switch, in user messaging we still call it
// "new" bootstrapping.
let source: BootstrapSource = { source: 'legacy' };
const newStyleStackSynthesis = isFeatureEnabled(configuration, cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT);
if (args.template) {
print(`Using bootstrapping template from ${args.template}`);
source = { source: 'custom', templateFile: args.template };
} else if (process.env.CDK_NEW_BOOTSTRAP) {
print('CDK_NEW_BOOTSTRAP set, using new-style bootstrapping');
source = { source: 'default' };
} else if (newStyleStackSynthesis) {
print(`'${cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT}' context set, using new-style bootstrapping`);
source = { source: 'default' };
}
const source: BootstrapSource = determineBootsrapVersion(args, configuration);

const bootstrapper = new Bootstrapper(source);

Expand Down Expand Up @@ -361,6 +344,48 @@ async function initCommandLine() {
}
}

/**
* Determine which version of bootstrapping
* (legacy, or "new") should be used.
*/
function determineBootsrapVersion(args: { template?: string }, configuration: Configuration): BootstrapSource {
const isV1 = version.DISPLAY_VERSION.startsWith('1.');
return isV1 ? determineV1BootstrapSource(args, configuration) : determineV2BootstrapSource(args);
}

function determineV1BootstrapSource(args: { template?: string }, configuration: Configuration): BootstrapSource {
let source: BootstrapSource;
if (args.template) {
print(`Using bootstrapping template from ${args.template}`);
source = { source: 'custom', templateFile: args.template };
} else if (process.env.CDK_NEW_BOOTSTRAP) {
print('CDK_NEW_BOOTSTRAP set, using new-style bootstrapping');
source = { source: 'default' };
} else if (isFeatureEnabled(configuration, cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT)) {
print(`'${cxapi.NEW_STYLE_STACK_SYNTHESIS_CONTEXT}' context set, using new-style bootstrapping`);
source = { source: 'default' };
} else {
// in V1, the "legacy" bootstrapping is the default
source = { source: 'legacy' };
}
return source;
}

function determineV2BootstrapSource(args: { template?: string }): BootstrapSource {
let source: BootstrapSource;
if (args.template) {
print(`Using bootstrapping template from ${args.template}`);
source = { source: 'custom', templateFile: args.template };
} else if (process.env.CDK_LEGACY_BOOTSTRAP) {
print('CDK_LEGACY_BOOTSTRAP set, using legacy-style bootstrapping');
source = { source: 'legacy' };
} else {
// in V2, the "new" bootstrapping is the default
source = { source: 'default' };
}
return source;
}

function isFeatureEnabled(configuration: Configuration, featureFlag: string) {
return configuration.context.get(featureFlag) ?? cxapi.futureFlagDefault(featureFlag);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/aws-cdk/test/integ/cli/bootstrapping.integtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ integTest('upgrade legacy bootstrap stack to new bootstrap stack while in use',
// Legacy bootstrap
await fixture.cdk(['bootstrap',
'--toolkit-stack-name', bootstrapStackName,
'--bootstrap-bucket-name', legacyBootstrapBucketName]);
'--bootstrap-bucket-name', legacyBootstrapBucketName], {
modEnv: {
CDK_LEGACY_BOOTSTRAP: '1',
},
});

// Deploy stack that uses file assets
await fixture.cdkDeploy('lambda', {
Expand Down Expand Up @@ -266,4 +270,4 @@ integTest('can deploy modern-synthesized stack even if bootstrap stack name is u
'--context', '@aws-cdk/core:newStyleStackSynthesis=1',
],
});
}));
}));

0 comments on commit 5cf56fb

Please sign in to comment.