-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lambda dockerfile and deployment workflow
- Loading branch information
1 parent
a87f13d
commit 8434d4f
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Deploy Python Lambda | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
paths: ['src/backend/**'] | ||
workflow_dispatch: | ||
|
||
env: | ||
AWS_REGION: us-east-2 | ||
ECR_REPOSITORY: mdst/mini-copilot | ||
CONTAINER_NAME: mini-copilot | ||
LAMBDA_FUNCTION_NAME: mini-copilot-lambda | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
environment: production | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@0e613a0980cbf65ed5b322eb7a1e075d28913a83 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
working-directory: ./src/backend | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
# Build a docker container and push it to ECR | ||
aws s3 cp s3://mini-copilot/trained/ ./trained --recursive | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
- name: Update Lambda Function | ||
run: | | ||
aws lambda update-function-code --function-name ${{ env.LAMBDA_FUNCTION_NAME }} \ | ||
--region ${{ env.AWS_REGION }} \ | ||
--image-uri ${{ steps.build-image.outputs.image }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM public.ecr.aws/lambda/python:3.12 | ||
|
||
# Copy requirements.txt | ||
COPY lambda_requirements.txt ${LAMBDA_TASK_ROOT} | ||
|
||
# Install the specified packages | ||
RUN pip install --compile --no-cache-dir -r lambda_requirements.txt | ||
|
||
# Copy model | ||
COPY trained/gpt2-728 ${LAMBDA_TASK_ROOT}/trained/gpt2-728 | ||
|
||
# Copy function code | ||
COPY lambda_function.py ${LAMBDA_TASK_ROOT} | ||
|
||
# Set the CMD to your handler | ||
CMD [ "lambda_function.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
boto3 | ||
transformers | ||
pytorch |