diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml new file mode 100644 index 0000000..0a7134b --- /dev/null +++ b/.github/workflows/ci-test.yml @@ -0,0 +1,50 @@ +name: KTB 해커톤 14조 PR CI 파이프라인 + +on: + pull_request: + branches: [ "develop"] + +jobs: + + test: + runs-on: ubuntu-22.04 + if: success() + steps: + - name: 코드 체크아웃 + uses: actions/checkout@v4 + + - name: 파이썬 의존성 설치 + uses: actions/setup-python@v4 + with: + python-version: "3.10.19" + + - name: 의존성 설치 + run: pip install -r requirements.txt + + - name: Ruff 문법 오류 코드 검사 + run: ruff check . + + notify-discord: + runs-on: ubuntu-22.04 + needs: test + if: always() + steps: + - name: Discord 빌드 알림 + uses: sarisia/actions-status-discord@v1 + with: + webhook: ${{ secrets.DISCORD_WEBHOOK_AI_PR_URL }} + title: "${{ needs.build.result == 'success' && '✅' || '❌' }} 새로운 PR이 올라왔습니다!" + description: | + **제목**: ${{ github.event.pull_request.title }} + **작성자**: ${{ github.event.pull_request.user.login }} + **브랜치**: `${{ github.event.pull_request.base.ref }}`←`${{ github.event.pull_request.head.ref }}` + + **📊 빌드 결과**: + - 상태: ${{ needs.build.result == 'success' && '성공' || '실패' }} + + **🔗 링크**: + - [PR 확인하기](${{ github.event.pull_request.html_url }}) + + color: "${{ needs.build.result == 'success' && 65280 || 16711680 }}" + username: GitHub PR Bot + avatar_url: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png \ No newline at end of file diff --git a/.github/workflows/cicd-prod.yml b/.github/workflows/cicd-prod.yml new file mode 100644 index 0000000..7d269dc --- /dev/null +++ b/.github/workflows/cicd-prod.yml @@ -0,0 +1,123 @@ +name: KTB 해커톤 14조 CICD 파이프라인 + +on: + push: + branches: + - develop + +jobs: + test: + runs-on: ubuntu-22.04 + if: success() + steps: + - name: 코드 체크아웃 + uses: actions/checkout@v4 + + - name: 파이썬 의존성 설치 + uses: actions/setup-python@v4 + with: + python-version: "3.10.19" + + - name: 의존성 설치 + run: pip install -r requirements.txt + + - name: Ruff 문법 오류 코드 검사 + run: ruff check . + + # 테스트가 모두 통과했을 때만, 도커 이미지 빌드 + 푸시하기 + build-push-image: + runs-on: ubuntu-22.04 + needs: test + permissions: + contents: read + steps: + - name: 코드 체크아웃 + uses: actions/checkout@v4 + + - name: Docker Buildx 설정 + uses: docker/setup-buildx-action@v3 + + - name: Docker 로그인 + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_ACCESS_TOKEN }} + + - name: Docker 이미지 빌드 & Push + uses: docker/build-push-action@v5 + with: + context: . + file: Dockerfile + platforms: linux/amd64 + push: true + tags: | + ${{ secrets.DOCKER_USERNAME }}/ktb-ai:latest + ${{ secrets.DOCKER_USERNAME }}/ktb-ai:${{ github.sha }} + + deploy: + runs-on: ubuntu-22.04 + needs: build-push-image + if: success() + steps: + - name: 체크아웃 + uses: actions/checkout@v4 + + - name: env 생성 + run: echo "${{ secrets.ENV }}" > .env + + - name: .env 파일 EC2에 전송 + uses: appleboy/scp-action@master + with: + host: ${{ secrets.EC2_PUBLIC_IP }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + source: ".env" # 방금 생성한 .env 파일 + target: "/home/ubuntu/app/" + + - name: docker-compose.yml 전달 + uses: appleboy/scp-action@master + with: + host: ${{ secrets.EC2_PUBLIC_IP }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + source: "docker-compose.yml" + target: "/home/ubuntu/app/" + + - name: EC2에서 docker-compose 실행 + uses: appleboy/ssh-action@master # SSH를 사용하여 EC2에서 명령 실행 + with: + host: ${{ secrets.EC2_PUBLIC_IP }} # EC2 퍼블릭 IP + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + script: | + # docker-compose 명령어 실행 + cd /home/ubuntu/app/ + docker compose pull + docker compose up -d fastapi + docker compose ps + + + notify-discord: + runs-on: ubuntu-22.04 + needs: deploy + if: always() + steps: + - name: Discord 배포 요청 알림 + uses: sarisia/actions-status-discord@v1 + with: + webhook: ${{ secrets.DISCORD_WEBHOOK_AI_URL }} + title: "${{ needs.deploy.result == 'success' && '✅' || '❌' }} develop 브랜치 배포 결과" + description: | + **커밋 메시지**: ${{ github.event.head_commit.message }} + **작성자**: ${{ github.event.pusher.name }} + **브랜치**: `${{ github.ref_name }}` + + **📊 빌드/배포 결과**: + - 상태: ${{ needs.deploy.result == 'success' && '성공' || '실패' }} + + **🔗 링크**: + - [커밋 확인하기](${{ github.event.head_commit.url }}) + + color: "${{ needs.deploy.result == 'success' && 65280 || 16711680 }}" + username: GitHub Deploy Bot + avatar_url: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bae36ea --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# 파이썬 의존성 설치 +FROM python:3.10.19-slim + +# 파일 이동 +WORKDIR /app + +# 의존성 설치 +COPY requirements.txt requirements.txt +RUN pip install -r requirements.txt + +# 코드 복사 +COPY . . + +# fastAPI 실행하기 +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5b1ce24 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + + fastapi: + image: wpgur07/ai:latest + container_name: zeusAI-app + ports: + - '8000:8000' + env_file: + - .env + restart: always \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..31b1c33 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[tool.ruff] +target-version = "py310" +line-length = 88 + +[tool.ruff.lint] +select = [] diff --git a/requirements.txt b/requirements.txt index 8a9923f..5e40243 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,4 +15,6 @@ langchain-openai==0.1.25 langchain-chroma==0.1.4 tiktoken==0.7.0 -chromadb==0.5.3 \ No newline at end of file +chromadb==0.5.3 + +ruff==0.6.9