diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..659b2db --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,27 @@ +name: Continuous Deployment + +on: + push: + branches: [ main ] + workflow_dispatch: # 수동 트리거 옵션 추가 + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Deploy to production server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.PROD_HOST }} + username: ${{ secrets.PROD_USERNAME }} + key: ${{ secrets.PROD_SSH_KEY }} + script: | + cd ~/ai-server-test + git remote update + git checkout main + git pull origin main + make # Makefile을 통한 배포 \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c9f69bd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: Continuous Integration + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop, main ] + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Install Docker Compose + run: | + sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + docker-compose --version + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build with docker-compose + run: docker-compose -f docker-compose.test.yml build + + # - name: Move cache + # run: | + # rm -rf /tmp/.buildx-cache + # mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + - name: Run tests + run: | + docker-compose -f docker-compose.test.yml up -d + + # 잠시 대기 + sleep 10 + + # 간단한 상태 확인 + curl -f http://localhost:80/health || exit 1 + + # 컨테이너 종료 + docker-compose -f docker-compose.test.yml down + + - name: Cleanup + if: always() + run: docker-compose -f docker-compose.test.yml down -v \ No newline at end of file diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml deleted file mode 100644 index 15a61d6..0000000 --- a/.github/workflows/github-actions-demo.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 -on: [push] -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/.gitignore b/.gitignore index e4ac5bb..9bd411d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ .env __pycache__ data -vectordb tmux-script/ \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..83ac0e7 --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,25 @@ + +services: + ai-server: + init: true + container_name: ai-server + environment: + OPENAI_API_KEY: "testapikey" + build: + context: ./srcs/ai-server + dockerfile: Dockerfile # 아래에 Dockerfile 예시 참고 + volumes: + - ./srcs/ai-server/project:/project + ports: + - "80:8000" # 호스트의 8000 포트를 컨테이너의 8000 포트 + + ai-preprocessing: + init: true + container_name: ai-preprocessing + environment: + OPENAI_API_KEY: "testapikey" + build: + context: ./srcs/ai-preprocessing + dockerfile: Dockerfile # 아래에 Dockerfile 예시 참고 + volumes: + - ./srcs/ai-preprocessing/project:/project \ No newline at end of file diff --git a/srcs/ai-preprocessing/Dockerfile b/srcs/ai-preprocessing/Dockerfile index 66f773d..ce0da5a 100644 --- a/srcs/ai-preprocessing/Dockerfile +++ b/srcs/ai-preprocessing/Dockerfile @@ -1,5 +1,11 @@ -FROM jeongtj/langchain-rag +# FROM jeongtj/langchain-rag +FROM python:3.11-slim WORKDIR /project +COPY ./requirements.txt /project/ + +RUN pip install -r requirements.txt + + CMD ["tail", "-f", "/dev/null"] diff --git a/srcs/ai-preprocessing/requirements.txt b/srcs/ai-preprocessing/requirements.txt new file mode 100644 index 0000000..42bc588 --- /dev/null +++ b/srcs/ai-preprocessing/requirements.txt @@ -0,0 +1,13 @@ +pandas +tqdm +python-dotenv +langchain-community +langchain-openai +langchain-core +faiss-cpu +langsmith +cohere +networkx +requests +langchain +langchainhub \ No newline at end of file diff --git a/srcs/ai-server/Dockerfile b/srcs/ai-server/Dockerfile index 38e8c9c..1c7cca2 100644 --- a/srcs/ai-server/Dockerfile +++ b/srcs/ai-server/Dockerfile @@ -1,9 +1,14 @@ -FROM jeongtj/langchain-rag +# FROM jeongtj/langchain-rag +FROM python:3.11-slim WORKDIR /project -COPY requirements.txt /project/ -COPY entrypoint.sh /home/entrypoint.sh +RUN apt update && apt install -y curl + +COPY ./requirements.txt /project/ +COPY ./entrypoint.sh /home/entrypoint.sh + +RUN sed -i 's/\r//' /home/entrypoint.sh RUN pip install -r requirements.txt RUN chmod +x /home/entrypoint.sh diff --git a/srcs/ai-server/entrypoint.sh b/srcs/ai-server/entrypoint.sh index 3cac2da..b915ffd 100644 --- a/srcs/ai-server/entrypoint.sh +++ b/srcs/ai-server/entrypoint.sh @@ -1,2 +1,34 @@ #!/bin/bash -uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload \ No newline at end of file + +# 환경 변수에 따라 실행 모드 결정 +if [ "$ENV" = "test" ]; then + echo "Running in TEST mode" + + # 백그라운드에서 uvicorn 실행 + uvicorn app.main:app --host 0.0.0.0 --port 8000 & + UVICORN_PID=$! + + # 서버가 시작될 때까지 대기 + echo "Waiting for server to start..." + sleep 5 + + # 서버가 실행 중인지 확인 + if curl -s http://localhost:8000/health > /dev/null; then + echo "Server is running correctly" + # 서버 종료 - 더 강력한 종료 시그널 사용 + echo "Shutting down server..." + kill -9 $UVICORN_PID + wait $UVICORN_PID 2>/dev/null || true + echo "Server shutdown complete" + exit 0 + else + echo "Server failed to start properly" + kill -9 $UVICORN_PID + wait $UVICORN_PID 2>/dev/null || true + exit 1 + fi +else + # 프로덕션 모드 실행 + echo "Running in PRODUCTION mode" + uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4 +fi \ No newline at end of file diff --git a/srcs/ai-server/project/app/main.py b/srcs/ai-server/project/app/main.py index 814db09..3b88a77 100644 --- a/srcs/ai-server/project/app/main.py +++ b/srcs/ai-server/project/app/main.py @@ -21,3 +21,7 @@ @app.get("/") async def root(): return {"message": "Travel Agent API is running"} + +@app.get("/health") +async def root(): + return {"status": "ok"} diff --git a/srcs/ai-server/project/app/utils/vectordb.py b/srcs/ai-server/project/app/utils/vectordb.py index 48ed52d..2c889e6 100644 --- a/srcs/ai-server/project/app/utils/vectordb.py +++ b/srcs/ai-server/project/app/utils/vectordb.py @@ -18,6 +18,10 @@ def load_vectordb(index_name: str): project_root = Path(__file__).parent.parent.parent vectordb_path = project_root / "vectordb" / index_name + if not vectordb_path.exists(): + index_name = "dummy_finder" + vectordb_path = project_root / "vectordb" / index_name + if not vectordb_path.exists(): raise FileNotFoundError(f"Vector DB not found at {vectordb_path}") diff --git a/srcs/ai-server/project/vectordb/dummy_finder/index.faiss b/srcs/ai-server/project/vectordb/dummy_finder/index.faiss new file mode 100644 index 0000000..e2f2f61 Binary files /dev/null and b/srcs/ai-server/project/vectordb/dummy_finder/index.faiss differ diff --git a/srcs/ai-server/project/vectordb/dummy_finder/index.pkl b/srcs/ai-server/project/vectordb/dummy_finder/index.pkl new file mode 100644 index 0000000..03492ef Binary files /dev/null and b/srcs/ai-server/project/vectordb/dummy_finder/index.pkl differ diff --git a/srcs/ai-server/requirements.txt b/srcs/ai-server/requirements.txt index d1f80a3..d339661 100644 --- a/srcs/ai-server/requirements.txt +++ b/srcs/ai-server/requirements.txt @@ -1,2 +1,15 @@ uvicorn -fastapi \ No newline at end of file +fastapi +pandas +tqdm +python-dotenv +langchain-community +langchain-openai +langchain-core +faiss-cpu +langsmith +cohere +networkx +requests +langchain +langchainhub \ No newline at end of file