Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor schema #259

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
!postcss.config.js
!jest.config.js
*.d.ts
dist/
node_modules/
__pycache__/
.ruff_cache/
.husky/
.mypy_cache/
.pytest_cache/

*.key
*.pem

Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ cleanTypeScript:
@find . -type d -name ".tscache" -exec rm -rf {} +
@find . -type d -name ".jest_cache" -exec rm -rf {} +
@find . -type d -name "node_modules" -exec rm -rf {} +
@find . -type d -name "cdk.out" -exec rm -rf {} +
@find . -type d -name "coverage" -exec rm -rf {} +


## Delete CloudFormation outputs
Expand Down
4 changes: 2 additions & 2 deletions bin/lisa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/

// Main app
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'node:fs';
import * as path from 'node:path';

import * as cdk from 'aws-cdk-lib';
import * as yaml from 'js-yaml';
Expand Down
2 changes: 1 addition & 1 deletion cdk.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app": "npx ts-node --prefer-ts-exts bin/lisa.ts",
"app": "npm run deploy",
"requireApproval": "never",
"watch": {
"include": ["**"],
Expand Down
2 changes: 1 addition & 1 deletion ecs_model_deployer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM public.ecr.aws/lambda/nodejs:18

COPY ./dist/ ${LAMBDA_TASK_ROOT}
RUN chmod 777 -R ${LAMBDA_TASK_ROOT}
CMD ["index.handler"]
CMD ["ecs_model_deployer/src/index.handler"]
6 changes: 4 additions & 2 deletions ecs_model_deployer/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "cdk_runner",
"name": "ecs_model_deployer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc && cp package.json ./dist && cp ./src/cdk*json ./dist/ && cp ../VERSION ./dist && cd ./dist && npm i --omit dev",
"build": "tsc && npm run copy-deps && npm run install-run-deps",
"copy-deps": "cp package.json ./dist && cp ./src/cdk*json ./dist/ && cp ../VERSION ./dist",
"install-run-deps": "cd dist && npm i --omit dev --include-workspace-root",
"clean": "rm -rf ./dist/",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
5 changes: 3 additions & 2 deletions ecs_model_deployer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
limitations under the License.
*/

import { spawnSync, spawn, ChildProcess } from 'child_process';
import { readdirSync, symlinkSync, rmSync } from 'fs';
import { ChildProcess, spawn, spawnSync } from 'node:child_process';

import { readdirSync, rmSync, symlinkSync } from 'node:fs';

/*
cdk CLI always wants ./ to be writable in order to write cdk.context.json.
Expand Down
5 changes: 3 additions & 2 deletions ecs_model_deployer/src/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/

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

import { ConfigFile, ConfigSchema } from './ecs-schema';
import { ConfigFile, ConfigSchema } from '../../../lib/schema';


export const app = new App();

Expand Down
55 changes: 27 additions & 28 deletions ecs_model_deployer/src/lib/ecs-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
*/

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

import { ECSCluster } from './ecsCluster';
import { getModelIdentifier } from './utils';
import { BaseProps, Config, Ec2Metadata, EcsSourceType, ModelConfig } from './ecs-schema';
import { BaseProps, Config, Ec2Metadata, EcsClusterConfig, EcsSourceType } from '../../../lib/schema';
import { StringParameter } from 'aws-cdk-lib/aws-ssm';

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

/**
* @param {Construct} scope - The parent or owner of the construct.
* @param {string} id - The unique identifier for the construct within its scope.
* @param {ECSModelProps} props - The properties of the construct.
*/
* @param {Construct} scope - The parent or owner of the construct.
* @param {string} id - The unique identifier for the construct within its scope.
* @param {ECSModelProps} props - The properties of the construct.
*/
constructor (scope: Construct, id: string, props: ECSModelProps) {
super(scope, id);
const { config, modelConfig, securityGroup, vpc, subnetSelection } = props;
Expand Down Expand Up @@ -87,15 +86,15 @@ export class EcsModel extends Construct {
}

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

/**
* Generates build arguments for the Docker build based on the configuration. The build arguments include the base
* image, and depending on the model type, either the local code path or the S3 deb URL.
*
* @param {Config} config - The application configuration.
* @param {ModelConfig} modelConfig - Configuration for the specific model.
* @returns {Object} An object containing the build arguments. The object has string keys and values, which represent
* the arguments for the Docker build.
*/
private getBuildArguments (config: Config, modelConfig: ModelConfig): { [key: string]: string } | undefined {
* Generates build arguments for the Docker build based on the configuration. The build arguments include the base
* image, and depending on the model type, either the local code path or the S3 deb URL.
*
* @param {Config} config - The application configuration.
* @param {EcsClusterConfig} modelConfig - Configuration for the specific model.
* @returns {Object} An object containing the build arguments. The object has string keys and values, which represent
* the arguments for the Docker build.
*/
private getBuildArguments (config: Config, modelConfig: EcsClusterConfig): { [key: string]: string } | undefined {
if (modelConfig.containerConfig.image.type !== EcsSourceType.ASSET) {
return undefined;
}
Expand Down
Loading