transforming lambda to use docker wip

This commit is contained in:
Khalim Conn-Kowlessar 2023-08-22 09:52:42 +01:00
parent 517409dfe0
commit 96ac0135e9
4 changed files with 54 additions and 11 deletions

View file

@ -1 +1,12 @@
model_data/local_data/*
backend/tests/*
recommendations/tests/*
model_data/tests/*
infrastructure/*
data_collection/*
node_modules/*
conservation_areas/*
open_uprn/*
land_registry/*
pytest.ini
*/README.md

View file

@ -59,16 +59,26 @@ jobs:
echo "::set-output name=db_port::${{ secrets[format('{0}_DB_PORT', github.ref_name)] }}"
echo "::set-output name=db_name::${{ secrets[format('{0}_DB_NAME', github.ref_name)] }}"
# - name: Build Lambda Layer
# run: |
# cd backend
# pip install -r requirements/lambda.txt -t python
# zip -r layer.zip python
#
# - name: Publish Lambda Layer
# run: |
# LAYER_ARN=$(aws lambda publish-layer-version --layer-name LambdaDependenciesLayer --zip-file fileb://backend/layer.zip | jq -r '.LayerVersionArn')
# aws ssm put-parameter --name "/${{ github.ref_name }}/LambdaDependenciesLayerArn" --value "$LAYER_ARN" --type String --overwrite
- name: Set ECR credentials
id: set_ecr_credentials
run: |
echo "::set-output name=ecr_uri::${{ secrets[format('{0}_ECR_URI', github.ref_name)] }}"
- name: Setup Docker
uses: docker/setup-buildx-action@v1
- name: Build Docker Image
run: |
docker build -t my-lambda-image:latest -f backend/docker/lambda.Dockerfile .
- name: Login to ECR
run: |
aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ steps.set_ecr_credentials.outputs.ecr_uri }}
- name: Tag and Push Docker Image to ECR
run: |
docker tag my-lambda-image:latest ${{ steps.set_ecr_credentials.outputs.ecr_uri }}:latest
docker push ${{ steps.set_ecr_credentials.outputs.ecr_uri }}:latest
- name: Deploy to AWS Lambda via Serverless
env:
@ -81,6 +91,7 @@ jobs:
DB_HOST: ${{ steps.set_db_credentials.outputs.db_host }}
DB_PORT: ${{ steps.set_db_credentials.outputs.db_port }}
DB_NAME: ${{ steps.set_db_credentials.outputs.db_name }}
ECR_URI: ${{ steps.set_ecr_credentials.outputs.ecr_uri }}
run: |
# Fetch database credentials from AWS Secrets Manager
SECRET_VALUE=$(aws secretsmanager get-secret-value --secret-id dev/assessment_model/db_credentials --query SecretString)

View file

@ -9,4 +9,24 @@ ENV PYTHONUNBUFFERED 1
WORKDIR /Model
# Install system dependencies
RUN apt-get update && apt-get install -y netcat-openbsd
RUN apt-get update && apt-get install -y netcat-openbsd
# Install python dependencies
COPY ./backend/requirements/base.txt ./backend/requirements/base.txt
RUN pip install --upgrade pip
RUN pip install -r backend/requirements/base.txt
# Copy project files
COPY ./backend/ ./backend
COPY ./recommendations/ ./recommendations
COPY ./model_data/BaseUtility.py ./model_data/BaseUtility.py
COPY ./model_data/config.py ./model_data/config.py
COPY ./model_data/optimiser/ ./model_data/optimiser/
COPY ./model_data/__init__.py ./model_data/__init__.py
COPY ./model_data/EpcClean.py ./model_data/EpcClean.py
COPY ./model_data/utils.py ./model_data/utils.py
COPY ./model_data/epc_attributes/ ./model_data/epc_attributes/
COPY ./datatypes/ ./datatypes/
# Define the handler location
CMD ["backend.app.main.handler"]

View file

@ -17,6 +17,7 @@ provider:
DB_USERNAME: ${env:DB_USERNAME}
DB_PASSWORD: ${env:DB_PASSWORD}
DB_PORT: ${env:DB_PORT}
ECR_URI: ${env:ECR_URI}
# Give lambda access to read from the bucket
iam:
role: