From 1656684fa54984ec6c6b2e47583d959545b0d2bd Mon Sep 17 00:00:00 2001 From: Ronald Luitwieler Date: Wed, 1 May 2019 12:55:40 +0200 Subject: [PATCH 1/4] feat(bootstrap): allow specifying the toolkit staging bucket name --- packages/aws-cdk/README.md | 9 +++++---- packages/aws-cdk/aws-cdk | 1 + packages/aws-cdk/bin/cdk.ts | 12 ++++++++---- packages/aws-cdk/lib/api/bootstrap-environment.ts | 5 ++++- 4 files changed, 18 insertions(+), 9 deletions(-) create mode 120000 packages/aws-cdk/aws-cdk diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index 7fd8bff8b8057..2450bdc7aa2ed 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -164,11 +164,12 @@ configuration's order of precedence is: Some of the interesting keys that can be used in the JSON configuration files: ```js { - "app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js') - "context": { // Context entries (--context=key=value) + "app": "node bin/main.js", // Command to start the CDK app (--app='node bin/main.js') + "context": { // Context entries (--context=key=value) "key": "value", }, - "toolkitStackName": "foo", // Customize 'bootstrap' stack name (--toolkit-stack-name=foo) - "versionReporting": false, // Opt-out of version reporting (--no-version-reporting) + "toolkitStackName": "foo", // Customize 'bootstrap' stack name (--toolkit-stack-name=foo) + "toolkitBucketName": "fooBucket", // Customize 'bootstrap' bucket name(--toolkit-bucket-name=fooBucket) + "versionReporting": false, // Opt-out of version reporting (--no-version-reporting) } ``` diff --git a/packages/aws-cdk/aws-cdk b/packages/aws-cdk/aws-cdk new file mode 120000 index 0000000000000..daec18417e708 --- /dev/null +++ b/packages/aws-cdk/aws-cdk @@ -0,0 +1 @@ +/Users/ldrhgp1/ronald/cdk/aws-cdk/node_modules/aws-cdk \ No newline at end of file diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 91f0ebffe3919..e8341e3be8ceb 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -56,7 +56,8 @@ async function parseCommandLineArguments() { .option('interactive', { type: 'boolean', alias: 'i', desc: 'interactively watch and show template updates' }) .option('output', { type: 'string', alias: 'o', desc: 'write CloudFormation template for requested stacks to the given directory', requiresArg: true }) .option('numbered', { type: 'boolean', alias: 'n', desc: 'prefix filenames with numbers to indicate deployment ordering' })) - .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment') + .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs + .option('toolkit-bucket-name', { type: 'string', alias: 'b', desc: 'The name of the CDK toolkit bucket name', default: undefined })) .command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', yargs => yargs .option('build-exclude', { type: 'array', alias: 'E', nargs: 1, desc: 'do not rebuild asset with the given ID. Can be specified multiple times.', default: [] }) .option('exclusively', { type: 'boolean', alias: 'e', desc: 'only deploy requested stacks, don\'t include dependencies' }) @@ -189,7 +190,7 @@ async function initCommandLine() { }); case 'bootstrap': - return await cliBootstrap(args.ENVIRONMENTS, toolkitStackName, args.roleArn); + return await cliBootstrap(args.ENVIRONMENTS, toolkitStackName, args.roleArn, args.toolkitBucketName); case 'deploy': return await cli.deploy({ @@ -238,7 +239,7 @@ async function initCommandLine() { * all stacks are implicitly selected. * @param toolkitStackName the name to be used for the CDK Toolkit stack. */ - async function cliBootstrap(environmentGlobs: string[], toolkitStackName: string, roleArn: string | undefined): Promise { + async function cliBootstrap(environmentGlobs: string[], toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise { // Two modes of operation. // // If there is an '--app' argument, we select the environments from the app. Otherwise we just take the user @@ -247,11 +248,14 @@ async function initCommandLine() { const app = configuration.settings.get(['app']); const environments = app ? await globEnvironmentsFromStacks(appStacks, environmentGlobs) : environmentsFromDescriptors(environmentGlobs); + + // Bucket name can be passed using --toolkit-bucket-name or set in cdk.json + const bucketName = configuration.settings.get(['toolkitBucketName']) || toolkitBucketName; await Promise.all(environments.map(async (environment) => { success(' ⏳ Bootstrapping environment %s...', colors.blue(environment.name)); try { - const result = await bootstrapEnvironment(environment, aws, toolkitStackName, roleArn); + const result = await bootstrapEnvironment(environment, aws, toolkitStackName, roleArn, bucketName); const message = result.noOp ? ' ✅ Environment %s bootstrapped (no changes).' : ' ✅ Environment %s bootstrapped.'; success(message, colors.blue(environment.name)); diff --git a/packages/aws-cdk/lib/api/bootstrap-environment.ts b/packages/aws-cdk/lib/api/bootstrap-environment.ts index 122899919e97a..d2c751b36b6dc 100644 --- a/packages/aws-cdk/lib/api/bootstrap-environment.ts +++ b/packages/aws-cdk/lib/api/bootstrap-environment.ts @@ -7,7 +7,7 @@ import { SDK } from './util/sdk'; export const BUCKET_NAME_OUTPUT = 'BucketName'; export const BUCKET_DOMAIN_NAME_OUTPUT = 'BucketDomainName'; -export async function bootstrapEnvironment(environment: Environment, aws: SDK, toolkitStackName: string, roleArn: string | undefined): Promise { +export async function bootstrapEnvironment(environment: Environment, aws: SDK, toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise { const synthesizedStack: SynthesizedStack = { environment, metadata: {}, @@ -35,5 +35,8 @@ export async function bootstrapEnvironment(environment: Environment, aws: SDK, t }, name: toolkitStackName, }; + if (toolkitBucketName) { + synthesizedStack.template.Resources.StagingBucket.Properties.BucketName = toolkitBucketName; + } return await deployStack({ stack: synthesizedStack, sdk: aws, roleArn }); } From 17c637d2dd72f02b1d6fb3ce3cf421e2c6713b05 Mon Sep 17 00:00:00 2001 From: Ronald Luitwieler Date: Wed, 1 May 2019 13:13:12 +0200 Subject: [PATCH 2/4] feat(bootstrap): allow specifying the toolkit staging bucket name --- packages/aws-cdk/bin/cdk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index e8341e3be8ceb..d5daef1237dce 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -248,7 +248,7 @@ async function initCommandLine() { const app = configuration.settings.get(['app']); const environments = app ? await globEnvironmentsFromStacks(appStacks, environmentGlobs) : environmentsFromDescriptors(environmentGlobs); - + // Bucket name can be passed using --toolkit-bucket-name or set in cdk.json const bucketName = configuration.settings.get(['toolkitBucketName']) || toolkitBucketName; From 0df7f666fd23ecac872bff8387399dd7f17b4131 Mon Sep 17 00:00:00 2001 From: Ronald Luitwieler Date: Wed, 1 May 2019 16:12:10 +0200 Subject: [PATCH 3/4] typo :) --- packages/aws-cdk/bin/cdk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index d5daef1237dce..421ff6dc2831b 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -57,7 +57,7 @@ async function parseCommandLineArguments() { .option('output', { type: 'string', alias: 'o', desc: 'write CloudFormation template for requested stacks to the given directory', requiresArg: true }) .option('numbered', { type: 'boolean', alias: 'n', desc: 'prefix filenames with numbers to indicate deployment ordering' })) .command('bootstrap [ENVIRONMENTS..]', 'Deploys the CDK toolkit stack into an AWS environment', yargs => yargs - .option('toolkit-bucket-name', { type: 'string', alias: 'b', desc: 'The name of the CDK toolkit bucket name', default: undefined })) + .option('toolkit-bucket-name', { type: 'string', alias: 'b', desc: 'The name of the CDK toolkit bucket', default: undefined })) .command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', yargs => yargs .option('build-exclude', { type: 'array', alias: 'E', nargs: 1, desc: 'do not rebuild asset with the given ID. Can be specified multiple times.', default: [] }) .option('exclusively', { type: 'boolean', alias: 'e', desc: 'only deploy requested stacks, don\'t include dependencies' }) From 26ee94aafa333b53b09816ef5aaec616b0b517af Mon Sep 17 00:00:00 2001 From: Ronald Luitwieler Date: Wed, 1 May 2019 21:53:19 +0200 Subject: [PATCH 4/4] remove ln --- packages/aws-cdk/aws-cdk | 1 - 1 file changed, 1 deletion(-) delete mode 120000 packages/aws-cdk/aws-cdk diff --git a/packages/aws-cdk/aws-cdk b/packages/aws-cdk/aws-cdk deleted file mode 120000 index daec18417e708..0000000000000 --- a/packages/aws-cdk/aws-cdk +++ /dev/null @@ -1 +0,0 @@ -/Users/ldrhgp1/ronald/cdk/aws-cdk/node_modules/aws-cdk \ No newline at end of file