Skip to content

Commit

Permalink
feat: MLFlow AI-GW image module
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpzx committed Oct 22, 2024
1 parent edc66f1 commit c87c905
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 1 deletion.
2 changes: 2 additions & 0 deletions manifests/mlflow-tracking/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ groups:
path: manifests/mlflow-tracking/images-modules.yaml
- name: mlflow
path: manifests/mlflow-tracking/mlflow-modules.yaml
- name: mlflow-ai-gw
path: manifests/mlflow-tracking/images-ai-gw-modules.yaml
targetAccountMappings:
- alias: primary
accountId:
Expand Down
39 changes: 39 additions & 0 deletions modules/mlflow/mlflow-ai-gw-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Mlflow Image

## Description

This module creates an mlflow tracking server container image and pushes to the specified Elastic Container Repository.

## Inputs/Outputs

### Input Parameters

#### Required

- `ecr-repository-name`: The name of the ECR repository to push the image to.

### Sample manifest declaration

```yaml
name: mlflow-image
path: modules/mlflow/mlflow-image
parameters:
- name: ecr-repository-name
valueFrom:
moduleMetadata:
group: storage
name: ecr-mlflow
key: EcrRepositoryName
```
### Module Metadata Outputs
- `MlflowImageUri`: Mlflow image URI

#### Output Example

```json
{
"MlflowImageUri": "xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/ecr-mlflow:latest"
}
```
21 changes: 21 additions & 0 deletions modules/mlflow/mlflow-ai-gw-image/deployspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
publishGenericEnvVariables: true
deploy:
phases:
build:
commands:
- aws ecr describe-repositories --repository-names ${SEEDFARMER_PARAMETER_ECR_REPOSITORY_NAME} || aws ecr create-repository --repository-name ${SEEDFARMER_PARAMETER_ECR_REPOSITORY_NAME} --image-scanning-configuration scanOnPush=true
- export COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- export IMAGE_TAG=ai-gw-${COMMIT_HASH:=latest}
- export REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/${SEEDFARMER_PARAMETER_ECR_REPOSITORY_NAME}
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
- echo Building the Docker image...
- cd src/ && docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
- docker push $REPOSITORY_URI:$IMAGE_TAG
- seedfarmer metadata add -k ImageUri -v $REPOSITORY_URI:latest
destroy:
phases:
build:
commands:
- aws ecr delete-repository --repository-name ${SEEDFARMER_PARAMETER_ECR_REPOSITORY_NAME} --force
# build_type: BUILD_GENERAL1_LARGE
42 changes: 42 additions & 0 deletions modules/mlflow/mlflow-ai-gw-image/modulestack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
AWSTemplateFormatVersion: 2010-09-09
Description: This stack deploys a Module specific IAM permissions

Parameters:
# DeploymentName:
# Type: String
# Description: The name of the deployment
# ModuleName:
# Type: String
# Description: The name of the Module
RoleName:
Type: String
Description: The name of the IAM Role
ECRRepositoryName:
Type: String
Description: The name of the ECR repository

Resources:
Policy:
Type: "AWS::IAM::Policy"
Properties:
PolicyDocument:
Statement:
- Effect: Allow
Action:
- "ecr:Describe*"
- "ecr:Get*"
- "ecr:List*"
Resource: "*"
- Action:
- "ecr:Create*"
- "ecr:Delete*"
- "ecr:*LayerUpload"
- "ecr:UploadLayerPart"
- "ecr:Batch*"
- "ecr:Put*"
Effect: Allow
Resource:
- !Sub "arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/${ECRRepositoryName}"
Version: 2012-10-17
PolicyName: "modulespecific-policy"
Roles: [!Ref RoleName]
15 changes: 15 additions & 0 deletions modules/mlflow/mlflow-ai-gw-image/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM public.ecr.aws/docker/library/python:3.10.15

RUN pip install \
'mlflow[gateway]' \
mlflow==2.17.0 && \
mkdir /mlflow/

EXPOSE 7000

COPY config.yaml ./mlflow/config.yaml

CMD mlflow gateway start \
--host 0.0.0.0 \
--port 7000 \
--config-path ./mlflow/config.yaml;
13 changes: 13 additions & 0 deletions modules/mlflow/mlflow-ai-gw-image/src/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
endpoints:
- name: chat
endpoint_type: llm/v1/chat
model:
provider: bedrock
name: anthropic.claude-3-5-sonnet-20240620-v1:0
config:
aws_config:
aws_region: 'AWS_REGION'
aws_role_arn: 'AWS_ROLE_ARN'
limit:
renewal_period: minute
calls: 10
2 changes: 1 addition & 1 deletion modules/mlflow/mlflow-image/src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.10.12

RUN pip install \
mlflow==2.16.0 \
mlflow==2.17.0 \
pymysql==1.1.1 \
boto3==1.34.45 && \
mkdir /mlflow/
Expand Down

0 comments on commit c87c905

Please sign in to comment.