Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pullrequest to main #51

Merged
merged 12 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions .aws/task_definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@
"memory": "8192",
"portMappings": [
{
"name": "xuexiao-5050-tcp",
"containerPort": 5050,
"hostPort": 5050,
"name": "xuexiao-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"command": [
"uvicorn",
"main:app",
"--host",
"0.0.0.0",
"--port",
"5050",
"--workers",
"6"
"command": [
"uvicorn",
"app:app",
"--host",
"0.0.0.0",
"--port", "80",
"--workers", "6"
],
"environment": [],
"environmentFiles": [
Expand Down
25 changes: 11 additions & 14 deletions .aws/task_definition_preview.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:654654285942:task-definition/botmeta-preview:4",
"taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:654654285942:task-definition/xuexiao-preview:4",
"containerDefinitions": [
{
"name": "xuexiao",
Expand All @@ -8,22 +8,19 @@
"memory": "8192",
"portMappings": [
{
"name": "xuexiao-5050-tcp",
"containerPort": 5050,
"hostPort": 5050,
"name": "xuexiao-80-tcp",
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"command": [
"uvicorn",
"main:app",
"--host",
"0.0.0.0",
"--port",
"5050",
"--workers",
"6"
"command": [
"uvicorn",
"app:app",
"--host", "0.0.0.0",
"--port", "80",
"--workers", "6"
],
"essential": true,
"environment": [],
Expand All @@ -47,7 +44,7 @@
}
}
],
"family": "quivr-preview",
"family": "xuexiao-preview",
"taskRoleArn": "arn:aws:iam::654654285942:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::654654285942:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/aws-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ on:
branches: ["main"]
paths:
- "server/**"
pull_request:
branches: [ "main" ]

env:
AWS_REGION: ap-northeast-1
ECR_REPOSITORY: xuexiao
ECR_REGISTRY: 654654285942.dkr.ecr.ap-northeast-1.amazonaws.com
ECS_CLUSTER: xuexiao

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
build_and_push:
name: Build and Push Docker Image
Expand All @@ -23,10 +29,10 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: arn:aws:iam::654654285942:role/Github-OIDC
audience: sts.amazonaws.com
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
Expand Down Expand Up @@ -87,10 +93,10 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
role-to-assume: arn:aws:iam::654654285942:role/Github-OIDC
audience: sts.amazonaws.com
aws-region: ${{ env.AWS_REGION }}

- name: Fill in the new image ID in the Amazon ECS task definition for ${{ matrix.name }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ yarn-error.log*
# local env files
.env*.local
.env
*.env
# vercel
.vercel

Expand Down
25 changes: 2 additions & 23 deletions doc/init_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,6 @@ Docker Compose's integration for ECS and ACI will be retired in November 2023. L
Successfully created ecs context "botmetaecscontext"
```

The current context in use is marked by * in the output of context listing:

```bash
$ docker context ls
```

```
NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
botmetaecscontext ecs
default moby Current DOCKER_HOST based configuration unix:///var/run/docker.sock
```

To make all subsequent commands target Amazon ECS, make the newly created ECS context the one in use by running:

```bash
docker context use botmetaecscontext
```


Docker Compose converts the Compose file to a CloudFormation template defining a set of AWS resources. Details on the resource mapping can be found in the documentation. To review the CloudFormation template generated, we can run the command:

```bash
$ docker compose convert
```
#### REFERENCES
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-private-integration.html
8 changes: 6 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM public.ecr.aws/lambda/python:3.10
# Using a slim version for a smaller base image
FROM python:3.11.6-slim-bullseye

# Copy function code
COPY . ${LAMBDA_TASK_ROOT}
# from your project folder.
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}" -U --no-cache-dir

CMD [ "app.handler" ]
EXPOSE 80

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80", "--workers", "6"]
2 changes: 1 addition & 1 deletion server/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}" -U --no-cach

EXPOSE 5050

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5050", "--workers", "6"]
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80", "--workers", "6"]
10 changes: 1 addition & 9 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from fastapi import FastAPI
from mangum import Mangum

from data_class import DalleData, ChatData
from openai_api import dalle
Expand All @@ -9,9 +8,8 @@
open_api_key = os.getenv("OPENAI_API_KEY")

app = FastAPI()
handler = Mangum(app)

@app.get("/api/greetings")
@app.get("/")
def read_root():
return {"Hello": "World"}

Expand All @@ -26,9 +24,3 @@ def run_img_generator(input_data: DalleData):
def run_langchain_chat(input_data: ChatData):
result = chat.langchain_chat(input_data, open_api_key)
return result

if __name__ == "__main__":
# run main.py to debug backend
import uvicorn

uvicorn.run(app, host="0.0.0.0", port=5050)
Loading