Skip to content

Commit

Permalink
feat(bootstrap): allow specifying the toolkit staging bucket name (#2407
Browse files Browse the repository at this point in the history
)

Add a command line argument to specify the toolkit staging bucket name.

Closes #2390.
  • Loading branch information
orangewise authored and rix0rrr committed May 6, 2019
1 parent 433e144 commit 3bfc641
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
9 changes: 5 additions & 4 deletions packages/aws-cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```
12 changes: 8 additions & 4 deletions packages/aws-cdk/bin/cdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', 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' })
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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<void> {
async function cliBootstrap(environmentGlobs: string[], toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise<void> {
// Two modes of operation.
//
// If there is an '--app' argument, we select the environments from the app. Otherwise we just take the user
Expand All @@ -248,10 +249,13 @@ async function initCommandLine() {

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));
Expand Down
5 changes: 4 additions & 1 deletion packages/aws-cdk/lib/api/bootstrap-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeployStackResult> {
export async function bootstrapEnvironment(environment: Environment, aws: SDK, toolkitStackName: string, roleArn: string | undefined, toolkitBucketName: string | undefined): Promise<DeployStackResult> {
const synthesizedStack: SynthesizedStack = {
environment,
metadata: {},
Expand Down Expand Up @@ -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 });
}

0 comments on commit 3bfc641

Please sign in to comment.