-
Notifications
You must be signed in to change notification settings - Fork 4k
/
container-image.ts
76 lines (68 loc) · 2.37 KB
/
container-image.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as ecr from '@aws-cdk/aws-ecr';
import * as cdk from '@aws-cdk/core';
import { ContainerDefinition } from './container-definition';
import { CfnTaskDefinition } from './ecs.generated';
/**
* Constructs for types of container images
*/
export abstract class ContainerImage {
/**
* Reference an image on DockerHub or another online registry
*/
public static fromRegistry(name: string, props: RepositoryImageProps = {}) {
return new RepositoryImage(name, props);
}
/**
* Reference an image in an ECR repository
*/
public static fromEcrRepository(repository: ecr.IRepository, tag: string = 'latest') {
return new EcrImage(repository, tag);
}
/**
* Reference an image that's constructed directly from sources on disk.
*
* If you already have a `DockerImageAsset` instance, you can use the
* `ContainerImage.fromDockerImageAsset` method instead.
*
* @param directory The directory containing the Dockerfile
*/
public static fromAsset(directory: string, props: AssetImageProps = {}) {
return new AssetImage(directory, props);
}
/**
* Use an existing `DockerImageAsset` for this container image.
*
* @param asset The `DockerImageAsset` to use for this container definition.
*/
public static fromDockerImageAsset(asset: DockerImageAsset): ContainerImage {
return {
bind(_scope: cdk.Construct, containerDefinition: ContainerDefinition): ContainerImageConfig {
asset.repository.grantPull(containerDefinition.taskDefinition.obtainExecutionRole());
return {
imageName: asset.imageUri,
};
},
};
}
/**
* Called when the image is used by a ContainerDefinition
*/
public abstract bind(scope: cdk.Construct, containerDefinition: ContainerDefinition): ContainerImageConfig;
}
/**
* The configuration for creating a container image.
*/
export interface ContainerImageConfig {
/**
* Specifies the name of the container image.
*/
readonly imageName: string;
/**
* Specifies the credentials used to access the image repository.
*/
readonly repositoryCredentials?: CfnTaskDefinition.RepositoryCredentialsProperty;
}
import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets';
import { AssetImage, AssetImageProps } from './images/asset-image';
import { EcrImage } from './images/ecr';
import { RepositoryImage, RepositoryImageProps } from './images/repository';