Skip to content

fix: AI 모델 다운로드 권한 문제 해결 #58

fix: AI 모델 다운로드 권한 문제 해결

fix: AI 모델 다운로드 권한 문제 해결 #58

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Extract Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=sha-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Development 배포는 VPC 내부 통신에서 불필요하므로 제거
deploy-production:
needs: build-and-push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Checkout Config Repository
uses: actions/checkout@v4
with:
repository: UruruLab/Ururu-AI-Config
path: config
token: ${{ secrets.GHCR_TOKEN }}
- name: Copy Production Environment Config Files
run: |
if compgen -G "config/.env*" > /dev/null; then
if [ -f "config/.env.production" ]; then
cp config/.env.production .env.production
echo "✅ Production environment config files copied successfully"
else
echo "❌ .env.production not found in config repository"
exit 1
fi
else
echo "❌ No config files found in config repository"
exit 1
fi
- name: Deploy to FastAPI Production EC2
uses: appleboy/ssh-action@v0.1.6
env:
GITHUB_SHA: ${{ github.sha }}
with:
host: ${{ secrets.AI_EC2_HOST }}
username: ${{ secrets.AI_EC2_USER }}
key: ${{ secrets.AI_EC2_SSH_KEY }}
port: 22
timeout: 1200s
envs: GITHUB_SHA
script: |
set -e
echo "🚀 FastAPI AI 서비스 배포 시작"
# 기존 컨테이너 상태 확인
if docker ps | grep ururu-ai-service; then
echo "📊 기존 AI 서비스 로그 확인"
docker logs --tail 10 ururu-ai-service
fi
# 작업 디렉토리 생성 및 이동
mkdir -p /home/ec2-user/ururu-ai
cd /home/ec2-user/ururu-ai
# 코드 업데이트 (올바른 디렉토리)
if [ ! -d ".git" ]; then
echo "📥 레포지토리 초기 클론"
git clone https://github.com/UruruLab/Ururu-AI.git .
else
echo "🔄 코드 업데이트"
git fetch origin
git checkout main
git reset --hard origin/main
fi
- name: Copy Config to EC2
uses: appleboy/scp-action@v0.1.4
with:
host: ${{ secrets.AI_EC2_HOST }}
username: ${{ secrets.AI_EC2_USER }}
key: ${{ secrets.AI_EC2_SSH_KEY }}
port: 22
source: ".env.production"
target: "/home/ec2-user/ururu-ai/"
- name: Continue Deployment
uses: appleboy/ssh-action@v0.1.6
env:
GITHUB_SHA: ${{ github.sha }}
with:
host: ${{ secrets.AI_EC2_HOST }}
username: ${{ secrets.AI_EC2_USER }}
key: ${{ secrets.AI_EC2_SSH_KEY }}
port: 22
timeout: 1200s
envs: GITHUB_SHA
script: |
set -e
cd /home/ec2-user/ururu-ai
# Config 파일 확인
echo "📝 Config 파일 확인"
if [ ! -f ".env.production" ]; then
echo "❌ .env.production 파일이 없습니다."
exit 1
else
echo "✅ .env.production 파일 확인됨"
fi
# Docker 컨테이너 배포
echo "🐳 Docker 컨테이너 배포"
cd docker/
docker-compose -f docker-compose-ai-prod.yml down || true
docker-compose -f docker-compose-ai-prod.yml up -d --build
echo "⏳ AI 모델 로딩 대기 중 (60초)..."
sleep 60
# 헬스체크
echo "🔍 헬스체크 시작"
echo "📋 컨테이너 상태 확인"
docker ps | grep ururu-ai-service || echo "컨테이너를 찾을 수 없습니다"
echo "📝 컨테이너 로그 확인"
docker logs --tail 10 ururu-ai-service || echo "로그를 가져올 수 없습니다"
for i in {1..120}; do
echo "헬스체크 시도 $i/120"
# 컨테이너가 실행 중인지 확인
if ! docker ps | grep ururu-ai-service > /dev/null; then
echo "❌ 컨테이너가 중지되었습니다"
docker logs --tail 20 ururu-ai-service
exit 1
fi
# 헬스체크 시도
if curl -f http://localhost:8000/health 2>/dev/null; then
echo "✅ FastAPI 서비스 헬스체크 통과"
break
fi
if [ $i -eq 120 ]; then
echo "❌ 헬스체크 실패 (20분 타임아웃)"
echo "📝 최종 컨테이너 로그:"
docker logs --tail 50 ururu-ai-service
echo "📊 컨테이너 상태:"
docker ps -a | grep ururu-ai-service
exit 1
fi
sleep 10
done
# 벡터 인덱스 상태 확인
echo "📊 벡터 인덱스 상태 확인"
VECTOR_STATUS=$(curl -s http://localhost:8000/api/vector/status | grep -o '"total_vectors":[0-9]*' | cut -d':' -f2 || echo "0")
echo "벡터 인덱스 상태: $VECTOR_STATUS 개 벡터"
# 임베딩 재생성 (필요시)
if [ "$VECTOR_STATUS" -lt 1000 ]; then
echo "🔄 벡터 인덱스 재생성 시작"
curl -X POST "http://localhost:8000/api/vector/embeddings/batch?batch_size=100&force_recreate=false" || echo "임베딩 재생성 요청 실패"
fi
echo "🎉 FastAPI AI 서비스 배포 완료"
echo "$(date): FastAPI AI 서비스 배포 완료 - commit: $GITHUB_SHA" >> /home/ec2-user/deployment.log
- name: Deployment Notification
if: always()
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "✅ FastAPI AI 서비스 배포 성공"
echo "🌐 AI 서비스: http://43.200.204.67:8000"
echo "📚 API 문서: http://43.200.204.67:8000/docs"
echo "🔗 Spring Boot 연동 준비 완료"
else
echo "❌ FastAPI AI 서비스 배포 실패"
echo "📝 로그 확인: docker logs ururu-ai-service"
echo "🔧 문제 해결 후 다시 배포하세요"
fi