Skip to content

Commit 9aba089

Browse files
authored
Feature/refactor schema (#259)
* Refactor schema package
1 parent d50df56 commit 9aba089

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2197
-13007
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
!postcss.config.js
44
!jest.config.js
55
*.d.ts
6+
dist/
67
node_modules/
78
__pycache__/
89
.ruff_cache/
910
.husky/
1011
.mypy_cache/
1112
.pytest_cache/
12-
1313
*.key
1414
*.pem
1515

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ cleanTypeScript:
232232
@find . -type d -name ".tscache" -exec rm -rf {} +
233233
@find . -type d -name ".jest_cache" -exec rm -rf {} +
234234
@find . -type d -name "node_modules" -exec rm -rf {} +
235+
@find . -type d -name "cdk.out" -exec rm -rf {} +
236+
@find . -type d -name "coverage" -exec rm -rf {} +
235237

236238

237239
## Delete CloudFormation outputs

bin/lisa.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818

1919
// Main app
20-
import * as fs from 'fs';
21-
import * as path from 'path';
20+
import * as fs from 'node:fs';
21+
import * as path from 'node:path';
2222

2323
import * as cdk from 'aws-cdk-lib';
2424
import * as yaml from 'js-yaml';

cdk.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"app": "npx ts-node --prefer-ts-exts bin/lisa.ts",
2+
"app": "npm run deploy",
33
"requireApproval": "never",
44
"watch": {
55
"include": ["**"],

ecs_model_deployer/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM public.ecr.aws/lambda/nodejs:18
22

33
COPY ./dist/ ${LAMBDA_TASK_ROOT}
44
RUN chmod 777 -R ${LAMBDA_TASK_ROOT}
5-
CMD ["index.handler"]
5+
CMD ["ecs_model_deployer/src/index.handler"]

ecs_model_deployer/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2-
"name": "cdk_runner",
2+
"name": "ecs_model_deployer",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "tsc && cp package.json ./dist && cp ./src/cdk*json ./dist/ && cp ../VERSION ./dist && cd ./dist && npm i --omit dev",
7+
"build": "tsc && npm run copy-deps && npm run install-run-deps",
8+
"copy-deps": "cp package.json ./dist && cp ./src/cdk*json ./dist/ && cp ../VERSION ./dist",
9+
"install-run-deps": "cd dist && npm i --omit dev --include-workspace-root",
810
"clean": "rm -rf ./dist/",
911
"test": "echo \"Error: no test specified\" && exit 1"
1012
},

ecs_model_deployer/src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
limitations under the License.
1515
*/
1616

17-
import { spawnSync, spawn, ChildProcess } from 'child_process';
18-
import { readdirSync, symlinkSync, rmSync } from 'fs';
17+
import { ChildProcess, spawn, spawnSync } from 'node:child_process';
18+
19+
import { readdirSync, rmSync, symlinkSync } from 'node:fs';
1920

2021
/*
2122
cdk CLI always wants ./ to be writable in order to write cdk.context.json.

ecs_model_deployer/src/lib/app.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616

1717
import { AddPermissionBoundary } from '@cdklabs/cdk-enterprise-iac';
18-
import { Aspects, App } from 'aws-cdk-lib';
18+
import { App, Aspects } from 'aws-cdk-lib';
1919
import { LisaModelStack, LisaModelStackProps } from './lisa_model_stack';
2020

21-
import { ConfigFile, ConfigSchema } from './ecs-schema';
21+
import { ConfigFile, ConfigSchema } from '../../../lib/schema';
22+
2223

2324
export const app = new App();
2425

ecs_model_deployer/src/lib/ecs-model.ts

+27-28
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
15-
*/
15+
*/
1616

17-
// ECS Model Construct.
1817
import { ISecurityGroup, IVpc, SubnetSelection } from 'aws-cdk-lib/aws-ec2';
1918
import { AmiHardwareType } from 'aws-cdk-lib/aws-ecs';
2019
import { Bucket } from 'aws-cdk-lib/aws-s3';
2120
import { Construct } from 'constructs';
2221

2322
import { ECSCluster } from './ecsCluster';
2423
import { getModelIdentifier } from './utils';
25-
import { BaseProps, Config, Ec2Metadata, EcsSourceType, ModelConfig } from './ecs-schema';
24+
import { BaseProps, Config, Ec2Metadata, EcsClusterConfig, EcsSourceType } from '../../../lib/schema';
2625
import { StringParameter } from 'aws-cdk-lib/aws-ssm';
2726

2827
// This is the amount of memory to buffer (or subtract off) from the total instance memory, if we don't include this,
@@ -33,11 +32,11 @@ const CONTAINER_MEMORY_BUFFER = 1024 * 5;
3332
* Properties for the EcsModel Construct.
3433
*
3534
* @property {IVpc} vpc - The virtual private cloud (VPC).
36-
* @property {SecurityGroup} securityGroup - The security group to use for the ECS cluster
37-
* @property {ModelConfig} modelConfig - The model configuration.
35+
* @property {ISecurityGroup} securityGroup - The security group to use for the ECS cluster
36+
* @property {EcsClusterConfig} modelConfig - The model configuration.
3837
*/
3938
type ECSModelProps = {
40-
modelConfig: ModelConfig;
39+
modelConfig: EcsClusterConfig;
4140
securityGroup: ISecurityGroup;
4241
vpc: IVpc;
4342
subnetSelection?: SubnetSelection;
@@ -51,10 +50,10 @@ export class EcsModel extends Construct {
5150
public readonly endpointUrl: string;
5251

5352
/**
54-
* @param {Construct} scope - The parent or owner of the construct.
55-
* @param {string} id - The unique identifier for the construct within its scope.
56-
* @param {ECSModelProps} props - The properties of the construct.
57-
*/
53+
* @param {Construct} scope - The parent or owner of the construct.
54+
* @param {string} id - The unique identifier for the construct within its scope.
55+
* @param {ECSModelProps} props - The properties of the construct.
56+
*/
5857
constructor (scope: Construct, id: string, props: ECSModelProps) {
5958
super(scope, id);
6059
const { config, modelConfig, securityGroup, vpc, subnetSelection } = props;
@@ -87,15 +86,15 @@ export class EcsModel extends Construct {
8786
}
8887

8988
/**
90-
* Generates environment variables for Docker at runtime based on the configuration. The environment variables
91-
* include the local model path, S3 bucket for models, model name, and other variables depending on the model type.
92-
*
93-
* @param {Config} config - The application configuration.
94-
* @param {ModelConfig} modelConfig - Configuration for the specific model.
95-
* @returns {Object} An object containing the environment variables. The object has string keys and values, which
96-
* represent the environment variables for Docker at runtime.
97-
*/
98-
private getEnvironmentVariables (config: Config, modelConfig: ModelConfig): { [key: string]: string } {
89+
* Generates environment variables for Docker at runtime based on the configuration. The environment variables
90+
* include the local model path, S3 bucket for models, model name, and other variables depending on the model type.
91+
*
92+
* @param {Config} config - The application configuration.
93+
* @param {EcsClusterConfig} modelConfig - Configuration for the specific model.
94+
* @returns {Object} An object containing the environment variables. The object has string keys and values, which
95+
* represent the environment variables for Docker at runtime.
96+
*/
97+
private getEnvironmentVariables (config: Config, modelConfig: EcsClusterConfig): { [key: string]: string } {
9998
const environment: { [key: string]: string } = {
10099
LOCAL_MODEL_PATH: `${config.nvmeContainerMountPath}/model`,
101100
S3_BUCKET_MODELS: config.s3BucketModels,
@@ -127,15 +126,15 @@ export class EcsModel extends Construct {
127126
}
128127

129128
/**
130-
* Generates build arguments for the Docker build based on the configuration. The build arguments include the base
131-
* image, and depending on the model type, either the local code path or the S3 deb URL.
132-
*
133-
* @param {Config} config - The application configuration.
134-
* @param {ModelConfig} modelConfig - Configuration for the specific model.
135-
* @returns {Object} An object containing the build arguments. The object has string keys and values, which represent
136-
* the arguments for the Docker build.
137-
*/
138-
private getBuildArguments (config: Config, modelConfig: ModelConfig): { [key: string]: string } | undefined {
129+
* Generates build arguments for the Docker build based on the configuration. The build arguments include the base
130+
* image, and depending on the model type, either the local code path or the S3 deb URL.
131+
*
132+
* @param {Config} config - The application configuration.
133+
* @param {EcsClusterConfig} modelConfig - Configuration for the specific model.
134+
* @returns {Object} An object containing the build arguments. The object has string keys and values, which represent
135+
* the arguments for the Docker build.
136+
*/
137+
private getBuildArguments (config: Config, modelConfig: EcsClusterConfig): { [key: string]: string } | undefined {
139138
if (modelConfig.containerConfig.image.type !== EcsSourceType.ASSET) {
140139
return undefined;
141140
}

0 commit comments

Comments
 (0)