Skip to content

Commit

Permalink
Merge pull request #1 from FloRul/dev
Browse files Browse the repository at this point in the history
Update code formatting and fix minor bugs
  • Loading branch information
FloRul authored Jan 26, 2024
2 parents 7ba727e + 7244a40 commit b5371be
Show file tree
Hide file tree
Showing 38 changed files with 1,958 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
46 changes: 46 additions & 0 deletions .github/workflows/inference_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy inference lambda image
on:
push:
paths:
- 'inference/src/**'
- '.github/workflows/inference-deploy.yml'
branches:
- dev
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v3
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Create ECR repository if it doesn't exist
run: |
aws ecr describe-repositories --repository-names ${{ vars.INFERENCE_LAMBDA_ECR }} || aws ecr create-repository --repository-name ${{ vars.INFERENCE_LAMBDA_ECR }}
- name: Compute hash of source code
id: compute-hash
run: |
echo "INFERENCE_IMAGE=$(tar -cf - ./inference/src | sha256sum | cut -d ' ' -f 1)" >> $GITHUB_ENV
shell: /usr/bin/bash -e {0}
- name: Build, tag, and push image to Amazon ECR
id: build-image
working-directory: ./inference/src
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ vars.INFERENCE_LAMBDA_ECR }}
IMAGE_TAG: ${{ env.INFERENCE_IMAGE }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
130 changes: 130 additions & 0 deletions .github/workflows/infra_planning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Infrastructure planning and management

on:
pull_request:
branches:
- main

jobs:
planning:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
defaults:
run:
working-directory: ${{ vars.TF_ACTIONS_WORKING_DIR }}
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v3
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Get the latest ingestion image tag
id: get-latest-ingestion-tag
run: |
LATEST_INGESTION_TAG=$(aws ecr describe-images --repository-name ${{vars.INGESTION_LAMBDA_ECR}} --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text)
echo "LATEST_INGESTION_TAG=$LATEST_INGESTION_TAG" >> $GITHUB_ENV
- name: Get the ingestion image URI from the build job
run: |
echo "INGESTION_IMAGE=${{ steps.login-ecr.outputs.registry }}/${{ vars.INGESTION_LAMBDA_ECR }}:${{env.LATEST_INGESTION_TAG}}" >> "$GITHUB_ENV"
- name: Get the latest memory image tag
id: get-latest-memory-tag
run: |
LATEST_MEMORY_TAG=$(aws ecr describe-images --repository-name ${{vars.MEMORY_LAMBDA_ECR}} --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text)
echo "LATEST_MEMORY_TAG=$LATEST_MEMORY_TAG" >> $GITHUB_ENV
- name: Get the memory image URI from the build job
run: |
echo "MEMORY_IMAGE=${{ steps.login-ecr.outputs.registry }}/${{ vars.MEMORY_LAMBDA_ECR }}:${{env.LATEST_MEMORY_TAG}}" >> "$GITHUB_ENV"
- name: Get the latest inference image tag
id: get-latest-inference-tag
run: |
LATEST_INFERENCE_TAG=$(aws ecr describe-images --repository-name ${{vars.INFERENCE_LAMBDA_ECR}} --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text)
echo "LATEST_INFERENCE_TAG=$LATEST_INFERENCE_TAG" >> $GITHUB_ENV
- name: Get the inference image URI from the build job
run: |
echo "INFERENCE_IMAGE=${{ steps.login-ecr.outputs.registry }}/${{ vars.INFERENCE_LAMBDA_ECR }}:${{env.LATEST_INFERENCE_TAG}}" >> "$GITHUB_ENV"
- name: Terraform fmt
id: fmt
run: terraform fmt -check
continue-on-error: true

- name: Terraform Init
id: init
run: terraform init -no-color -upgrade

- name: Terraform Validate
id: validate
run: terraform validate -no-color

- name: Terraform Plan
id: plan
run: terraform plan -var="ingestion_lambda_image_uri=${{ env.INGESTION_IMAGE }}" -var="inference_lambda_image_uri=${{ env.INFERENCE_IMAGE }}" -var="memory_lambda_image_uri=${{ env.MEMORY_IMAGE }}" -no-color
continue-on-error: true

- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
})
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Terraform Format and Style')
})
// 2. Prepare format of the comment
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
61 changes: 61 additions & 0 deletions .github/workflows/infra_provisioning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Apply infrastructure

