@@ -47,7 +47,7 @@ export class NetworkMode {
47
47
/**
48
48
* @param mode The networking mode to use for docker build
49
49
*/
50
- private constructor ( public readonly mode : string ) { }
50
+ private constructor ( public readonly mode : string ) { }
51
51
}
52
52
53
53
/**
@@ -77,7 +77,7 @@ export class Platform {
77
77
/**
78
78
* @param platform The platform to use for docker build
79
79
*/
80
- private constructor ( public readonly platform : string ) { }
80
+ private constructor ( public readonly platform : string ) { }
81
81
}
82
82
83
83
/**
@@ -132,6 +132,13 @@ export interface DockerImageAssetInvalidationOptions {
132
132
* @default true
133
133
*/
134
134
readonly platform ?: boolean ;
135
+
136
+ /**
137
+ * Use `outputs` while calculating the asset hash
138
+ *
139
+ * @default true
140
+ */
141
+ readonly outputs ?: boolean ;
135
142
}
136
143
137
144
/**
@@ -197,6 +204,14 @@ export interface DockerImageAssetOptions extends FingerprintOptions, FileFingerp
197
204
* @default - hash all parameters
198
205
*/
199
206
readonly invalidation ?: DockerImageAssetInvalidationOptions ;
207
+
208
+ /**
209
+ * Outputs to pass to the `docker build` command.
210
+ *
211
+ * @default - no outputs are passed to the build command (default outputs are used)
212
+ * @see https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs
213
+ */
214
+ readonly outputs ?: string [ ] ;
200
215
}
201
216
202
217
/**
@@ -267,6 +282,11 @@ export class DockerImageAsset extends Construct implements IAsset {
267
282
*/
268
283
private readonly dockerBuildArgs ?: { [ key : string ] : string } ;
269
284
285
+ /**
286
+ * Outputs to pass to the `docker build` command.
287
+ */
288
+ private readonly dockerOutputs ?: string [ ] ;
289
+
270
290
/**
271
291
* Docker target to build to
272
292
*/
@@ -330,6 +350,7 @@ export class DockerImageAsset extends Construct implements IAsset {
330
350
if ( props . invalidation ?. repositoryName !== false && props . repositoryName ) { extraHash . repositoryName = props . repositoryName ; }
331
351
if ( props . invalidation ?. networkMode !== false && props . networkMode ) { extraHash . networkMode = props . networkMode ; }
332
352
if ( props . invalidation ?. platform !== false && props . platform ) { extraHash . platform = props . platform ; }
353
+ if ( props . invalidation ?. outputs !== false && props . outputs ) { extraHash . outputs = props . outputs ; }
333
354
334
355
// add "salt" to the hash in order to invalidate the image in the upgrade to
335
356
// 1.21.0 which removes the AdoptedRepository resource (and will cause the
@@ -354,6 +375,7 @@ export class DockerImageAsset extends Construct implements IAsset {
354
375
this . assetPath = staging . relativeStagedPath ( stack ) ;
355
376
this . dockerBuildArgs = props . buildArgs ;
356
377
this . dockerBuildTarget = props . target ;
378
+ this . dockerOutputs = props . outputs ;
357
379
358
380
const location = stack . synthesizer . addDockerImageAsset ( {
359
381
directoryName : this . assetPath ,
@@ -363,6 +385,7 @@ export class DockerImageAsset extends Construct implements IAsset {
363
385
sourceHash : staging . assetHash ,
364
386
networkMode : props . networkMode ?. mode ,
365
387
platform : props . platform ?. platform ,
388
+ dockerOutputs : this . dockerOutputs ,
366
389
} ) ;
367
390
368
391
this . repository = ecr . Repository . fromRepositoryName ( this , 'Repository' , location . repositoryName ) ;
@@ -393,12 +416,13 @@ export class DockerImageAsset extends Construct implements IAsset {
393
416
// tell tools such as SAM CLI that the resourceProperty of this resource
394
417
// points to a local path and include the path to de dockerfile, docker build args, and target,
395
418
// in order to enable local invocation of this function.
396
- resource . cfnOptions . metadata = resource . cfnOptions . metadata || { } ;
419
+ resource . cfnOptions . metadata = resource . cfnOptions . metadata || { } ;
397
420
resource . cfnOptions . metadata [ cxapi . ASSET_RESOURCE_METADATA_PATH_KEY ] = this . assetPath ;
398
421
resource . cfnOptions . metadata [ cxapi . ASSET_RESOURCE_METADATA_DOCKERFILE_PATH_KEY ] = this . dockerfilePath ;
399
422
resource . cfnOptions . metadata [ cxapi . ASSET_RESOURCE_METADATA_DOCKER_BUILD_ARGS_KEY ] = this . dockerBuildArgs ;
400
423
resource . cfnOptions . metadata [ cxapi . ASSET_RESOURCE_METADATA_DOCKER_BUILD_TARGET_KEY ] = this . dockerBuildTarget ;
401
424
resource . cfnOptions . metadata [ cxapi . ASSET_RESOURCE_METADATA_PROPERTY_KEY ] = resourceProperty ;
425
+ resource . cfnOptions . metadata [ cxapi . ASSET_RESOURCE_METADATA_DOCKER_OUTPUTS_KEY ] = this . dockerOutputs ;
402
426
}
403
427
404
428
}
0 commit comments