diff --git a/packages/aws-cdk/lib/util/asset-publishing.ts b/packages/aws-cdk/lib/util/asset-publishing.ts index 7b4c4f943d9ff..47d83eb5c691c 100644 --- a/packages/aws-cdk/lib/util/asset-publishing.ts +++ b/packages/aws-cdk/lib/util/asset-publishing.ts @@ -54,6 +54,7 @@ export async function publishAssets( publishInParallel: options.parallel ?? true, buildAssets: options.buildAssets ?? true, publishAssets: true, + quiet: options.quiet, }); await publisher.publish(); if (publisher.hasFailures) { diff --git a/packages/cdk-assets/lib/private/asset-handler.ts b/packages/cdk-assets/lib/private/asset-handler.ts index 5baa32d9d52f4..baafb3cd0317e 100644 --- a/packages/cdk-assets/lib/private/asset-handler.ts +++ b/packages/cdk-assets/lib/private/asset-handler.ts @@ -28,4 +28,11 @@ export interface IHandlerHost { readonly dockerFactory: DockerFactory; emitMessage(type: EventType, m: string): void; -} \ No newline at end of file +} + +export interface IHandlerOptions { + /** + * Suppress all output + */ + readonly quiet?: boolean; +} diff --git a/packages/cdk-assets/lib/private/docker.ts b/packages/cdk-assets/lib/private/docker.ts index 4dae410047497..27b7f1ed9b911 100644 --- a/packages/cdk-assets/lib/private/docker.ts +++ b/packages/cdk-assets/lib/private/docker.ts @@ -21,6 +21,12 @@ interface BuildOptions { readonly outputs?: string[]; readonly cacheFrom?: DockerCacheOption[]; readonly cacheTo?: DockerCacheOption; + readonly quiet?: boolean; +} + +interface PushOptions { + readonly tag: string; + readonly quiet?: boolean; } export interface DockerCredentialsConfig { @@ -101,7 +107,10 @@ export class Docker { ...options.cacheTo ? ['--cache-to', this.cacheOptionToFlag(options.cacheTo)] : [], '.', ]; - await this.execute(buildCommand, { cwd: options.directory }); + await this.execute(buildCommand, { + cwd: options.directory, + quiet: options.quiet, + }); } /** @@ -128,8 +137,8 @@ export class Docker { await this.execute(['tag', sourceTag, targetTag]); } - public async push(tag: string) { - await this.execute(['push', tag]); + public async push(options: PushOptions) { + await this.execute(['push', options.tag], { quiet: options.quiet }); } /** diff --git a/packages/cdk-assets/lib/private/handlers/container-images.ts b/packages/cdk-assets/lib/private/handlers/container-images.ts index 670c813dd8b20..3b21e922aec66 100644 --- a/packages/cdk-assets/lib/private/handlers/container-images.ts +++ b/packages/cdk-assets/lib/private/handlers/container-images.ts @@ -3,7 +3,7 @@ import { DockerImageDestination } from '@aws-cdk/cloud-assembly-schema'; import type * as AWS from 'aws-sdk'; import { DockerImageManifestEntry } from '../../asset-manifest'; import { EventType } from '../../progress'; -import { IAssetHandler, IHandlerHost } from '../asset-handler'; +import { IAssetHandler, IHandlerHost, IHandlerOptions } from '../asset-handler'; import { Docker } from '../docker'; import { replaceAwsPlaceholders } from '../placeholders'; import { shell } from '../shell'; @@ -21,7 +21,8 @@ export class ContainerImageAssetHandler implements IAssetHandler { constructor( private readonly workDir: string, private readonly asset: DockerImageManifestEntry, - private readonly host: IHandlerHost) { + private readonly host: IHandlerHost, + private readonly options: IHandlerOptions) { } public async build(): Promise { @@ -36,7 +37,9 @@ export class ContainerImageAssetHandler implements IAssetHandler { ecr: initOnce.ecr, }); - const builder = new ContainerImageBuilder(dockerForBuilding, this.workDir, this.asset, this.host); + const builder = new ContainerImageBuilder(dockerForBuilding, this.workDir, this.asset, this.host, { + quiet: this.options.quiet, + }); const localTagName = await builder.build(); if (localTagName === undefined || this.host.aborted) { return; } @@ -70,7 +73,7 @@ export class ContainerImageAssetHandler implements IAssetHandler { if (this.host.aborted) { return; } this.host.emitMessage(EventType.UPLOAD, `Push ${initOnce.imageUri}`); - await dockerForPushing.push(initOnce.imageUri); + await dockerForPushing.push({ tag: initOnce.imageUri, quiet: this.options.quiet }); } private async initOnce(options: { quiet?: boolean } = {}): Promise { @@ -120,12 +123,17 @@ export class ContainerImageAssetHandler implements IAssetHandler { } } +interface ContainerImageBuilderOptions { + readonly quiet?: boolean; +} + class ContainerImageBuilder { constructor( private readonly docker: Docker, private readonly workDir: string, private readonly asset: DockerImageManifestEntry, - private readonly host: IHandlerHost) { + private readonly host: IHandlerHost, + private readonly options: ContainerImageBuilderOptions) { } async build(): Promise { @@ -188,6 +196,7 @@ class ContainerImageBuilder { outputs: source.dockerOutputs, cacheFrom: source.cacheFrom, cacheTo: source.cacheTo, + quiet: this.options.quiet, }); } diff --git a/packages/cdk-assets/lib/private/handlers/index.ts b/packages/cdk-assets/lib/private/handlers/index.ts index 1a46247674468..2b3c767eb4963 100644 --- a/packages/cdk-assets/lib/private/handlers/index.ts +++ b/packages/cdk-assets/lib/private/handlers/index.ts @@ -1,14 +1,14 @@ import { ContainerImageAssetHandler } from './container-images'; import { FileAssetHandler } from './files'; import { AssetManifest, DockerImageManifestEntry, FileManifestEntry, IManifestEntry } from '../../asset-manifest'; -import { IAssetHandler, IHandlerHost } from '../asset-handler'; +import { IAssetHandler, IHandlerHost, IHandlerOptions } from '../asset-handler'; -export function makeAssetHandler(manifest: AssetManifest, asset: IManifestEntry, host: IHandlerHost): IAssetHandler { +export function makeAssetHandler(manifest: AssetManifest, asset: IManifestEntry, host: IHandlerHost, options: IHandlerOptions): IAssetHandler { if (asset instanceof FileManifestEntry) { return new FileAssetHandler(manifest.directory, asset, host); } if (asset instanceof DockerImageManifestEntry) { - return new ContainerImageAssetHandler(manifest.directory, asset, host); + return new ContainerImageAssetHandler(manifest.directory, asset, host, options); } throw new Error(`Unrecognized asset type: '${asset}'`); diff --git a/packages/cdk-assets/lib/publishing.ts b/packages/cdk-assets/lib/publishing.ts index 9e38308cd7e66..03cf2683f3293 100644 --- a/packages/cdk-assets/lib/publishing.ts +++ b/packages/cdk-assets/lib/publishing.ts @@ -45,6 +45,13 @@ export interface AssetPublishingOptions { * @default true */ readonly publishAssets?: boolean; + + /** + * Whether to print publishing logs + * + * @default true + */ + readonly quiet?: boolean; } /** @@ -240,7 +247,9 @@ export class AssetPublishing implements IPublishProgress { if (existing) { return existing; } - const ret = makeAssetHandler(this.manifest, asset, this.handlerHost); + const ret = makeAssetHandler(this.manifest, asset, this.handlerHost, { + quiet: this.options.quiet, + }); this.handlerCache.set(asset, ret); return ret; }