Skip to content

Commit f7ef343

Browse files
committed
fix(cli): specifying --quiet does not suppress asset building and publishing logs
1 parent 399b6bb commit f7ef343

6 files changed

Lines changed: 44 additions & 12 deletions

File tree

packages/aws-cdk/lib/util/asset-publishing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export async function publishAssets(
5454
publishInParallel: options.parallel ?? true,
5555
buildAssets: options.buildAssets ?? true,
5656
publishAssets: true,
57+
quiet: options.quiet,
5758
});
5859
await publisher.publish();
5960
if (publisher.hasFailures) {

packages/cdk-assets/lib/private/asset-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ export interface IHandlerHost {
2828
readonly dockerFactory: DockerFactory;
2929

3030
emitMessage(type: EventType, m: string): void;
31+
}
32+
33+
export interface IHandlerOptions {
34+
readonly quiet?: boolean;
3135
}

packages/cdk-assets/lib/private/docker.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ interface BuildOptions {
2121
readonly outputs?: string[];
2222
readonly cacheFrom?: DockerCacheOption[];
2323
readonly cacheTo?: DockerCacheOption;
24+
readonly quiet?: boolean;
25+
}
26+
27+
interface PushOptions {
28+
readonly tag: string;
29+
readonly quiet?: boolean;
2430
}
2531

2632
export interface DockerCredentialsConfig {
@@ -101,7 +107,10 @@ export class Docker {
101107
...options.cacheTo ? ['--cache-to', this.cacheOptionToFlag(options.cacheTo)] : [],
102108
'.',
103109
];
104-
await this.execute(buildCommand, { cwd: options.directory });
110+
await this.execute(buildCommand, {
111+
cwd: options.directory,
112+
quiet: options.quiet,
113+
});
105114
}
106115

107116
/**
@@ -128,8 +137,8 @@ export class Docker {
128137
await this.execute(['tag', sourceTag, targetTag]);
129138
}
130139

131-
public async push(tag: string) {
132-
await this.execute(['push', tag]);
140+
public async push(options: PushOptions) {
141+
await this.execute(['push', options.tag], { quiet: options.quiet });
133142
}
134143

135144
/**

packages/cdk-assets/lib/private/handlers/container-images.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DockerImageDestination } from '@aws-cdk/cloud-assembly-schema';
33
import type * as AWS from 'aws-sdk';
44
import { DockerImageManifestEntry } from '../../asset-manifest';
55
import { EventType } from '../../progress';
6-
import { IAssetHandler, IHandlerHost } from '../asset-handler';
6+
import { IAssetHandler, IHandlerHost, IHandlerOptions } from '../asset-handler';
77
import { Docker } from '../docker';
88
import { replaceAwsPlaceholders } from '../placeholders';
99
import { shell } from '../shell';
@@ -21,7 +21,8 @@ export class ContainerImageAssetHandler implements IAssetHandler {
2121
constructor(
2222
private readonly workDir: string,
2323
private readonly asset: DockerImageManifestEntry,
24-
private readonly host: IHandlerHost) {
24+
private readonly host: IHandlerHost,
25+
private readonly options: IHandlerOptions) {
2526
}
2627

2728
public async build(): Promise<void> {
@@ -36,7 +37,9 @@ export class ContainerImageAssetHandler implements IAssetHandler {
3637
ecr: initOnce.ecr,
3738
});
3839

39-
const builder = new ContainerImageBuilder(dockerForBuilding, this.workDir, this.asset, this.host);
40+
const builder = new ContainerImageBuilder(dockerForBuilding, this.workDir, this.asset, this.host, {
41+
quiet: this.options.quiet,
42+
});
4043
const localTagName = await builder.build();
4144

4245
if (localTagName === undefined || this.host.aborted) { return; }
@@ -70,7 +73,7 @@ export class ContainerImageAssetHandler implements IAssetHandler {
7073
if (this.host.aborted) { return; }
7174

7275
this.host.emitMessage(EventType.UPLOAD, `Push ${initOnce.imageUri}`);
73-
await dockerForPushing.push(initOnce.imageUri);
76+
await dockerForPushing.push({ tag: initOnce.imageUri, quite: this.options.quiet });
7477
}
7578

7679
private async initOnce(options: { quiet?: boolean } = {}): Promise<ContainerImageAssetHandlerInit> {
@@ -120,12 +123,17 @@ export class ContainerImageAssetHandler implements IAssetHandler {
120123
}
121124
}
122125

126+
interface ContainerImageBuilderOptions {
127+
readonly quiet?: boolean;
128+
}
129+
123130
class ContainerImageBuilder {
124131
constructor(
125132
private readonly docker: Docker,
126133
private readonly workDir: string,
127134
private readonly asset: DockerImageManifestEntry,
128-
private readonly host: IHandlerHost) {
135+
private readonly host: IHandlerHost,
136+
private readonly options: ContainerImageBuilderOptions) {
129137
}
130138

131139
async build(): Promise<string | undefined> {
@@ -188,6 +196,7 @@ class ContainerImageBuilder {
188196
outputs: source.dockerOutputs,
189197
cacheFrom: source.cacheFrom,
190198
cacheTo: source.cacheTo,
199+
quiet: this.options.quiet,
191200
});
192201
}
193202

packages/cdk-assets/lib/private/handlers/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { ContainerImageAssetHandler } from './container-images';
22
import { FileAssetHandler } from './files';
33
import { AssetManifest, DockerImageManifestEntry, FileManifestEntry, IManifestEntry } from '../../asset-manifest';
4-
import { IAssetHandler, IHandlerHost } from '../asset-handler';
4+
import { IAssetHandler, IHandlerHost, IHandlerOptions } from '../asset-handler';
55

6-
export function makeAssetHandler(manifest: AssetManifest, asset: IManifestEntry, host: IHandlerHost): IAssetHandler {
6+
export function makeAssetHandler(manifest: AssetManifest, asset: IManifestEntry, host: IHandlerHost, options: IHandlerOptions): IAssetHandler {
77
if (asset instanceof FileManifestEntry) {
88
return new FileAssetHandler(manifest.directory, asset, host);
99
}
1010
if (asset instanceof DockerImageManifestEntry) {
11-
return new ContainerImageAssetHandler(manifest.directory, asset, host);
11+
return new ContainerImageAssetHandler(manifest.directory, asset, host, options);
1212
}
1313

1414
throw new Error(`Unrecognized asset type: '${asset}'`);

packages/cdk-assets/lib/publishing.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export interface AssetPublishingOptions {
4545
* @default true
4646
*/
4747
readonly publishAssets?: boolean;
48+
49+
/**
50+
* Whether to print publishing logs
51+
*
52+
* @default true
53+
*/
54+
readonly quiet?: boolean;
4855
}
4956

5057
/**
@@ -240,7 +247,9 @@ export class AssetPublishing implements IPublishProgress {
240247
if (existing) {
241248
return existing;
242249
}
243-
const ret = makeAssetHandler(this.manifest, asset, this.handlerHost);
250+
const ret = makeAssetHandler(this.manifest, asset, this.handlerHost, {
251+
quiet: this.options.quiet,
252+
});
244253
this.handlerCache.set(asset, ret);
245254
return ret;
246255
}

0 commit comments

Comments
 (0)