-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_container.ts
123 lines (111 loc) · 4.04 KB
/
ts_container.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright 2023-2024 Amazon.com, Inc. or its affiliates.
*/
import { RemovalPolicy, SymlinkFollowMode } from "aws-cdk-lib";
import { DockerImageAsset } from "aws-cdk-lib/aws-ecr-assets";
import { ContainerImage } from "aws-cdk-lib/aws-ecs";
import { IRole } from "aws-cdk-lib/aws-iam";
import { Construct } from "constructs";
import { OSMLAccount } from "../osml_account";
import { OSMLECRDeployment } from "../osml_ecr_deployment";
import { OSMLVpc } from "../osml_vpc";
/**
* Represents the configuration for the TSContainer Construct.
*/
export class TSContainerConfig {
/**
* Creates an instance of TSContainerConfig.
* @param {string} [TS_CONTAINER="awsosml/osml-tile-server:latest"] - The container image to use for the TileServer.
* @param {string} [TS_BUILD_PATH="lib/osml-tile-server"] - The build path for the TileServer.
* @param {string} [TS_BUILD_TARGET="osml_tile_sever"] - The build target for the TileServer.
* @param {string} [TS_REPOSITORY="tile-server-container"] - The repository name for the TileServer.
*/
constructor(
public TS_CONTAINER: string = "awsosml/osml-tile-server:latest",
public TS_BUILD_PATH: string = "lib/osml-tile-server",
public TS_BUILD_TARGET: string = "osml_tile_server",
public TS_REPOSITORY: string = "tile-server-container"
) {}
}
/**
* Interface representing the properties for the TSContainer construct.
*/
export interface TSContainerProps {
/**
* The OSML deployment account.
*/
account: OSMLAccount;
/**
* The OSML VPC (Virtual Private Cloud) associated with the TSContainer.
*/
osmlVpc: OSMLVpc;
/**
* Optional task role to be used by the TSContainer.
*/
taskRole?: IRole;
/**
* Optional flag to instruct building tile server container from source.
*/
buildFromSource?: boolean;
/**
* Optional configuration settings specific to the TSContainer.
*/
config?: TSContainerConfig;
}
/**
* Represents a construct responsible for deploying the ECR container image
* for the tile server service.
*/
export class TSContainer extends Construct {
public removalPolicy: RemovalPolicy;
public config: TSContainerConfig;
public containerImage: ContainerImage;
/**
* Creates an instance of TSContainer.
* @param {Construct} scope The scope/stack in which to define this construct.
* @param {string} id The id of this construct within the current scope.
* @param {TSContainerProps} props The properties of this construct.
* @returns TSContainer - The TSContainer construct.
*/
constructor(scope: Construct, id: string, props: TSContainerProps) {
super(scope, id);
// Determine the removal policy based on the provided properties.
this.removalPolicy = props.account.prodLike
? RemovalPolicy.RETAIN
: RemovalPolicy.DESTROY;
// Check if a custom configuration was provided; otherwise, create a new default configuration.
if (props.config != undefined) {
// Import an existing TS configuration.
this.config = props.config;
} else {
// Create a new default configuration.
this.config = new TSContainerConfig();
}
if (props.buildFromSource == true) {
// Create a container image from a Docker image asset for development environment.
this.containerImage = ContainerImage.fromDockerImageAsset(
new DockerImageAsset(this, id, {
directory: this.config.TS_BUILD_PATH,
file: "Dockerfile",
followSymlinks: SymlinkFollowMode.ALWAYS,
target: this.config.TS_BUILD_TARGET
})
);
} else {
// Create an ECR deployment for production environment.
const ecrDeployment: OSMLECRDeployment = new OSMLECRDeployment(
this,
"TSContainerECRDeployment",
{
account: props.account,
sourceUri: this.config.TS_CONTAINER,
repositoryName: this.config.TS_REPOSITORY,
removalPolicy: this.removalPolicy,
vpc: props.osmlVpc.vpc,
vpcSubnets: props.osmlVpc.selectedSubnets
}
);
this.containerImage = ecrDeployment.containerImage;
}
}
}