Skip to content

Commit 0a9f01e

Browse files
committed
feat(cli): add publish command for asset publishing
1 parent 82fb0f3 commit 0a9f01e

File tree

10 files changed

+103
-0
lines changed

10 files changed

+103
-0
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/io/toolkit-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type ToolkitAction =
77
| 'synth'
88
| 'list'
99
| 'diff'
10+
| 'publish'
1011
| 'deploy'
1112
| 'drift'
1213
| 'rollback'

packages/aws-cdk/lib/cli/cdk-toolkit.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,30 @@ export class CdkToolkit {
374374
return diffs && options.fail ? 1 : 0;
375375
}
376376

377+
public async publish(options: PublishOptions) {
378+
const buildAsset = async (assetNode: AssetBuildNode) => {
379+
await this.props.deployments.buildSingleAsset(
380+
assetNode.assetManifestArtifact,
381+
assetNode.assetManifest,
382+
assetNode.asset,
383+
{
384+
stack: assetNode.parentStack,
385+
roleArn: options.roleArn,
386+
stackName: assetNode.parentStack.stackName,
387+
},
388+
);
389+
};
390+
391+
const publishAsset = async (assetNode: AssetPublishNode) => {
392+
await this.props.deployments.publishSingleAsset(assetNode.assetManifest, assetNode.asset, {
393+
stack: assetNode.parentStack,
394+
roleArn: options.roleArn,
395+
stackName: assetNode.parentStack.stackName,
396+
forcePublish: options.force,
397+
});
398+
};
399+
}
400+
377401
public async deploy(options: DeployOptions) {
378402
if (options.watch) {
379403
return this.watch(options);
@@ -1679,6 +1703,19 @@ interface WatchOptions extends Omit<CfnDeployOptions, 'execute'> {
16791703
readonly concurrency?: number;
16801704
}
16811705

1706+
export interface PublishOptions {
1707+
/**
1708+
* Role to pass to CloudFormation for asset publishing
1709+
*/
1710+
roleArn?: string;
1711+
1712+
/**
1713+
* Always publish, even if it already exists
1714+
* @default false
1715+
*/
1716+
force?: boolean;
1717+
}
1718+
16821719
export interface DeployOptions extends CfnDeployOptions, WatchOptions {
16831720
/**
16841721
* ARNs of SNS topics that CloudFormation will notify with stack related events

packages/aws-cdk/lib/cli/cli-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ export async function makeConfig(): Promise<CliConfig> {
136136
concurrency: { type: 'number', alias: ['n'], desc: 'Maximum number of simultaneous synths to execute.', default: 4, requiresArg: true },
137137
},
138138
},
139+
'publish': {
140+
description: 'Publishes synthesized assets (e.g. Docker images, Lambda ZIPs, S3 files) to their destinations',
141+
options: {
142+
force: { alias: 'f', type: 'boolean', desc: 'Always publish, even if it already exists', default: false },
143+
},
144+
},
139145
'deploy': {
140146
description: 'Deploys the stack(s) named STACKS into your AWS account',
141147
options: {

packages/aws-cdk/lib/cli/cli-type-registry.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,17 @@
407407
}
408408
}
409409
},
410+
"publish": {
411+
"description": "Publishes synthesized assets (e.g. Docker images, Lambda ZIPs, S3 files) to their destinations",
412+
"options": {
413+
"force": {
414+
"alias": "f",
415+
"type": "boolean",
416+
"desc": "Always publish, even if it already exists",
417+
"default": false
418+
}
419+
}
420+
},
410421
"deploy": {
411422
"description": "Deploys the stack(s) named STACKS into your AWS account",
412423
"options": {

packages/aws-cdk/lib/cli/cli.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
372372
},
373373
});
374374

375+
case 'publish':
376+
ioHost.currentAction = 'publish';
377+
return cli.publish({
378+
roleArn: args.roleArn,
379+
force: args.force,
380+
});
381+
375382
case 'deploy':
376383
ioHost.currentAction = 'deploy';
377384
const parameterMap: { [name: string]: string | undefined } = {};

packages/aws-cdk/lib/cli/convert-to-user-input.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export function convertYargsToUserInput(args: any): UserInput {
112112
};
113113
break;
114114

115+
case 'publish':
116+
commandOptions = {
117+
force: args.force,
118+
};
119+
break;
120+
115121
case 'deploy':
116122
commandOptions = {
117123
all: args.all,
@@ -399,6 +405,9 @@ export function convertConfigToUserInput(config: any): UserInput {
399405
safe: config.flags?.safe,
400406
concurrency: config.flags?.concurrency,
401407
};
408+
const publishOptions = {
409+
force: config.publish?.force,
410+
};
402411
const deployOptions = {
403412
all: config.deploy?.all,
404413
buildExclude: config.deploy?.buildExclude,
@@ -536,6 +545,7 @@ export function convertConfigToUserInput(config: any): UserInput {
536545
bootstrap: bootstrapOptions,
537546
gc: gcOptions,
538547
flags: flagsOptions,
548+
publish: publishOptions,
539549
deploy: deployOptions,
540550
rollback: rollbackOptions,
541551
import: importOptions,

packages/aws-cdk/lib/cli/parse-command-line-arguments.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,14 @@ export function parseCommandLineArguments(args: Array<string>): any {
430430
requiresArg: true,
431431
}),
432432
)
433+
.command('publish', 'Publishes synthesized assets (e.g. Docker images, Lambda ZIPs, S3 files) to their destinations', (yargs: Argv) =>
434+
yargs.option('force', {
435+
default: false,
436+
alias: 'f',
437+
type: 'boolean',
438+
desc: 'Always publish, even if it already exists',
439+
}),
440+
)
433441
.command('deploy [STACKS..]', 'Deploys the stack(s) named STACKS into your AWS account', (yargs: Argv) =>
434442
yargs
435443
.option('all', {

packages/aws-cdk/lib/cli/user-configuration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export enum Command {
1717
LIST = 'list',
1818
DIFF = 'diff',
1919
BOOTSTRAP = 'bootstrap',
20+
PUBLISH = 'publish',
2021
DEPLOY = 'deploy',
2122
DESTROY = 'destroy',
2223
SYNTHESIZE = 'synthesize',

packages/aws-cdk/lib/cli/user-input.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ export interface UserInput {
5050
*/
5151
readonly flags?: FlagsOptions;
5252

53+
/**
54+
* Publishes synthesized assets (e.g. Docker images, Lambda ZIPs, S3 files) to their destinations
55+
*/
56+
readonly publish?: PublishOptions;
57+
5358
/**
5459
* Deploys the stack(s) named STACKS into your AWS account
5560
*/
@@ -710,6 +715,22 @@ export interface FlagsOptions {
710715
readonly FLAGNAME?: Array<string>;
711716
}
712717

718+
/**
719+
* Publishes synthesized assets (e.g. Docker images, Lambda ZIPs, S3 files) to their destinations
720+
*
721+
* @struct
722+
*/
723+
export interface PublishOptions {
724+
/**
725+
* Always publish, even if it already exists
726+
*
727+
* aliases: f
728+
*
729+
* @default - false
730+
*/
731+
readonly force?: boolean;
732+
}
733+
713734
/**
714735
* Deploys the stack(s) named STACKS into your AWS account
715736
*

packages/aws-cdk/test/cli/cli-arguments.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ describe('config', () => {
125125
}),
126126
context: expect.anything(),
127127
acknowledge: expect.anything(),
128+
publish: expect.anything(),
128129
deploy: expect.anything(),
129130
destroy: expect.anything(),
130131
diff: expect.anything(),

0 commit comments

Comments
 (0)