Merge pull request #9 from topoteretes/feature/improve_actions
Update the base repo
This commit is contained in:
commit
be0c1e8b59
7 changed files with 122 additions and 37 deletions
2
.github/workflows/cd.yaml
vendored
2
.github/workflows/cd.yaml
vendored
|
|
@ -48,7 +48,7 @@ jobs:
|
|||
aws_account_id: ${{ env.AWS_ACCOUNT_ID_DEV }}
|
||||
should_publish: true
|
||||
ecr_image_repo_name: promethai-dev-backend-promethai-backend-memory
|
||||
dockerfile_location: ./level_2
|
||||
dockerfile_location: level_2/.
|
||||
- name: Export Docker image tag
|
||||
id: export-promethai-docker-tag
|
||||
run: |
|
||||
|
|
|
|||
68
.github/workflows/cd_prd.yaml
vendored
68
.github/workflows/cd_prd.yaml
vendored
|
|
@ -23,38 +23,38 @@ jobs:
|
|||
steps:
|
||||
- name: Take code from repo
|
||||
uses: actions/checkout@v3
|
||||
- name: Set environment variable for stage
|
||||
id: set-env
|
||||
run: |
|
||||
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
|
||||
echo "STAGE=prd" >> $GITHUB_ENV
|
||||
echo "::set-output name=stage::prd"
|
||||
else
|
||||
echo "STAGE=dev" >> $GITHUB_ENV
|
||||
echo "::set-output name=stage::dev"
|
||||
fi
|
||||
- name: Use output
|
||||
run: echo "The stage is ${{ steps.set-env.outputs.stage }}"
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1
|
||||
with:
|
||||
role-to-assume: ${{ env.AWS_ROLE_DEV_CICD }}
|
||||
aws-region: eu-west-1
|
||||
- name: Create Docker image and push to ECR
|
||||
uses: ./.github/actions/image_builder
|
||||
id: generate-promethai-docker
|
||||
with:
|
||||
stage: prd
|
||||
aws_account_id: ${{ env.AWS_ACCOUNT_ID_DEV }}
|
||||
should_publish: true
|
||||
ecr_image_repo_name: promethai-prd-backend-promethai-backend-memory
|
||||
dockerfile_location: ./level_2
|
||||
- name: Export Docker image tag
|
||||
id: export-promethai-docker-tag
|
||||
run: |
|
||||
export DOCKER_TAG=$(cat /tmp/.DOCKER_IMAGE_VERSION)
|
||||
echo "Docker tag is: $DOCKER_TAG"
|
||||
echo "promethai_docker_tag_backend=$DOCKER_TAG" >> $GITHUB_OUTPUT
|
||||
# - name: Set environment variable for stage
|
||||
# id: set-env
|
||||
# run: |
|
||||
# if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
|
||||
# echo "STAGE=prd" >> $GITHUB_ENV
|
||||
# echo "::set-output name=stage::prd"
|
||||
# else
|
||||
# echo "STAGE=dev" >> $GITHUB_ENV
|
||||
# echo "::set-output name=stage::dev"
|
||||
# fi
|
||||
# - name: Use output
|
||||
# run: echo "The stage is ${{ steps.set-env.outputs.stage }}"
|
||||
# - name: Configure AWS credentials
|
||||
# uses: aws-actions/configure-aws-credentials@v1
|
||||
# with:
|
||||
# role-to-assume: ${{ env.AWS_ROLE_DEV_CICD }}
|
||||
# aws-region: eu-west-1
|
||||
# - name: Create Docker image and push to ECR
|
||||
# uses: ./.github/actions/image_builder
|
||||
# id: generate-promethai-docker
|
||||
# with:
|
||||
# stage: prd
|
||||
# aws_account_id: ${{ env.AWS_ACCOUNT_ID_DEV }}
|
||||
# should_publish: true
|
||||
# ecr_image_repo_name: promethai-prd-backend-promethai-backend-memory
|
||||
# dockerfile_location: ./level_2
|
||||
# - name: Export Docker image tag
|
||||
# id: export-promethai-docker-tag
|
||||
# run: |
|
||||
# export DOCKER_TAG=$(cat /tmp/.DOCKER_IMAGE_VERSION)
|
||||
# echo "Docker tag is: $DOCKER_TAG"
|
||||
# echo "promethai_docker_tag_backend=$DOCKER_TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
# - name: Create Tag and Release
|
||||
# runs-on: ubuntu-latest
|
||||
|
|
@ -78,8 +78,8 @@ jobs:
|
|||
# with:
|
||||
# tag_name: ${{ steps.bump_version_and_push_tag.outputs.tag }}
|
||||
# release_name: Release ${{ steps.bump_version_and_push_tag.outputs.tag }}
|
||||
outputs:
|
||||
promethai_docker_tag_backend: ${{ steps.export-promethai-docker-tag.outputs.promethai_docker_tag_backend }}
|
||||
# outputs:
|
||||
# promethai_docker_tag_backend: ${{ steps.export-promethai-docker-tag.outputs.promethai_docker_tag_backend }}
|
||||
|
||||
# apply_tf:
|
||||
# name: Trigger terraform apply workflow
|
||||
|
|
|
|||
BIN
assets/topoteretes_logo.png
Normal file
BIN
assets/topoteretes_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
|
|
@ -1,3 +1,9 @@
|
|||
set -euo pipefail
|
||||
|
||||
AWS_REGION=${region:-eu-west-1}
|
||||
AWS_DEPLOYMENT_ACCOUNT=${account:-463722570299}
|
||||
AWS_REPOSITORY=${repo:-"${AWS_DEPLOYMENT_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com"}
|
||||
|
||||
STAGE=${stage:-"dev"}
|
||||
SHA_SHORT="$(git rev-parse --short HEAD)"
|
||||
CUR_DATE="$(date +%Y%m%d%H%M%S)"
|
||||
|
|
@ -6,7 +12,7 @@ IMAGE_NAME=${image_name:-promethai-${STAGE}-promethai-backend-memory}
|
|||
|
||||
REPO_NAME="${AWS_REPOSITORY}/${IMAGE_NAME}"
|
||||
FULL_IMAGE_NAME="${REPO_NAME}:${VERSION}"
|
||||
APP_DIR=${app_dir:-"./level_2"} # Updated this line
|
||||
APP_DIR=${app_dir:-"level_2/"} # Updated this line
|
||||
|
||||
PUBLISH=${publish:-false}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ load_dotenv()
|
|||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
|
||||
app = FastAPI(debug=True)
|
||||
|
||||
from auth.cognito.JWTBearer import JWTBearer
|
||||
from auth.auth import jwks
|
||||
auth = JWTBearer(jwks)
|
||||
|
||||
from fastapi import Depends
|
||||
class ImageResponse(BaseModel):
|
||||
success: bool
|
||||
message: str
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
export ENVIRONMENT
|
||||
#python fetch_secret.py
|
||||
python fetch_secret.py
|
||||
|
||||
# Start Gunicorn
|
||||
gunicorn -w 2 -k uvicorn.workers.UvicornWorker -t 120 --bind=0.0.0.0:8000 --bind=0.0.0.0:443 --log-level debug api:app
|
||||
75
level_2/fetch_secret.py
Normal file
75
level_2/fetch_secret.py
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import os
|
||||
from dotenv import load_dotenv
|
||||
from api import start_api_server
|
||||
|
||||
# API_ENABLED = os.environ.get("API_ENABLED", "False").lower() == "true"
|
||||
import boto3
|
||||
|
||||
environment = os.getenv("AWS_ENV", "dev")
|
||||
|
||||
|
||||
|
||||
def fetch_secret(secret_name, region_name, env_file_path):
|
||||
session = boto3.session.Session()
|
||||
client = session.client(service_name="secretsmanager", region_name=region_name)
|
||||
|
||||
try:
|
||||
response = client.get_secret_value(SecretId=secret_name)
|
||||
except Exception as e:
|
||||
print(f"Error retrieving secret: {e}")
|
||||
return None
|
||||
|
||||
if "SecretString" in response:
|
||||
secret = response["SecretString"]
|
||||
else:
|
||||
secret = response["SecretBinary"]
|
||||
|
||||
with open(env_file_path, "w") as env_file:
|
||||
env_file.write(secret)
|
||||
|
||||
if os.path.exists(env_file_path):
|
||||
print(f"The .env file is located at: {os.path.abspath(env_file_path)}")
|
||||
load_dotenv()
|
||||
PINECONE_API_KEY = os.getenv("PINECONE_API_KEY", "")
|
||||
|
||||
print("LEN OF PINECONE_API_KEY", len(PINECONE_API_KEY))
|
||||
else:
|
||||
print("The .env file was not found.")
|
||||
return "Success in loading env files"
|
||||
|
||||
|
||||
env_file = ".env"
|
||||
if os.path.exists(env_file):
|
||||
# Load default environment variables (.env)
|
||||
load_dotenv()
|
||||
print("Talk to the AI!")
|
||||
|
||||
|
||||
else:
|
||||
secrets = fetch_secret(
|
||||
f"promethai-{environment}-backend-secretso-promethaijs-dotenv",
|
||||
"eu-west-1",
|
||||
".env",
|
||||
)
|
||||
if secrets:
|
||||
print(secrets)
|
||||
load_dotenv()
|
||||
|
||||
|
||||
# Check if "dev" is present in the task ARN
|
||||
if "dev" in environment:
|
||||
# Fetch the secret
|
||||
secrets = fetch_secret(
|
||||
f"promethai-dev-backend-secretso-promethaijs-dotenv",
|
||||
"eu-west-1",
|
||||
".env",
|
||||
)
|
||||
load_dotenv()
|
||||
elif "prd" in environment:
|
||||
# Fetch the secret
|
||||
secrets = fetch_secret(
|
||||
f"promethai-prd-backend-secretso-promethaijs-dotenv",
|
||||
"eu-west-1",
|
||||
".env",
|
||||
)
|
||||
load_dotenv()
|
||||
Loading…
Add table
Reference in a new issue