UNPKG

9.67 kBTypeScriptView Raw
1import { BundlingOptions } from './bundling';
2/**
3 * Common interface for all assets.
4 */
5export interface IAsset {
6 /**
7 * A hash of this asset, which is available at construction time. As this is a plain string, it
8 * can be used in construct IDs in order to enforce creation of a new resource when the content
9 * hash has changed.
10 */
11 readonly assetHash: string;
12}
13/**
14 * Asset hash options
15 */
16export interface AssetOptions {
17 /**
18 * Specify a custom hash for this asset. If `assetHashType` is set it must
19 * be set to `AssetHashType.CUSTOM`. For consistency, this custom hash will
20 * be SHA256 hashed and encoded as hex. The resulting hash will be the asset
21 * hash.
22 *
23 * NOTE: the hash is used in order to identify a specific revision of the asset, and
24 * used for optimizing and caching deployment activities related to this asset such as
25 * packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will
26 * need to make sure it is updated every time the asset changes, or otherwise it is
27 * possible that some deployments will not be invalidated.
28 *
29 * @default - based on `assetHashType`
30 */
31 readonly assetHash?: string;
32 /**
33 * Specifies the type of hash to calculate for this asset.
34 *
35 * If `assetHash` is configured, this option must be `undefined` or
36 * `AssetHashType.CUSTOM`.
37 *
38 * @default - the default is `AssetHashType.SOURCE`, but if `assetHash` is
39 * explicitly specified this value defaults to `AssetHashType.CUSTOM`.
40 */
41 readonly assetHashType?: AssetHashType;
42 /**
43 * Bundle the asset by executing a command in a Docker container or a custom bundling provider.
44 *
45 * The asset path will be mounted at `/asset-input`. The Docker
46 * container is responsible for putting content at `/asset-output`.
47 * The content at `/asset-output` will be zipped and used as the
48 * final asset.
49 *
50 * @default - uploaded as-is to S3 if the asset is a regular file or a .zip file,
51 * archived into a .zip file and uploaded to S3 otherwise
52 *
53 *
54 */
55 readonly bundling?: BundlingOptions;
56}
57/**
58 * The type of asset hash
59 *
60 * NOTE: the hash is used in order to identify a specific revision of the asset, and
61 * used for optimizing and caching deployment activities related to this asset such as
62 * packaging, uploading to Amazon S3, etc.
63 */
64export declare enum AssetHashType {
65 /**
66 * Based on the content of the source path
67 *
68 * When bundling, use `SOURCE` when the content of the bundling output is not
69 * stable across repeated bundling operations.
70 */
71 SOURCE = "source",
72 /**
73 * Based on the content of the bundled path
74 *
75 * @deprecated use `OUTPUT` instead
76 */
77 BUNDLE = "bundle",
78 /**
79 * Based on the content of the bundling output
80 *
81 * Use `OUTPUT` when the source of the asset is a top level folder containing
82 * code and/or dependencies that are not directly linked to the asset.
83 */
84 OUTPUT = "output",
85 /**
86 * Use a custom hash
87 */
88 CUSTOM = "custom"
89}
90/**
91 * Represents the source for a file asset.
92 */
93export interface FileAssetSource {
94 /**
95 * A hash on the content source. This hash is used to uniquely identify this
96 * asset throughout the system. If this value doesn't change, the asset will
97 * not be rebuilt or republished.
98 */
99 readonly sourceHash: string;
100 /**
101 * An external command that will produce the packaged asset.
102 *
103 * The command should produce the location of a ZIP file on `stdout`.
104 *
105 * @default - Exactly one of `directory` and `executable` is required
106 */
107 readonly executable?: string[];
108 /**
109 * The path, relative to the root of the cloud assembly, in which this asset
110 * source resides. This can be a path to a file or a directory, depending on the
111 * packaging type.
112 *
113 * @default - Exactly one of `directory` and `executable` is required
114 */
115 readonly fileName?: string;
116 /**
117 * Which type of packaging to perform.
118 *
119 * @default - Required if `fileName` is specified.
120 */
121 readonly packaging?: FileAssetPackaging;
122}
123export interface DockerImageAssetSource {
124 /**
125 * The hash of the contents of the docker build context. This hash is used
126 * throughout the system to identify this image and avoid duplicate work
127 * in case the source did not change.
128 *
129 * NOTE: this means that if you wish to update your docker image, you
130 * must make a modification to the source (e.g. add some metadata to your Dockerfile).
131 */
132 readonly sourceHash: string;
133 /**
134 * An external command that will produce the packaged asset.
135 *
136 * The command should produce the name of a local Docker image on `stdout`.
137 *
138 * @default - Exactly one of `directoryName` and `executable` is required
139 */
140 readonly executable?: string[];
141 /**
142 * The directory where the Dockerfile is stored, must be relative
143 * to the cloud assembly root.
144 *
145 * @default - Exactly one of `directoryName` and `executable` is required
146 */
147 readonly directoryName?: string;
148 /**
149 * Build args to pass to the `docker build` command.
150 *
151 * Since Docker build arguments are resolved before deployment, keys and
152 * values cannot refer to unresolved tokens (such as `lambda.functionArn` or
153 * `queue.queueUrl`).
154 *
155 * Only allowed when `directoryName` is specified.
156 *
157 * @default - no build args are passed
158 */
159 readonly dockerBuildArgs?: {
160 [key: string]: string;
161 };
162 /**
163 * Docker target to build to
164 *
165 * Only allowed when `directoryName` is specified.
166 *
167 * @default - no target
168 */
169 readonly dockerBuildTarget?: string;
170 /**
171 * Path to the Dockerfile (relative to the directory).
172 *
173 * Only allowed when `directoryName` is specified.
174 *
175 * @default - no file
176 */
177 readonly dockerFile?: string;
178 /**
179 * ECR repository name
180 *
181 * Specify this property if you need to statically address the image, e.g.
182 * from a Kubernetes Pod. Note, this is only the repository name, without the
183 * registry and the tag parts.
184 *
185 * @default - automatically derived from the asset's ID.
186 * @deprecated repository name should be specified at the environment-level and not at the image level
187 */
188 readonly repositoryName?: string;
189 /**
190 * Networking mode for the RUN commands during build. _Requires Docker Engine API v1.25+_.
191 *
192 * Specify this property to build images on a specific networking mode.
193 *
194 * @default - no networking mode specified
195 */
196 readonly networkMode?: string;
197 /**
198 * Platform to build for. _Requires Docker Buildx_.
199 *
200 * Specify this property to build images on a specific platform.
201 *
202 * @default - no platform specified (the current machine architecture will be used)
203 */
204 readonly platform?: string;
205}
206/**
207 * Packaging modes for file assets.
208 */
209export declare enum FileAssetPackaging {
210 /**
211 * The asset source path points to a directory, which should be archived using
212 * zip and and then uploaded to Amazon S3.
213 */
214 ZIP_DIRECTORY = "zip",
215 /**
216 * The asset source path points to a single file, which should be uploaded
217 * to Amazon S3.
218 */
219 FILE = "file"
220}
221/**
222 * The location of the published file asset. This is where the asset
223 * can be consumed at runtime.
224 */
225export interface FileAssetLocation {
226 /**
227 * The name of the Amazon S3 bucket.
228 */
229 readonly bucketName: string;
230 /**
231 * The Amazon S3 object key.
232 */
233 readonly objectKey: string;
234 /**
235 * The HTTP URL of this asset on Amazon S3.
236 * @default - value specified in `httpUrl` is used.
237 * @deprecated use `httpUrl`
238 */
239 readonly s3Url?: string;
240 /**
241 * The HTTP URL of this asset on Amazon S3.
242 *
243 * This value suitable for inclusion in a CloudFormation template, and
244 * may be an encoded token.
245 *
246 * Example value: `https://s3-us-east-1.amazonaws.com/mybucket/myobject`
247 */
248 readonly httpUrl: string;
249 /**
250 * The S3 URL of this asset on Amazon S3.
251 *
252 * This value suitable for inclusion in a CloudFormation template, and
253 * may be an encoded token.
254 *
255 * Example value: `s3://mybucket/myobject`
256 */
257 readonly s3ObjectUrl: string;
258 /**
259 * The ARN of the KMS key used to encrypt the file asset bucket, if any.
260 *
261 * The CDK bootstrap stack comes with a key policy that does not require
262 * setting this property, so you only need to set this property if you
263 * have customized the bootstrap stack to require it.
264 *
265 * @default - Asset bucket is not encrypted, or decryption permissions are
266 * defined by a Key Policy.
267 */
268 readonly kmsKeyArn?: string;
269 /**
270 * Like `s3ObjectUrl`, but not suitable for CloudFormation consumption
271 *
272 * If there are placeholders in the S3 URL, they will be returned unreplaced
273 * and un-evaluated.
274 *
275 * @default - This feature cannot be used
276 */
277 readonly s3ObjectUrlWithPlaceholders?: string;
278}
279/**
280 * The location of the published docker image. This is where the image can be
281 * consumed at runtime.
282 */
283export interface DockerImageAssetLocation {
284 /**
285 * The URI of the image in Amazon ECR.
286 */
287 readonly imageUri: string;
288 /**
289 * The name of the ECR repository.
290 */
291 readonly repositoryName: string;
292}