From 82ea096f4d5617effe5f6ae121c3f7b6c3cd708c Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 15:59:11 +0800 Subject: [PATCH 01/12] feat: add pullrequest to main --- .github/workflows/aws-preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/aws-preview.yml b/.github/workflows/aws-preview.yml index 97f39dcb..aa415277 100644 --- a/.github/workflows/aws-preview.yml +++ b/.github/workflows/aws-preview.yml @@ -5,6 +5,8 @@ on: branches: ["main"] paths: - "server/**" + pull_request: + branches: [ "main" ] env: AWS_REGION: ap-northeast-1 From 32d7dab0da51366a1737b8cd860db78d9db5e8d1 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 16:31:49 +0800 Subject: [PATCH 02/12] feat: configure github OIDC --- .github/workflows/aws-preview.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/aws-preview.yml b/.github/workflows/aws-preview.yml index aa415277..28cd4d17 100644 --- a/.github/workflows/aws-preview.yml +++ b/.github/workflows/aws-preview.yml @@ -14,6 +14,10 @@ env: 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 @@ -25,10 +29,11 @@ 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 + role-session-name: samplerolesession + audience: sts.amazonaws.com aws-region: ${{ env.AWS_REGION }} - name: Login to Amazon ECR From 77aa4a4c803e83c52f30f751c755635db53911d3 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 16:38:02 +0800 Subject: [PATCH 03/12] fix: AWS Deployment --- .github/workflows/aws-preview.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/aws-preview.yml b/.github/workflows/aws-preview.yml index 28cd4d17..097eedfd 100644 --- a/.github/workflows/aws-preview.yml +++ b/.github/workflows/aws-preview.yml @@ -32,7 +32,6 @@ jobs: uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::654654285942:role/Github-OIDC - role-session-name: samplerolesession audience: sts.amazonaws.com aws-region: ${{ env.AWS_REGION }} @@ -94,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 }} From b76c151011021f7d3879eccc8d17f05ec79fbdd3 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 16:52:47 +0800 Subject: [PATCH 04/12] fix: rename --- .aws/task_definition_preview.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index a4218e0f..1c8e6f87 100644 --- a/.aws/task_definition_preview.json +++ b/.aws/task_definition_preview.json @@ -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", @@ -47,7 +47,7 @@ } } ], - "family": "quivr-preview", + "family": "xuexiao-preview", "taskRoleArn": "arn:aws:iam::654654285942:role/ecsTaskExecutionRole", "executionRoleArn": "arn:aws:iam::654654285942:role/ecsTaskExecutionRole", "networkMode": "awsvpc", From f1db4e510ee2b7347dd2bb888367de66d684284b Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 19:07:18 +0800 Subject: [PATCH 05/12] feat: update bootstrap command --- .aws/task_definition.json | 2 +- .aws/task_definition_preview.json | 2 +- .gitignore | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.aws/task_definition.json b/.aws/task_definition.json index 0b4c017a..ed706216 100644 --- a/.aws/task_definition.json +++ b/.aws/task_definition.json @@ -18,7 +18,7 @@ "essential": true, "command": [ "uvicorn", - "main:app", + "app:handler", "--host", "0.0.0.0", "--port", diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index 1c8e6f87..6bef6a8e 100644 --- a/.aws/task_definition_preview.json +++ b/.aws/task_definition_preview.json @@ -17,7 +17,7 @@ ], "command": [ "uvicorn", - "main:app", + "app:handler", "--host", "0.0.0.0", "--port", diff --git a/.gitignore b/.gitignore index bd314a15..02e65447 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ yarn-error.log* # local env files .env*.local .env +*.env # vercel .vercel From 7f4abb164435654d9a6c4ca28409bbf4e04f99b4 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 19:16:43 +0800 Subject: [PATCH 06/12] feat: update bootstrap unicorn --- .aws/task_definition.json | 2 +- .aws/task_definition_preview.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.aws/task_definition.json b/.aws/task_definition.json index ed706216..d21477b5 100644 --- a/.aws/task_definition.json +++ b/.aws/task_definition.json @@ -18,7 +18,7 @@ "essential": true, "command": [ "uvicorn", - "app:handler", + "app:app", "--host", "0.0.0.0", "--port", diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index 6bef6a8e..5edb4f13 100644 --- a/.aws/task_definition_preview.json +++ b/.aws/task_definition_preview.json @@ -17,7 +17,7 @@ ], "command": [ "uvicorn", - "app:handler", + "app:app", "--host", "0.0.0.0", "--port", From 6ab6ad377e030f71b7ee2fb45a544da67336ef1f Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 19:24:05 +0800 Subject: [PATCH 07/12] feat: update bootstrap unicorn --- .aws/task_definition.json | 9 +-------- .aws/task_definition_preview.json | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/.aws/task_definition.json b/.aws/task_definition.json index d21477b5..53b05eae 100644 --- a/.aws/task_definition.json +++ b/.aws/task_definition.json @@ -17,14 +17,7 @@ ], "essential": true, "command": [ - "uvicorn", - "app:app", - "--host", - "0.0.0.0", - "--port", - "5050", - "--workers", - "6" + "app.handler" ], "environment": [], "environmentFiles": [ diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index 5edb4f13..5f4a23c0 100644 --- a/.aws/task_definition_preview.json +++ b/.aws/task_definition_preview.json @@ -16,14 +16,7 @@ } ], "command": [ - "uvicorn", - "app:app", - "--host", - "0.0.0.0", - "--port", - "5050", - "--workers", - "6" + "app.handler" ], "essential": true, "environment": [], From 9b7bcdb7314084dec6c16a9c59991d1078b5fb92 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 19 Mar 2024 20:11:17 +0800 Subject: [PATCH 08/12] feat: expose 80 --- .aws/task_definition.json | 6 +++--- .aws/task_definition_preview.json | 6 +++--- doc/init_aws.md | 25 ++----------------------- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/.aws/task_definition.json b/.aws/task_definition.json index 53b05eae..861c14d0 100644 --- a/.aws/task_definition.json +++ b/.aws/task_definition.json @@ -8,9 +8,9 @@ "memory": "8192", "portMappings": [ { - "name": "xuexiao-5050-tcp", - "containerPort": 5050, - "hostPort": 5050, + "name": "xuexiao-80-tcp", + "containerPort": 80, + "hostPort": 80, "protocol": "tcp", "appProtocol": "http" } diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index 5f4a23c0..174ddcb8 100644 --- a/.aws/task_definition_preview.json +++ b/.aws/task_definition_preview.json @@ -8,9 +8,9 @@ "memory": "8192", "portMappings": [ { - "name": "xuexiao-5050-tcp", - "containerPort": 5050, - "hostPort": 5050, + "name": "xuexiao-80-tcp", + "containerPort": 80, + "hostPort": 80, "protocol": "tcp", "appProtocol": "http" } diff --git a/doc/init_aws.md b/doc/init_aws.md index b1feb3e2..4b98fc5d 100644 --- a/doc/init_aws.md +++ b/doc/init_aws.md @@ -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 -``` \ No newline at end of file +#### REFERENCES +https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-private-integration.html From 01cbdf2ecc7acee9f2caefdc8895c661a86681f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Tue, 19 Mar 2024 22:13:45 +0800 Subject: [PATCH 09/12] feat: export 90 --- .aws/task_definition.json | 2 +- .aws/task_definition_preview.json | 2 +- server/Dockerfile | 8 ++++++-- server/Dockerfile.dev | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.aws/task_definition.json b/.aws/task_definition.json index 861c14d0..308b84f8 100644 --- a/.aws/task_definition.json +++ b/.aws/task_definition.json @@ -17,7 +17,7 @@ ], "essential": true, "command": [ - "app.handler" + "app:app" ], "environment": [], "environmentFiles": [ diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index 174ddcb8..ef813667 100644 --- a/.aws/task_definition_preview.json +++ b/.aws/task_definition_preview.json @@ -16,7 +16,7 @@ } ], "command": [ - "app.handler" + "app:app" ], "essential": true, "environment": [], diff --git a/server/Dockerfile b/server/Dockerfile index 208a717c..158c0a4c 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -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" ] \ No newline at end of file +EXPOSE 5050 + +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80", "--workers", "6"] \ No newline at end of file diff --git a/server/Dockerfile.dev b/server/Dockerfile.dev index 095fbea1..158c0a4c 100644 --- a/server/Dockerfile.dev +++ b/server/Dockerfile.dev @@ -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"] \ No newline at end of file +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80", "--workers", "6"] \ No newline at end of file From 59f3c3bffbfc36e3e45d62694e695001312d9fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Tue, 19 Mar 2024 22:24:05 +0800 Subject: [PATCH 10/12] =?UTF-8?q?fix=EF=BC=9Arun=20on=2080?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/app.py b/server/app.py index d827f101..d79ab8a0 100644 --- a/server/app.py +++ b/server/app.py @@ -31,4 +31,4 @@ def run_langchain_chat(input_data: ChatData): # run main.py to debug backend import uvicorn - uvicorn.run(app, host="0.0.0.0", port=5050) + uvicorn.run(app, host="0.0.0.0", port=80) From c6a4bca0ce27308a2b61ab06629b82950bc57858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Tue, 19 Mar 2024 22:34:25 +0800 Subject: [PATCH 11/12] feat: export 90 --- server/Dockerfile | 2 +- server/app.py | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index 158c0a4c..a9fcfec4 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -7,6 +7,6 @@ COPY . ${LAMBDA_TASK_ROOT} COPY requirements.txt . RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}" -U --no-cache-dir -EXPOSE 5050 +EXPOSE 80 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80", "--workers", "6"] \ No newline at end of file diff --git a/server/app.py b/server/app.py index d79ab8a0..c2fda1c0 100644 --- a/server/app.py +++ b/server/app.py @@ -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 @@ -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"} @@ -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=80) From 766fa94b8c908aa2d4a4f64b350c74d11f92e19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E6=B2=89?= Date: Tue, 19 Mar 2024 22:39:12 +0800 Subject: [PATCH 12/12] feat: export 90 --- .aws/task_definition.json | 9 +++++++-- .aws/task_definition_preview.json | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.aws/task_definition.json b/.aws/task_definition.json index 308b84f8..44761da8 100644 --- a/.aws/task_definition.json +++ b/.aws/task_definition.json @@ -16,8 +16,13 @@ } ], "essential": true, - "command": [ - "app:app" + "command": [ + "uvicorn", + "app:app", + "--host", + "0.0.0.0", + "--port", "80", + "--workers", "6" ], "environment": [], "environmentFiles": [ diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index ef813667..fc203f4b 100644 --- a/.aws/task_definition_preview.json +++ b/.aws/task_definition_preview.json @@ -15,8 +15,12 @@ "appProtocol": "http" } ], - "command": [ - "app:app" + "command": [ + "uvicorn", + "app:app", + "--host", "0.0.0.0", + "--port", "80", + "--workers", "6" ], "essential": true, "environment": [],