Skip to content

Commit 54f865f

Browse files
committed
feat(cli): allow to parallelize asset build
1 parent 2a6f8d3 commit 54f865f

File tree

11 files changed

+47
-2
lines changed

11 files changed

+47
-2
lines changed

packages/@aws-cdk/toolkit-lib/lib/actions/deploy/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ export interface DeployOptions extends BaseDeployOptions {
214214
*/
215215
readonly assetParallelism?: boolean;
216216

217+
/**
218+
* Maximum number of asset builds to run in parallel
219+
*
220+
* This setting only has an effect if `assetParallelism` is set to `true`.
221+
*
222+
* @default 1
223+
*/
224+
readonly assetBuildConcurrency?: number;
225+
217226
/**
218227
* When to build assets
219228
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
823823

824824
const graphConcurrency: Concurrency = {
825825
'stack': concurrency,
826-
'asset-build': 1, // This will be CPU-bound/memory bound, mostly matters for Docker builds
826+
'asset-build': (options.assetParallelism ?? true) ? options.assetBuildConcurrency ?? 1 : 1, // This will be CPU-bound/memory bound, mostly matters for Docker builds
827827
'asset-publish': (options.assetParallelism ?? true) ? 8 : 1, // This will be I/O-bound, 8 in parallel seems reasonable
828828
};
829829

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ export class CdkToolkit {
705705

706706
const graphConcurrency: Concurrency = {
707707
'stack': concurrency,
708-
'asset-build': 1, // This will be CPU-bound/memory bound, mostly matters for Docker builds
708+
'asset-build': (options.assetParallelism ?? true) ? options.assetBuildConcurrency ?? 1 : 1, // This will be CPU-bound/memory bound, mostly matters for Docker builds
709709
'asset-publish': (options.assetParallelism ?? true) ? 8 : 1, // This will be I/O-bound, 8 in parallel seems reasonable
710710
};
711711

@@ -1766,6 +1766,15 @@ export interface DeployOptions extends CfnDeployOptions, WatchOptions {
17661766
*/
17671767
readonly assetParallelism?: boolean;
17681768

1769+
/**
1770+
* Maximum number of asset builds to run in parallel
1771+
*
1772+
* This setting only has an effect if `assetParallelism` is set to `true`.
1773+
*
1774+
* @default 1
1775+
*/
1776+
readonly assetBuildConcurrency?: number;
1777+
17691778
/**
17701779
* When to build assets
17711780
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export async function makeConfig(): Promise<CliConfig> {
208208
},
209209
'concurrency': { type: 'number', desc: 'Maximum number of simultaneous deployments (dependency permitting) to execute.', default: 1, requiresArg: true },
210210
'asset-parallelism': { type: 'boolean', desc: 'Whether to build/publish assets in parallel' },
211+
'asset-build-concurrency': { type: 'number', desc: 'Maximum number of asset builds to run in parallel', default: 1, requiresArg: true },
211212
'asset-prebuild': { type: 'boolean', desc: 'Whether to build all assets before deploying the first stack (useful for failing Docker builds)', default: true },
212213
'ignore-no-stacks': { type: 'boolean', desc: 'Whether to deploy if the app contains no stacks', default: false },
213214
},

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,12 @@
548548
"type": "boolean",
549549
"desc": "Whether to build/publish assets in parallel"
550550
},
551+
"asset-build-concurrency": {
552+
"type": "number",
553+
"desc": "Maximum number of asset builds to run in parallel",
554+
"default": 1,
555+
"requiresArg": true
556+
},
551557
"asset-prebuild": {
552558
"type": "boolean",
553559
"desc": "Whether to build all assets before deploying the first stack (useful for failing Docker builds)",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
407407
traceLogs: args.logs,
408408
concurrency: args.concurrency,
409409
assetParallelism: configuration.settings.get(['assetParallelism']),
410+
assetBuildConcurrency: configuration.settings.get(['assetBuildConcurrency']),
410411
assetBuildTime: configuration.settings.get(['assetPrebuild'])
411412
? AssetBuildTime.ALL_BEFORE_DEPLOY
412413
: AssetBuildTime.JUST_IN_TIME,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export function convertYargsToUserInput(args: any): UserInput {
140140
logs: args.logs,
141141
concurrency: args.concurrency,
142142
assetParallelism: args.assetParallelism,
143+
assetBuildConcurrency: args.assetBuildConcurrency,
143144
assetPrebuild: args.assetPrebuild,
144145
ignoreNoStacks: args.ignoreNoStacks,
145146
STACKS: args.STACKS,
@@ -425,6 +426,7 @@ export function convertConfigToUserInput(config: any): UserInput {
425426
logs: config.deploy?.logs,
426427
concurrency: config.deploy?.concurrency,
427428
assetParallelism: config.deploy?.assetParallelism,
429+
assetBuildConcurrency: config.deploy?.assetBuildConcurrency,
428430
assetPrebuild: config.deploy?.assetPrebuild,
429431
ignoreNoStacks: config.deploy?.ignoreNoStacks,
430432
};

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,12 @@ export function parseCommandLineArguments(args: Array<string>): any {
584584
type: 'boolean',
585585
desc: 'Whether to build/publish assets in parallel',
586586
})
587+
.option('asset-build-concurrency', {
588+
default: 1,
589+
type: 'number',
590+
desc: 'Maximum number of asset builds to run in parallel',
591+
requiresArg: true,
592+
})
587593
.option('asset-prebuild', {
588594
default: true,
589595
type: 'boolean',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export async function commandLineArgumentsToSettings(ioHelper: IoHelper, argv: A
321321
rollback: argv.rollback,
322322
notices: argv.notices,
323323
assetParallelism: argv['asset-parallelism'],
324+
assetBuildConcurrency: argv['asset-build-concurrency'],
324325
assetPrebuild: argv['asset-prebuild'],
325326
ignoreNoStacks: argv['ignore-no-stacks'],
326327
hotswap: {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,15 @@ export interface DeployOptions {
911911
*/
912912
readonly assetParallelism?: boolean;
913913

914+
/**
915+
* Maximum number of asset builds to run in parallel
916+
*
917+
* This setting only has an effect if `assetParallelism` is set to `true`.
918+
*
919+
* @default 1
920+
*/
921+
readonly assetBuildConcurrency?: number;
922+
914923
/**
915924
* Whether to build all assets before deploying the first stack (useful for failing Docker builds)
916925
*

0 commit comments

Comments
 (0)