Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@aws-cdk/cx-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@
"semver": "^7.7.1"
},
"peerDependencies": {
"@aws-cdk/cloud-assembly-schema": "^40.6.0"
"@aws-cdk/cloud-assembly-schema": "^41.0.0"
},
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/cloud-assembly-schema": "^40.7.0",
"@aws-cdk/cloud-assembly-schema": "^41.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^29.5.14",
"@types/mock-fs": "^4.13.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/integ-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"dependencies": {
"chokidar": "^3.6.0",
"@aws-cdk/cloud-assembly-schema": "^40.7.0",
"@aws-cdk/cloud-assembly-schema": "^41.0.0",
"@aws-sdk/client-cloudformation": "^3",
"@aws-cdk/cloudformation-diff": "^2",
"@aws-cdk/cx-api": "0.0.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk-lib/aws-ecr-assets/lib/_construct-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Construct } from 'constructs';
import { Stack } from '../../core/lib/stack';

export function stackRelativeConstructPath(c: Construct) {
const scopes = c.node.scopes;
const stackIndex = scopes.indexOf(Stack.of(c));
return scopes.slice(stackIndex + 1).map(x => x.node.id).join('/');
}
25 changes: 25 additions & 0 deletions packages/aws-cdk-lib/aws-ecr-assets/lib/image-asset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { Construct } from 'constructs';
import { stackRelativeConstructPath } from './_construct-path';
import { FingerprintOptions, FollowMode, IAsset } from '../../assets';
import * as ecr from '../../aws-ecr';
import { Annotations, AssetStaging, FeatureFlags, FileFingerprintOptions, IgnoreMode, Stack, SymlinkFollowMode, Token, Stage, CfnResource } from '../../core';
Expand Down Expand Up @@ -314,6 +315,29 @@ export interface DockerImageAssetOptions extends FingerprintOptions, FileFingerp
* @default - cache is used
*/
readonly cacheDisabled?: boolean;

/**
* A display name for this asset
*
* If supplied, the display name will be used in locations where the asset
* identifier is printed, like in the CLI progress information. If the same
* asset is added multiple times, the display name of the first occurrence is
* used.
*
* If `assetName` is given, it will also be used as the default `displayName`.
* Otherwise, the default is the construct path of the ImageAsset construct,
* with respect to the enclosing stack. If the asset is produced by a
* construct helper function (such as `lambda.Code.fromAssetImage()`), this
* will look like `MyFunction/AssetImage`.
*
* We use the stack-relative construct path so that in the common case where
* you have multiple stacks with the same asset, we won't show something like
* `/MyBetaStack/MyFunction/Code` when you are actually deploying to
* production.
*
* @default - Stack-relative construct path
*/
readonly displayName?: string;
}

/**
Expand Down Expand Up @@ -534,6 +558,7 @@ export class DockerImageAsset extends Construct implements IAsset {
dockerCacheFrom: this.dockerCacheFrom,
dockerCacheTo: this.dockerCacheTo,
dockerCacheDisabled: this.dockerCacheDisabled,
displayName: props.displayName ?? props.assetName ?? stackRelativeConstructPath(this),
});

this.repository = ecr.Repository.fromRepositoryName(this, 'Repository', location.repositoryName);
Expand Down
24 changes: 24 additions & 0 deletions packages/aws-cdk-lib/aws-ecr-assets/lib/tarball-asset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { Construct } from 'constructs';
import { stackRelativeConstructPath } from './_construct-path';
import { IAsset } from '../../assets';
import * as ecr from '../../aws-ecr';
import { AssetStaging, Stack, Stage } from '../../core';
Expand All @@ -17,6 +18,28 @@ export interface TarballImageAssetProps {
* is located as a resource inside your project.
*/
readonly tarballFile: string;

/**
* A display name for this asset
*
* If supplied, the display name will be used in locations where the asset
* identifier is printed, like in the CLI progress information. If the same
* asset is added multiple times, the display name of the first occurrence is
* used.
*
* The default is the construct path of the `TarballImageAsset` construct,
* with respect to the enclosing stack. If the asset is produced by a
* construct helper function (such as `lambda.Code.fromAssetImage()`), this
* will look like `MyFunction/AssetImage`.
*
* We use the stack-relative construct path so that in the common case where
* you have multiple stacks with the same asset, we won't show something like
* `/MyBetaStack/MyFunction/Code` when you are actually deploying to
* production.
*
* @default - Stack-relative construct path
*/
readonly displayName?: string;
}

/**
Expand Down Expand Up @@ -79,6 +102,7 @@ export class TarballImageAsset extends Construct implements IAsset {
'-c',
`docker load -i ${relativePathInOutDir} | tail -n 1 | sed "s/Loaded image: //g"`,
],
displayName: props.displayName ?? stackRelativeConstructPath(this),
});

this.repository = ecr.Repository.fromRepositoryName(this, 'Repository', location.repositoryName);
Expand Down
32 changes: 32 additions & 0 deletions packages/aws-cdk-lib/aws-s3-assets/lib/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ export interface AssetOptions extends CopyOptions, cdk.FileCopyOptions, cdk.Asse
* @default - the default server-side encryption with Amazon S3 managed keys(SSE-S3) key will be used.
*/
readonly sourceKMSKey?: kms.IKey;