on:
push:
branches: main
jobs:
apply:
defaults:
run:
working-directory: ${{ vars.TF_ACTIONS_WORKING_DIR }}
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Get the latest ingestion image tag
id: get-latest-ingestion-tag
run: |
LATEST_INGESTION_TAG=$(aws ecr describe-images --repository-name ${{vars.INGESTION_LAMBDA_ECR}} --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text)
echo "LATEST_INGESTION_TAG=$LATEST_INGESTION_TAG" >> $GITHUB_ENV
- name: Get the ingestion image URI from the build job
run: |
echo "INGESTION_IMAGE=${{ steps.login-ecr.outputs.registry }}/${{ vars.INGESTION_LAMBDA_ECR }}:${{env.LATEST_INGESTION_TAG}}" >> "$GITHUB_ENV"
- name: Get the latest memory image tag
id: get-latest-memory-tag
run: |
LATEST_MEMORY_TAG=$(aws ecr describe-images --repository-name ${{vars.MEMORY_LAMBDA_ECR}} --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text)
echo "LATEST_MEMORY_TAG=$LATEST_MEMORY_TAG" >> $GITHUB_ENV
- name: Get the memory image URI from the build job
run: |
echo "MEMORY_IMAGE=${{ steps.login-ecr.outputs.registry }}/${{ vars.MEMORY_LAMBDA_ECR }}:${{env.LATEST_MEMORY_TAG}}" >> "$GITHUB_ENV"
- name: Get the latest inference image tag
id: get-latest-inference-tag
run: |
LATEST_INFERENCE_TAG=$(aws ecr describe-images --repository-name ${{vars.INFERENCE_LAMBDA_ECR}} --query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text)
echo "LATEST_INFERENCE_TAG=$LATEST_INFERENCE_TAG" >> $GITHUB_ENV
- name: Get the inference image URI from the build job
run: |
echo "INFERENCE_IMAGE=${{ steps.login-ecr.outputs.registry }}/${{ vars.INFERENCE_LAMBDA_ECR }}:${{env.LATEST_INFERENCE_TAG}}" >> "$GITHUB_ENV"
- name: Terraform Init
id: terraform-Init
run: |
terraform init -no-color -upgrade
- name: Terraform Apply
id: terraform-Apply
run: |
terraform apply -var="ingestion_lambda_image_uri=${{ env.INGESTION_IMAGE }}" -var="inference_lambda_image_uri=${{ env.INFERENCE_IMAGE }}" -var="memory_lambda_image_uri=${{ env.MEMORY_IMAGE }}" -no-color -auto-approve
44 changes: 44 additions & 0 deletions .github/workflows/ingestion_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy ingestion lambda image
on:
push:
paths:
- 'ingestion/src/**'
- '.github/workflows/ingestion-deploy.yml'
branches:
- dev
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v3
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Create ECR repository if it doesn't exist
run: aws ecr describe-repositories --repository-names ${{ vars.INGESTION_LAMBDA_ECR }} || aws ecr create-repository --repository-name ${{ vars.INGESTION_LAMBDA_ECR }}

- name: Compute hash of source code
id: compute-hash
run: echo "INGESTION_IMAGE=$(tar -cf - ./ingestion/src | sha256sum | cut -d ' ' -f 1)" >> $GITHUB_ENV
shell: /usr/bin/bash -e {0}
- name: Build, tag, and push image to Amazon ECR
id: build-image
working-directory: ./ingestion/src
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ vars.INGESTION_LAMBDA_ECR }}
IMAGE_TAG: ${{ env.INGESTION_IMAGE }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
44 changes: 44 additions & 0 deletions .github/workflows/memory_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy ingestion lambda image
on:
push:
paths:
- 'conversation_memory/src/**'
- '.github/workflows/memory-deploy.yml'
branches:
- dev
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hashicorp/setup-terraform@v3
- uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Create ECR repository if it doesn't exist
run: aws ecr describe-repositories --repository-names ${{ vars.MEMORY_LAMBDA_ECR }} || aws ecr create-repository --repository-name ${{ vars.MEMORY_LAMBDA_ECR }}

- name: Compute hash of source code
id: compute-hash
run: echo "MEMORY_IMAGE=$(tar -cf - ./conversation_memory/src | sha256sum | cut -d ' ' -f 1)" >> $GITHUB_ENV
shell: /usr/bin/bash -e {0}
- name: Build, tag, and push image to Amazon ECR
id: build-image
working-directory: ./conversation_memory/src
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ vars.MEMORY_LAMBDA_ECR }}
IMAGE_TAG: ${{ env.MEMORY_IMAGE }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
*.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc

## Ignore EC2 Key pair files
*.pem
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# levio-aws-demo-fev
Code de l'infrastructure et des composants pour la démo AWS de Levio en genAI.
21 changes: 21 additions & 0 deletions conversation_memory/dynamo.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
data "aws_dynamodb_table" "person_table" {
name = "Person"
}

resource "aws_dynamodb_table" "basic-conversation_memory_table-table" {
name = var.dynamo_history_table_name
billing_mode = "PAY_PER_REQUEST"
hash_key = "SessionId"
range_key = "SK"

attribute {
// Timestamp
name = "SK"
type = "S"
}

attribute {
name = "SessionId"
type = "S"
}
}
Loading

0 comments on commit b5371be

Please sign in to comment.