diff --git a/.aws/task_definition.json b/.aws/task_definition.json index 0b4c017a..44761da8 100644 --- a/.aws/task_definition.json +++ b/.aws/task_definition.json @@ -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": [ diff --git a/.aws/task_definition_preview.json b/.aws/task_definition_preview.json index a4218e0f..fc203f4b 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", @@ -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": [], @@ -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", diff --git a/.github/workflows/aws-preview.yml b/.github/workflows/aws-preview.yml index 97f39dcb..097eedfd 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 @@ -12,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 @@ -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 @@ -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 }} 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 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 diff --git a/server/Dockerfile b/server/Dockerfile index 208a717c..a9fcfec4 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 80 + +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 diff --git a/server/app.py b/server/app.py index d827f101..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=5050)