Skip to content

Commit 48963f7

Browse files
authored
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 319cfcd commit 48963f7

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
import { Construct } from 'constructs';
88

@@ -13,7 +13,7 @@ import { Construct as CoreConstruct } from '@aws-cdk/core';
1313
/**
1414
* Options for DockerImageAsset
1515
*/
16-
export interface DockerImageAssetOptions extends assets.FingerprintOptions {
16+
export interface DockerImageAssetOptions extends assets.FingerprintOptions, FileFingerprintOptions {
1717
/**
1818
* ECR repository name
1919
*
@@ -141,8 +141,9 @@ export class DockerImageAsset extends CoreConstruct implements assets.IAsset {
141141
// deletion of the ECR repository the app used).
142142
extraHash.version = '1.21.0';
143143

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { toSymlinkFollow } from './compat';
1212
// eslint-disable-next-line no-duplicate-imports, import/order
1313
import { Construct as CoreConstruct } from '@aws-cdk/core';
1414

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

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)