Skip to content

Commit 098bfe4

Browse files
skinny85Niranjan Jayakar
authored andcommitted
chore: add new interfaces for Assets (#13356)
This is a re-submit of the PR #12700, which had to be reverted because of JSII issue aws/jsii#2256. Since that issue has been fixed in JSII version `1.23.0`, which is what we currently use, re-introduce the changes from that PR. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e6ba035 commit 098bfe4

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

packages/@aws-cdk/assets/lib/fs/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface CopyOptions {
1010
* A strategy for how to handle symlinks.
1111
*
1212
* @default Never
13+
* @deprecated use `followSymlinks` instead
1314
*/
1415
readonly follow?: FollowMode;
1516

packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import * as assets from '@aws-cdk/assets';
44
import * as ecr from '@aws-cdk/aws-ecr';
5-
import { Annotations, FeatureFlags, IgnoreMode, Stack, Token } from '@aws-cdk/core';
5+
import { Annotations, AssetStaging, FeatureFlags, FileFingerprintOptions, IgnoreMode, Stack, SymlinkFollowMode, Token } from '@aws-cdk/core';
66
import * as cxapi from '@aws-cdk/cx-api';
77

88
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
@@ -12,7 +12,7 @@ import { Construct } from 'constructs';
1212
/**
1313
* Options for DockerImageAsset
1414
*/
15-
export interface DockerImageAssetOptions extends assets.FingerprintOptions {
15+
export interface DockerImageAssetOptions extends assets.FingerprintOptions, FileFingerprintOptions {
1616
/**
1717
* ECR repository name
1818
*
@@ -140,8 +140,9 @@ export class DockerImageAsset extends Construct implements assets.IAsset {
140140
// deletion of the ECR repository the app used).
141141
extraHash.version = '1.21.0';
142142

143-
const staging = new assets.Staging(this, 'Staging', {
143+
const staging = new AssetStaging(this, 'Staging', {
144144
...props,
145+
follow: props.followSymlinks ?? toSymlinkFollow(props.follow),
145146
exclude,
146147
ignoreMode,
147148
sourcePath: dir,
@@ -184,3 +185,13 @@ function validateBuildArgs(buildArgs?: { [key: string]: string }) {
184185
}
185186
}
186187
}
188+
189+
function toSymlinkFollow(follow?: assets.FollowMode): SymlinkFollowMode | undefined {
190+
switch (follow) {
191+
case undefined: return undefined;
192+
case assets.FollowMode.NEVER: return SymlinkFollowMode.NEVER;
193+
case assets.FollowMode.ALWAYS: return SymlinkFollowMode.ALWAYS;
194+
case assets.FollowMode.BLOCK_EXTERNAL: return SymlinkFollowMode.BLOCK_EXTERNAL;
195+
case assets.FollowMode.EXTERNAL: return SymlinkFollowMode.EXTERNAL;
196+
}
197+
}

packages/@aws-cdk/aws-s3-assets/lib/asset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { toSymlinkFollow } from './compat';
1111

1212
const ARCHIVE_EXTENSIONS = ['.zip', '.jar'];
1313

14-
export interface AssetOptions extends assets.CopyOptions, cdk.AssetOptions {
14+
export interface AssetOptions extends assets.CopyOptions, cdk.FileCopyOptions, cdk.AssetOptions {
1515
/**
1616
* A list of principals that should be able to read this asset from S3.
1717
* You can use `asset.grantRead(principal)` to grant read permissions later.
@@ -124,7 +124,7 @@ export class Asset extends Construct implements cdk.IAsset {
124124
const staging = new cdk.AssetStaging(this, 'Stage', {
125125
...props,
126126
sourcePath: path.resolve(props.path),
127-
follow: toSymlinkFollow(props.follow),
127+
follow: props.followSymlinks ?? toSymlinkFollow(props.follow),
128128
assetHash: props.assetHash ?? props.sourceHash,
129129
});
130130

packages/@aws-cdk/core/lib/fs/options.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,9 @@ export enum IgnoreMode {
5656
* context flag is set.
5757
*/
5858
DOCKER = 'docker'
59-
};
60-
61-
/**
62-
* Obtains applied when copying directories into the staging location.
63-
*/
64-
export interface CopyOptions {
65-
/**
66-
* A strategy for how to handle symlinks.
67-
*
68-
* @default SymlinkFollowMode.NEVER
69-
*/
70-
readonly follow?: SymlinkFollowMode;
59+
}
7160

61+
interface FileOptions {
7262
/**
7363
* Glob patterns to exclude from the copy.
7464
*
@@ -85,9 +75,30 @@ export interface CopyOptions {
8575
}
8676

8777
/**
88-
* Options related to calculating source hash.
78+
* Options applied when copying directories
79+
*/
80+
export interface CopyOptions extends FileOptions {
81+
/**
82+
* A strategy for how to handle symlinks.
83+
*
84+
* @default SymlinkFollowMode.NEVER
85+
*/
86+
readonly follow?: SymlinkFollowMode;
87+
}
88+
89+
/**
90+
* Options applied when copying directories into the staging location.
8991
*/
90-
export interface FingerprintOptions extends CopyOptions {
92+
export interface FileCopyOptions extends FileOptions {
93+
/**
94+
* A strategy for how to handle symlinks.
95+
*
96+
* @default SymlinkFollowMode.NEVER
97+
*/
98+
readonly followSymlinks?: SymlinkFollowMode;
99+
}
100+
101+
interface ExtraHashOptions {
91102
/**
92103
* Extra information to encode into the fingerprint (e.g. build instructions
93104
* and other inputs)
@@ -96,3 +107,15 @@ export interface FingerprintOptions extends CopyOptions {
96107
*/
97108
readonly extraHash?: string;
98109
}
110+
111+
/**
112+
* Options related to calculating source hash.
113+
*/
114+
export interface FingerprintOptions extends CopyOptions, ExtraHashOptions {
115+
}
116+
117+
/**
118+
* Options related to calculating source hash.
119+
*/
120+
export interface FileFingerprintOptions extends FileCopyOptions, ExtraHashOptions {
121+
}

0 commit comments

Comments
 (0)