mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
commit
b720edd988
7 changed files with 74 additions and 5 deletions
45
.github/workflows/deploy_terraform.yml
vendored
45
.github/workflows/deploy_terraform.yml
vendored
|
|
@ -3,7 +3,9 @@ name: Deploy infrastructure
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "**"
|
- "main"
|
||||||
|
- "dev"
|
||||||
|
- "prod"
|
||||||
paths:
|
paths:
|
||||||
- 'infrastructure/terraform/**'
|
- 'infrastructure/terraform/**'
|
||||||
- '.github/workflows/deploy_terraform.yml'
|
- '.github/workflows/deploy_terraform.yml'
|
||||||
|
|
@ -205,3 +207,44 @@ jobs:
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
|
||||||
AWS_REGION: ${{ secrets.DEV_AWS_REGION }}
|
AWS_REGION: ${{ secrets.DEV_AWS_REGION }}
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Categorisation image and Push
|
||||||
|
# ============================================================
|
||||||
|
categorisation_image:
|
||||||
|
needs: [determine_stage, shared_terraform]
|
||||||
|
uses: ./.github/workflows/_build_image.yml
|
||||||
|
with:
|
||||||
|
ecr_repo: categorisation-${{ needs.determine_stage.outputs.stage }}
|
||||||
|
dockerfile_path: backend/categorisation/handler/Dockerfile
|
||||||
|
build_context: .
|
||||||
|
build_args: |
|
||||||
|
DEV_DB_HOST=$DEV_DB_HOST
|
||||||
|
DEV_DB_PORT=$DEV_DB_PORT
|
||||||
|
DEV_DB_NAME=$DEV_DB_NAME
|
||||||
|
secrets:
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
|
||||||
|
AWS_REGION: ${{ secrets.DEV_AWS_REGION }}
|
||||||
|
DEV_DB_HOST: ${{ secrets.DEV_DB_HOST }}
|
||||||
|
DEV_DB_PORT: ${{ secrets.DEV_DB_PORT }}
|
||||||
|
DEV_DB_NAME: ${{ secrets.DEV_DB_NAME }}
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Deploy Categorisation Lambda
|
||||||
|
# ============================================================
|
||||||
|
categorisation_lambda:
|
||||||
|
needs: [categorisation_image, determine_stage]
|
||||||
|
uses: ./.github/workflows/_deploy_lambda.yml
|
||||||
|
with:
|
||||||
|
lambda_name: categorisation
|
||||||
|
lambda_path: infrastructure/terraform/lambda/categorisation
|
||||||
|
stage: ${{ needs.determine_stage.outputs.stage }}
|
||||||
|
ecr_repo: categorisation-${{ needs.determine_stage.outputs.stage }}
|
||||||
|
image_digest: ${{ needs.categorisation_image.outputs.image_digest }}
|
||||||
|
terraform_apply: ${{ needs.determine_stage.outputs.terraform_apply }}
|
||||||
|
secrets:
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
|
||||||
|
AWS_REGION: ${{ secrets.DEV_AWS_REGION }}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
|
import json
|
||||||
from typing import Any, Mapping
|
from typing import Any, Mapping
|
||||||
|
from backend.categorisation.categorisation_trigger_request import (
|
||||||
|
CategorisationTriggerRequest,
|
||||||
|
)
|
||||||
|
from backend.categorisation.processor import process_portfolio
|
||||||
from utils.logger import setup_logger
|
from utils.logger import setup_logger
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -7,4 +12,15 @@ logger = setup_logger()
|
||||||
|
|
||||||
def handler(event: Mapping[str, Any], context: Any) -> None:
|
def handler(event: Mapping[str, Any], context: Any) -> None:
|
||||||
|
|
||||||
pass
|
for record in event.get("Records", []):
|
||||||
|
try:
|
||||||
|
body_dict = json.loads(record["body"])
|
||||||
|
logger.debug("Validating request body")
|
||||||
|
payload = CategorisationTriggerRequest.model_validate(body_dict)
|
||||||
|
|
||||||
|
logger.debug("Successfully validated request body")
|
||||||
|
|
||||||
|
process_portfolio(payload.portfolio_id)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to process record: {e}")
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ module "address2uprn" {
|
||||||
|
|
||||||
image_uri = local.image_uri
|
image_uri = local.image_uri
|
||||||
|
|
||||||
|
timeout = 900
|
||||||
|
|
||||||
environment = merge(
|
environment = merge(
|
||||||
{
|
{
|
||||||
STAGE = var.stage
|
STAGE = var.stage
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
data "aws_secretsmanager_secret_version" "db_credentials" {
|
||||||
|
secret_id = "${var.stage}/assessment_model/db_credentials"
|
||||||
|
}
|
||||||
|
|
||||||
data "terraform_remote_state" "shared" {
|
data "terraform_remote_state" "shared" {
|
||||||
backend = "s3"
|
backend = "s3"
|
||||||
config = {
|
config = {
|
||||||
|
|
@ -7,6 +11,10 @@ data "terraform_remote_state" "shared" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
locals {
|
||||||
|
db_credentials = jsondecode(data.aws_secretsmanager_secret_version.db_credentials.secret_string)
|
||||||
|
}
|
||||||
|
|
||||||
module "lambda" {
|
module "lambda" {
|
||||||
source = "../modules/lambda_with_sqs"
|
source = "../modules/lambda_with_sqs"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ terraform {
|
||||||
}
|
}
|
||||||
|
|
||||||
backend "s3" {
|
backend "s3" {
|
||||||
bucket = "categorisation"
|
bucket = "categorisation-terraform-state"
|
||||||
key = "terraform.tfstate"
|
key = "terraform.tfstate"
|
||||||
region = "eu-west-2"
|
region = "eu-west-2"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ resource "aws_sqs_queue" "dlq" {
|
||||||
resource "aws_sqs_queue" "this" {
|
resource "aws_sqs_queue" "this" {
|
||||||
name = var.name
|
name = var.name
|
||||||
|
|
||||||
visibility_timeout_seconds = 120
|
visibility_timeout_seconds = 1000
|
||||||
|
|
||||||
redrive_policy = jsonencode({
|
redrive_policy = jsonencode({
|
||||||
deadLetterTargetArn = aws_sqs_queue.dlq.arn
|
deadLetterTargetArn = aws_sqs_queue.dlq.arn
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,5 @@ variable "name" { type = string }
|
||||||
|
|
||||||
variable "max_receive_count" {
|
variable "max_receive_count" {
|
||||||
type = number
|
type = number
|
||||||
default = 5
|
default = 1
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue