From df99caafb066e2951e71fd777159611917bddc31 Mon Sep 17 00:00:00 2001 From: bleuxsy <100823803+bleuxsy@users.noreply.github.com> Date: Mon, 25 Aug 2025 13:16:07 +0900 Subject: [PATCH 1/6] feat: Add the log template for Ai #5 --- .github/workflows/ai-workflow.yml | 21 +++++++--------- msa-ai-service/task-definition.json | 37 ++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ai-workflow.yml b/.github/workflows/ai-workflow.yml index cf7550b..c102228 100644 --- a/.github/workflows/ai-workflow.yml +++ b/.github/workflows/ai-workflow.yml @@ -1,7 +1,5 @@ -name: CI/CD for AI Service - - +name: CI/CD for 00 Service on: push: branches: [ "release/1.0.0" ] @@ -16,7 +14,7 @@ env: ECS_TASK_DEFINITION_FAMILY: ai-service-td CONTAINER_NAME: msa-ai-service -# GitHub Actions Runner에 부여할 권한 + permissions: id-token: write contents: read @@ -25,28 +23,28 @@ jobs: build-and-deploy: runs-on: ubuntu-latest steps: - # 1. 소스 코드 체크아웃 + - name: Checkout code uses: actions/checkout@v4 - # 2. AWS 자격 증명 설정 (OIDC 역할 사용) + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::490913547024:role/gitactionToECR # 기존에 사용하던 역할 ARN aws-region: ${{ env.AWS_REGION }} - # 3. Amazon ECR 로그인 + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 - # 4. 이미지 태그로 사용할 짧은 Git 커밋 해시 생성 + - name: Set short git commit SHA id: vars run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - # 5. Docker 이미지 빌드 및 ECR에 푸시 + - name: Build, tag, and push image to Amazon ECR id: build-image env: @@ -57,7 +55,7 @@ jobs: docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT - # 6. 최신 ECS 태스크 정의 파일 다운로드 + - name: Download task definition id: download-task-def @@ -68,7 +66,6 @@ jobs: - name: Clean task definition for old SDK id: clean-task-def run: | - # jq를 사용해 다운로드한 파일에서 enableFaultInjection 키를 삭제합니다. jq 'del(.enableFaultInjection)' ${{ steps.download-task-def.outputs.file }} > cleaned-task-def.json echo "file=cleaned-task-def.json" >> $GITHUB_OUTPUT @@ -80,7 +77,7 @@ jobs: container-name: ${{ env.CONTAINER_NAME }} image: ${{ steps.build-image.outputs.image }} - # 8. 새로운 태스크 정의를 ECS 서비스에 배포 + - name: Deploy Amazon ECS task definition uses: aws-actions/amazon-ecs-deploy-task-definition@v1 with: diff --git a/msa-ai-service/task-definition.json b/msa-ai-service/task-definition.json index 4ad9960..82de17a 100644 --- a/msa-ai-service/task-definition.json +++ b/msa-ai-service/task-definition.json @@ -22,21 +22,46 @@ "value": "dev" } ], - "environmentFiles": [], "mountPoints": [], "volumesFrom": [], - "ulimits": [], + "logConfiguration": { + "logDriver": "awsfirelens", + "options": { + "Host": "loki-service.msa-service", + "Labels": "job=ai-service, cluster=DevCluster, service=ai-service", + "Name": "loki", + "Port": "3100" + } + }, + "systemControls": [] + }, + { + "name": "log_router", + "image": "public.ecr.aws/aws-observability/aws-for-fluent-bit:stable", + "cpu": 0, + "memoryReservation": 51, + "portMappings": [], + "essential": false, + "environment": [], + "mountPoints": [], + "volumesFrom": [], + "user": "0", "logConfiguration": { "logDriver": "awslogs", "options": { - "awslogs-group": "/ecs/ai-service-td", + "awslogs-group": "/ecs/firelens-log-router", "awslogs-create-group": "true", "awslogs-region": "ap-northeast-2", "awslogs-stream-prefix": "ecs" - }, - "secretOptions": [] + } }, - "systemControls": [] + "systemControls": [], + "firelensConfiguration": { + "type": "fluentbit", + "options": { + "enable-ecs-log-metadata": "true" + } + } } ], "family": "ai-service-td", From b97888a68e87861f279a00eb0a5bde6e155382e8 Mon Sep 17 00:00:00 2001 From: bleuxsy <100823803+bleuxsy@users.noreply.github.com> Date: Mon, 25 Aug 2025 15:13:14 +0900 Subject: [PATCH 2/6] feat: Add the log params for ai #5 --- msa-ai-service/app/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/msa-ai-service/app/main.py b/msa-ai-service/app/main.py index 7455ab6..f25c1e7 100644 --- a/msa-ai-service/app/main.py +++ b/msa-ai-service/app/main.py @@ -13,6 +13,7 @@ app = FastAPI(title="MSA AI Service") + app.include_router(health.router, prefix="/ai", tags=["health"]) app.include_router(seed_router.router, prefix="/ai", tags=["seed"]) app.include_router(qa_router.router, prefix="/ai", tags=["qa"]) From 8b3906c51ab8f61fe607e84733fc83591c3f8e8b Mon Sep 17 00:00:00 2001 From: bleuxsy <100823803+bleuxsy@users.noreply.github.com> Date: Mon, 25 Aug 2025 15:23:35 +0900 Subject: [PATCH 3/6] feat: Add the log params for ai #5 --- msa-ai-service/log_config.yaml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 msa-ai-service/log_config.yaml diff --git a/msa-ai-service/log_config.yaml b/msa-ai-service/log_config.yaml new file mode 100644 index 0000000..b331b51 --- /dev/null +++ b/msa-ai-service/log_config.yaml @@ -0,0 +1,34 @@ +version: 1 +disable_existing_loggers: false +formatters: + default: + (): "uvicorn.logging.DefaultFormatter" + fmt: "%(levelprefix)s %(message)s" + use_colors: null + access: + (): "uvicorn.logging.AccessFormatter" + # 아래 fmt와 datefmt를 수정하여 접속 로그 형식을 바꿀 수 있습니다. + fmt: '%(asctime)s %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s' + datefmt: "%Y-%m-%d %H:%M:%S" # 원하는 날짜/시간 포맷 +handlers: + default: + formatter: default + class: logging.StreamHandler + stream: ext://sys.stderr + access: + formatter: access + class: logging.StreamHandler + stream: ext://sys.stdout +loggers: + uvicorn: + handlers: + - default + level: INFO + propagate: false + uvicorn.error: + level: INFO + uvicorn.access: + handlers: + - access + level: INFO + propagate: false \ No newline at end of file From 16c73d022c9865028138002a474cbb5f167f3087 Mon Sep 17 00:00:00 2001 From: bleuxsy <100823803+bleuxsy@users.noreply.github.com> Date: Mon, 25 Aug 2025 15:31:04 +0900 Subject: [PATCH 4/6] feat: Add the log params for ai #5 --- msa-ai-service/Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/msa-ai-service/Dockerfile b/msa-ai-service/Dockerfile index 63aa625..6895298 100644 --- a/msa-ai-service/Dockerfile +++ b/msa-ai-service/Dockerfile @@ -5,6 +5,10 @@ WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt +# 1. log_config.yaml 파일을 컨테이너 안으로 복사하는 라인 추가 +COPY log_config.yaml . + COPY . . -CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] +# 2. CMD 명령어에 --log-config 옵션 추가 +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-config", "log_config.yaml"] \ No newline at end of file From f71f56904ffb6f66ce69251dcff007741816bdef Mon Sep 17 00:00:00 2001 From: miiiniii Date: Wed, 27 Aug 2025 15:27:19 +0900 Subject: [PATCH 5/6] fix: Change task-definition.json --- msa-ai-service/task-definition.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/msa-ai-service/task-definition.json b/msa-ai-service/task-definition.json index 82de17a..eb2cd1a 100644 --- a/msa-ai-service/task-definition.json +++ b/msa-ai-service/task-definition.json @@ -17,10 +17,10 @@ ], "essential": true, "environment": [ - { - "name": "SPRING_PROFILES_ACTIVE", - "value": "dev" - } + { "name": "ENV", "value": "prod" }, + { "name": "MONGODB_URI", "value": "mongodb+srv://ksm3255:!4786buch@team1mongodb.oh0o0np.mongodb.net/?retryWrites=true&w=majority&appName=Team1Mongodb" }, + { "name": "MONGODB_NAME", "value": "ai_service_db" }, + { "name": "OPENAI_API_KEY", "value": "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" } ], "mountPoints": [], "volumesFrom": [], From 158dfb01160924333c7fbcde3ebf5efd2bb3adbb Mon Sep 17 00:00:00 2001 From: miiiniii Date: Wed, 10 Sep 2025 14:39:40 +0900 Subject: [PATCH 6/6] chore: Add SSL certificate to Dockerfile #17 --- msa-ai-service/Dockerfile | 6 ++++++ msa-ai-service/app/core/config.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/msa-ai-service/Dockerfile b/msa-ai-service/Dockerfile index 63aa625..92cc422 100644 --- a/msa-ai-service/Dockerfile +++ b/msa-ai-service/Dockerfile @@ -2,6 +2,12 @@ FROM python:3.10-slim WORKDIR /app +# SSL 인증서와 필요한 툴 설치 +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + && rm -rf /var/lib/apt/lists/* + COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt diff --git a/msa-ai-service/app/core/config.py b/msa-ai-service/app/core/config.py index 1885309..6101958 100644 --- a/msa-ai-service/app/core/config.py +++ b/msa-ai-service/app/core/config.py @@ -14,5 +14,5 @@ MONGODB_NAME = os.getenv("MONGODB_NAME", "ai_service_db") OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") -REVIEW_LABELS = ["quantity", "size", "sweet", "salty", "spicy", "deep"] +REVIEW_LABELS = ["quantity", "size", "sweet", "salty", "spicy", "deep", "sour"] POLARITY_LABELS = ["POSITIVE", "NEGATIVE"] \ No newline at end of file