mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
transforming lambda to use docker wip
This commit is contained in:
parent
517409dfe0
commit
96ac0135e9
4 changed files with 54 additions and 11 deletions
|
|
@ -1 +1,12 @@
|
||||||
model_data/local_data/*
|
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
|
||||||
|
|
|
||||||
31
.github/workflows/deploy_fastapi_backend.yml
vendored
31
.github/workflows/deploy_fastapi_backend.yml
vendored
|
|
@ -59,16 +59,26 @@ jobs:
|
||||||
echo "::set-output name=db_port::${{ secrets[format('{0}_DB_PORT', github.ref_name)] }}"
|
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)] }}"
|
echo "::set-output name=db_name::${{ secrets[format('{0}_DB_NAME', github.ref_name)] }}"
|
||||||
|
|
||||||
# - name: Build Lambda Layer
|
- name: Set ECR credentials
|
||||||
# run: |
|
id: set_ecr_credentials
|
||||||
# cd backend
|
run: |
|
||||||
# pip install -r requirements/lambda.txt -t python
|
echo "::set-output name=ecr_uri::${{ secrets[format('{0}_ECR_URI', github.ref_name)] }}"
|
||||||
# zip -r layer.zip python
|
|
||||||
#
|
- name: Setup Docker
|
||||||
# - name: Publish Lambda Layer
|
uses: docker/setup-buildx-action@v1
|
||||||
# run: |
|
|
||||||
# LAYER_ARN=$(aws lambda publish-layer-version --layer-name LambdaDependenciesLayer --zip-file fileb://backend/layer.zip | jq -r '.LayerVersionArn')
|
- name: Build Docker Image
|
||||||
# aws ssm put-parameter --name "/${{ github.ref_name }}/LambdaDependenciesLayerArn" --value "$LAYER_ARN" --type String --overwrite
|
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
|
- name: Deploy to AWS Lambda via Serverless
|
||||||
env:
|
env:
|
||||||
|
|
@ -81,6 +91,7 @@ jobs:
|
||||||
DB_HOST: ${{ steps.set_db_credentials.outputs.db_host }}
|
DB_HOST: ${{ steps.set_db_credentials.outputs.db_host }}
|
||||||
DB_PORT: ${{ steps.set_db_credentials.outputs.db_port }}
|
DB_PORT: ${{ steps.set_db_credentials.outputs.db_port }}
|
||||||
DB_NAME: ${{ steps.set_db_credentials.outputs.db_name }}
|
DB_NAME: ${{ steps.set_db_credentials.outputs.db_name }}
|
||||||
|
ECR_URI: ${{ steps.set_ecr_credentials.outputs.ecr_uri }}
|
||||||
run: |
|
run: |
|
||||||
# Fetch database credentials from AWS Secrets Manager
|
# Fetch database credentials from AWS Secrets Manager
|
||||||
SECRET_VALUE=$(aws secretsmanager get-secret-value --secret-id dev/assessment_model/db_credentials --query SecretString)
|
SECRET_VALUE=$(aws secretsmanager get-secret-value --secret-id dev/assessment_model/db_credentials --query SecretString)
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,24 @@ ENV PYTHONUNBUFFERED 1
|
||||||
WORKDIR /Model
|
WORKDIR /Model
|
||||||
|
|
||||||
# Install system dependencies
|
# 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"]
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ provider:
|
||||||
DB_USERNAME: ${env:DB_USERNAME}
|
DB_USERNAME: ${env:DB_USERNAME}
|
||||||
DB_PASSWORD: ${env:DB_PASSWORD}
|
DB_PASSWORD: ${env:DB_PASSWORD}
|
||||||
DB_PORT: ${env:DB_PORT}
|
DB_PORT: ${env:DB_PORT}
|
||||||
|
ECR_URI: ${env:ECR_URI}
|
||||||
# Give lambda access to read from the bucket
|
# Give lambda access to read from the bucket
|
||||||
iam:
|
iam:
|
||||||
role:
|
role:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue