Skip to content

Commit 8fb30ea

Browse files
authored
chore: add new interfaces for Assets (#13807)
This is a re-submit of the PR #13356, which had to be reverted because of JSII issue aws/jsii#2653. Since that issue has been fixed in JSII version `1.26.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 37a5502 commit 8fb30ea

File tree

4 files changed

+55
-20
lines changed

4 files changed

+55
-20
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: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33
import * as ecr from '@aws-cdk/aws-ecr';
4-
import { Annotations, FeatureFlags, IgnoreMode, Stack, Token } from '@aws-cdk/core';
4+
import { Annotations, AssetStaging, FeatureFlags, FileFingerprintOptions, IgnoreMode, Stack, SymlinkFollowMode, Token } from '@aws-cdk/core';
55
import * as cxapi from '@aws-cdk/cx-api';
66
import { Construct } from 'constructs';
77

88
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
99
// eslint-disable-next-line
10-
import { FingerprintOptions, IAsset, Staging } from '@aws-cdk/assets';
10+
import { FingerprintOptions, FollowMode, IAsset } from '@aws-cdk/assets';
1111
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
1212
// eslint-disable-next-line no-duplicate-imports, import/order
1313
import { Construct as CoreConstruct } from '@aws-cdk/core';
1414

1515
/**
1616
* Options for DockerImageAsset
1717
*/
18-
export interface DockerImageAssetOptions extends FingerprintOptions {
18+
export interface DockerImageAssetOptions extends FingerprintOptions, FileFingerprintOptions {
1919
/**
2020
* ECR repository name
2121
*
@@ -156,8 +156,9 @@ export class DockerImageAsset extends CoreConstruct implements IAsset {
156156
// deletion of the ECR repository the app used).
157157
extraHash.version = '1.21.0';
158158

159-
const staging = new Staging(this, 'Staging', {
159+
const staging = new AssetStaging(this, 'Staging', {
160160
...props,
161+
follow: props.followSymlinks ?? toSymlinkFollow(props.follow),
161162
exclude,
162163
ignoreMode,
163164
sourcePath: dir,
@@ -200,3 +201,13 @@ function validateBuildArgs(buildArgs?: { [key: string]: string }) {
200201
}
201202
}
202203
}
204+
205+
function toSymlinkFollow(follow?: FollowMode): SymlinkFollowMode | undefined {
206+
switch (follow) {
207+
case undefined: return undefined;
208+
case FollowMode.NEVER: return SymlinkFollowMode.NEVER;
209+
case FollowMode.ALWAYS: return SymlinkFollowMode.ALWAYS;
210+
case FollowMode.BLOCK_EXTERNAL: return SymlinkFollowMode.BLOCK_EXTERNAL;
211+
case FollowMode.EXTERNAL: return SymlinkFollowMode.EXTERNAL;
212+
}
213+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CopyOptions } from '@aws-cdk/assets';
1414
// eslint-disable-next-line no-duplicate-imports, import/order
1515
import { Construct as CoreConstruct } from '@aws-cdk/core';
1616

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

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)