/**
* A display name for this asset
*
* If supplied, the display name will be used in locations where the asset
* identifier is printed, like in the CLI progress information. If the same
* asset is added multiple times, the display name of the first occurrence is
* used.
*
* The default is the construct path of the Asset construct, with respect to
* the enclosing stack. If the asset is produced by a construct helper
* function (such as `lambda.Code.fromAsset()`), this will look like
* `MyFunction/Code`.
*
* We use the stack-relative construct path so that in the common case where
* you have multiple stacks with the same asset, we won't show something like
* `/MyBetaStack/MyFunction/Code` when you are actually deploying to
* production.
*
* @default - Stack-relative construct path
*/
readonly displayName?: string;
}

export interface AssetProps extends AssetOptions {
Expand Down Expand Up @@ -173,6 +195,7 @@ export class Asset extends Construct implements cdk.IAsset {
sourceHash: this.sourceHash,
fileName: this.assetPath,
deployTime: props.deployTime,
displayName: props.displayName ?? this.defaultDisplayName(),
});

this.s3BucketName = location.bucketName;
Expand Down Expand Up @@ -231,4 +254,13 @@ export class Asset extends Construct implements cdk.IAsset {
// version (for example, when using Lambda traffic shifting).
this.bucket.grantRead(grantee);
}

/**
* Return the stack-relative cosntruct path of this construct
*/
private defaultDisplayName(): string {
const scopes = this.node.scopes;
const stackIndex = scopes.indexOf(cdk.Stack.of(this));
return scopes.slice(stackIndex + 1).map(x => x.node.id).join('/');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class ProductStack extends cdk.Stack {
packaging: cdk.FileAssetPackaging.FILE,
sourceHash: templateHash,
fileName: this.templateFile,
displayName: `${this.node.path} Template`,
}).httpUrl;

if (this._parentProductStackHistory) {
Expand Down
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/core/lib/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ export interface FileAssetSource {
* @default false
*/
readonly deployTime?: boolean;

/**
* A display name for this asset
*
* If supplied, the display name will be used in locations where the asset
* identifier is printed, like in the CLI progress information.
*
* @default - The asset hash is used to display the asset
*/
readonly displayName?: string;
}

export interface DockerImageAssetSource {
Expand Down Expand Up @@ -291,6 +301,16 @@ export interface DockerImageAssetSource {
* @default - cache is used
*/
readonly dockerCacheDisabled?: boolean;

/**
* A display name for this asset
*
* If supplied, the display name will be used in locations where the asset
* identifier is printed, like in the CLI progress information.
*
* @default - The asset hash is used to display the asset
*/
readonly displayName?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export abstract class CustomResourceProviderBase extends Construct {
fileName: assetFileName,
sourceHash: staging.assetHash,
packaging: FileAssetPackaging.ZIP_DIRECTORY,
displayName: `${this.node.path} Code`,
});

this._codeHash = staging.assetHash;
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/core/lib/nested-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class NestedStack extends Stack {
packaging: FileAssetPackaging.FILE,
sourceHash: templateHash,
fileName: this.templateFile,
displayName: `${this.stackName} template`,
});

this.addResourceMetadata(this.resource, 'TemplateURL');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AssetManifestBuilder {
* Derive the region from the stack, use the asset hash as the key, copy the
* file extension over, and set the prefix.
*/
public defaultAddFileAsset(stack: Stack, asset: FileAssetSource, target: AssetManifestFileDestination) {
public defaultAddFileAsset(stack: Stack, asset: FileAssetSource, target: AssetManifestFileDestination, options?: AddFileAssetOptions) {
validateFileAssetSource(asset);

const extension =
Expand All @@ -45,7 +45,7 @@ export class AssetManifestBuilder {
assumeRoleArn: target.role?.assumeRoleArn,
assumeRoleExternalId: target.role?.assumeRoleExternalId,
assumeRoleAdditionalOptions: target.role?.assumeRoleAdditionalOptions,
});
}, options);
}

/**
Expand All @@ -57,6 +57,7 @@ export class AssetManifestBuilder {
stack: Stack,
asset: DockerImageAssetSource,
target: AssetManifestDockerImageDestination,
options?: AddDockerImageAssetOptions,
) {
validateDockerImageAssetSource(asset);
const imageTag = `${target.dockerTagPrefix ?? ''}${asset.sourceHash}`;
Expand Down Expand Up @@ -84,17 +85,18 @@ export class AssetManifestBuilder {
assumeRoleArn: target.role?.assumeRoleArn,
assumeRoleExternalId: target.role?.assumeRoleExternalId,
assumeRoleAdditionalOptions: target.role?.assumeRoleAdditionalOptions,
});
}, options);
}

/**
* Add a file asset source and destination to the manifest
*
* sourceHash should be unique for every source.
*/
public addFileAsset(stack: Stack, sourceHash: string, source: cxschema.FileSource, dest: cxschema.FileDestination) {
public addFileAsset(stack: Stack, sourceHash: string, source: cxschema.FileSource, dest: cxschema.FileDestination, options?: AddFileAssetOptions) {
if (!this.files[sourceHash]) {
this.files[sourceHash] = {
displayName: options?.displayName,
source,
destinations: {},
};
Expand All @@ -108,9 +110,16 @@ export class AssetManifestBuilder {
*
* sourceHash should be unique for every source.
*/
public addDockerImageAsset(stack: Stack, sourceHash: string, source: cxschema.DockerImageSource, dest: cxschema.DockerImageDestination) {
public addDockerImageAsset(
stack: Stack,
sourceHash: string,
source: cxschema.DockerImageSource,
dest: cxschema.DockerImageDestination,
options?: AddDockerImageAssetOptions,
) {
if (!this.dockerImages[sourceHash]) {
this.dockerImages[sourceHash] = {
displayName: options?.displayName,
source,
destinations: {},
};
Expand Down Expand Up @@ -170,6 +179,30 @@ export class AssetManifestBuilder {
}
}

/**
* Options for the addFileAsset operation
*/
export interface AddFileAssetOptions {
/**
* A display name to associate with the asset
*
* @default - No display name
*/
readonly displayName?: string;
}

/**
* Options for the addDockerImageAsset operation
*/
export interface AddDockerImageAssetOptions {
/**
* A display name to associate with the asset
*
* @default - No display name
*/
readonly displayName?: string;
}

/**
* The destination for a file asset, when it is given to the AssetManifestBuilder
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export class CliCredentialsStackSynthesizer extends StackSynthesizer implements
const location = this.assetManifest.defaultAddFileAsset(this.boundStack, asset, {
bucketName: this.bucketName,
bucketPrefix: this.bucketPrefix,
}, {
displayName: asset.displayName,
});
return this.cloudFormationLocationFromFileAsset(location);
}
Expand All @@ -169,6 +171,8 @@ export class CliCredentialsStackSynthesizer extends StackSynthesizer implements
const location = this.assetManifest.defaultAddDockerImageAsset(this.boundStack, asset, {
repositoryName: this.repositoryName,
dockerTagPrefix: this.dockerTagPrefix,
}, {
displayName: asset.displayName,
});
return this.cloudFormationLocationFromDockerImageAsset(location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ export class DefaultStackSynthesizer extends StackSynthesizer implements IReusab
assumeRoleExternalId: this.props.fileAssetPublishingExternalId,
assumeRoleAdditionalOptions: this.props.fileAssetPublishingRoleAdditionalOptions,
} : undefined,
}, {
displayName: asset.displayName,
});
return this.cloudFormationLocationFromFileAsset(location);
}
Expand All @@ -455,6 +457,8 @@ export class DefaultStackSynthesizer extends StackSynthesizer implements IReusab
assumeRoleExternalId: this.props.imageAssetPublishingExternalId,
assumeRoleAdditionalOptions: this.props.imageAssetPublishingRoleAdditionalOptions,
} : undefined,
}, {
displayName: asset.displayName,
});
return this.cloudFormationLocationFromDockerImageAsset(location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ function stackTemplateFileAsset(stack: Stack, session: ISynthesisSession): FileA
packaging: FileAssetPackaging.FILE,
sourceHash,
deployTime: true,
displayName: `${stack.stackName} Template`,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"dependencies": {
"@aws-cdk/asset-awscli-v1": "^2.2.227",
"@aws-cdk/asset-node-proxy-agent-v6": "^2.1.0",
"@aws-cdk/cloud-assembly-schema": "^40.7.0",
"@aws-cdk/cloud-assembly-schema": "^41.0.0",
"@balena/dockerignore": "^1.0.2",
"case": "1.6.3",
"fs-extra": "^11.3.0",
Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@
"@aws-cdk/service-spec-types" "^0.0.128"
"@cdklabs/tskb" "^0.0.3"

"@aws-cdk/cloud-assembly-schema@^40.7.0":
version "40.7.0"
resolved "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-40.7.0.tgz#1d53d55fc616477965338f0de98192ec3a3ed9bc"
integrity sha512-00wVKn9pOOGXbeNwA4E8FUFt0zIB4PmSO7PvIiDWgpaFX3G/sWyy0A3s6bg/n2Yvkghu8r4a8ckm+mAzkAYmfA==
dependencies:
jsonschema "~1.4.1"
semver "^7.7.1"

"@aws-cdk/cloud-assembly-schema@^41.0.0":
version "41.0.0"
resolved "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-41.0.0.tgz#0d6fc77dd22d78f181a462b89f769497c3898065"
Expand Down
Loading