-
Notifications
You must be signed in to change notification settings - Fork 1
Spring Boot AI 서비스 연동 502 에러 해결 #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
410bd70
c084cc5
cf50c42
914fdaa
e60b805
2a1f05c
77c39d5
4828c77
8d1e157
817f786
780b421
ada0611
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,63 +94,14 @@ jobs: | |
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| file: ./Dockerfile | ||
| 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 | ||
|
|
||
| deploy-development: | ||
| needs: build-and-push | ||
| runs-on: ubuntu-latest | ||
| if: github.ref == 'refs/heads/develop' | ||
| environment: development | ||
|
|
||
| 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.PRIVATE_REPO_TOKEN }} | ||
|
|
||
| - name: Copy Development Environment Config Files | ||
| run: | | ||
| if compgen -G "config/.env*" > /dev/null; then | ||
| if [ -f "config/.env.development" ]; then | ||
| cp config/.env.development .env.development | ||
| echo "✅ Development environment config files copied successfully" | ||
| else | ||
| echo "❌ .env.development not found in config repository" | ||
| exit 1 | ||
| fi | ||
| else | ||
| echo "❌ No config files found in config repository" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Validate Docker Compose Configuration | ||
| run: | | ||
| echo "Validating development environment configuration files" | ||
| echo "Validating docker-compose.development.yml syntax" | ||
| ENVIRONMENT=development docker compose -f docker-compose.development.yml config --quiet | ||
| echo "Verifying environment variable bindings" | ||
| ENVIRONMENT=development docker compose -f docker-compose.development.yml config \ | ||
| | grep -A 10 "environment:" \ | ||
| | grep "^[[:space:]]*[[:alpha:]]" \ | ||
| | sed 's/.*$/&<redacted>/' || true | ||
| echo "Development environment deployment preparation completed" | ||
|
|
||
| - name: Simulate Deployment (No actual EC2 deployment) | ||
| run: | | ||
| echo "Development environment deployment simulation" | ||
| echo "- Docker Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop" | ||
| echo "- Config File: .env.development (fetched from Config repository)" | ||
| echo "Development environment deployment configuration completed" | ||
| # Development 배포는 VPC 내부 통신에서 불필요하므로 제거 | ||
|
|
||
| deploy-production: | ||
| needs: build-and-push | ||
|
|
@@ -167,7 +118,7 @@ jobs: | |
| with: | ||
| repository: UruruLab/Ururu-AI-Config | ||
| path: config | ||
| token: ${{ secrets.PRIVATE_REPO_TOKEN }} | ||
| token: ${{ secrets.GHCR_TOKEN }} | ||
|
|
||
| - name: Copy Production Environment Config Files | ||
| run: | | ||
|
|
@@ -187,25 +138,129 @@ jobs: | |
| - name: Validate Docker Compose Configuration | ||
| run: | | ||
| echo "Validating production environment configuration files" | ||
| echo "Validating docker-compose.production.yml syntax" | ||
| ENVIRONMENT=production docker compose -f docker-compose.production.yml config --quiet | ||
| echo "Verifying environment variable bindings" | ||
| ENVIRONMENT=production docker compose -f docker-compose.production.yml config \ | ||
| | grep -A 10 "environment:" \ | ||
| | grep "^[[:space:]]*[[:alpha:]]" \ | ||
| | sed 's/.*$/&<redacted>/' || true | ||
| echo "Production environment deployment preparation completed" | ||
|
|
||
| - name: Prepare Deployment Notification | ||
| run: | | ||
| echo "Production environment deployment preparation completed" | ||
| echo "- Docker Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" | ||
| echo "- Config File: .env.production (fetched from Config repository)" | ||
| echo "Actual EC2 deployment will be handled by separate process" | ||
| - name: Deploy to FastAPI Production EC2 | ||
| uses: appleboy/ssh-action@v0.1.6 | ||
| with: | ||
| host: ${{ secrets.AI_EC2_HOST }} # 새로운 FastAPI EC2 | ||
| username: ${{ secrets.AI_EC2_USER }} # ec2-user | ||
| key: ${{ secrets.AI_EC2_SSH_KEY }} # 새로운 EC2 키 | ||
| port: 22 | ||
| timeout: 600s | ||
| script: | | ||
|
Comment on lines
+143
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SSH 배포 스크립트에 + # 예시: 파일 전송
+ - name: Upload .env.production
+ uses: appleboy/scp-action@v0.1.4
+ with:
+ host: ${{ secrets.AI_EC2_HOST }}
+ username: ${{ secrets.AI_EC2_USER }}
+ key: ${{ secrets.AI_EC2_SSH_KEY }}
+ source: ".env.production"
+ target: "/home/ec2-user/ururu-ai/.env.production"🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SSH 배포 스크립트가 더 간결하고 명확해졌습니다. 이 구조로 적용하겠습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @23MinL 좋은 결정입니다! 직접 파일 업로드 방식은 확실히 더 투명하고 안전한 접근법이죠. scp-action을 사용하면 파일 전송 과정이 명시적으로 분리되어 디버깅도 더 쉬워지고, 스크립트 내에서 파일 생성 로직이 복잡해지는 것도 방지할 수 있습니다. 배포 파이프라인 개선 작업 화이팅하세요! 🚀 ✏️ Learnings added
🧠 Learnings used |
||
| set -e | ||
| echo "🚀 FastAPI AI 서비스 배포 시작" | ||
|
|
||
| # 기존 컨테이너 상태 확인 | ||
| if docker ps | grep ururu-ai-service; then | ||
| echo "📊 기존 AI 서비스 로그 확인" | ||
| docker logs --tail 10 ururu-ai-service | ||
| fi | ||
|
|
||
| # 코드 업데이트 (올바른 디렉토리) | ||
| 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 | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # 환경변수 설정 | ||
| echo "📝 환경변수 설정" | ||
| cat > .env.production << EOF | ||
| ENVIRONMENT=production | ||
| AI_PORT=8000 | ||
| SPRING_BOOT_BASE_URL=http://${{ secrets.SPRING_BOOT_PRIVATE_IP }}:8080 | ||
| BUILD_TARGET=production | ||
| EOF | ||
|
|
||
|
Comment on lines
+143
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스크립트 내 환경변수 값이 GitHub Actions 로그에 노출됨
- cat > .env.production << EOF
+ # secrets 값 노출 방지를 위해 따옴표 보존(<< 'EOF') 및 런타임 치환 사용
+ cat > .env.production << 'EOF'
ENVIRONMENT=production
AI_PORT=8000
- SPRING_BOOT_BASE_URL=http://${{ secrets.SPRING_BOOT_PRIVATE_IP }}:8080
+ SPRING_BOOT_BASE_URL=http://${SPRING_BOOT_PRIVATE_IP}:8080
BUILD_TARGET=production
EOF추가로
🧰 Tools🪛 YAMLlint (1.37.1)[error] 154-154: trailing spaces (trailing-spaces) [error] 160-160: trailing spaces (trailing-spaces) [error] 172-172: trailing spaces (trailing-spaces) [error] 181-181: trailing spaces (trailing-spaces) 🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SPRING_BOOT_PRIVATE_IP secrets 추가 완료 + 환경변수 중복 문제 수정 완료 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @23MinL 빠른 수정 완료 감사합니다! 🎉 SPRING_BOOT_PRIVATE_IP secrets를 환경변수로 분리하여 GitHub Actions 로그 노출을 방지하고, 환경변수 중복 문제까지 해결해주셨네요. 이제 VPC 내부 IP가 워크플로 로그에 평문으로 노출되지 않아 보안이 강화되었습니다. 특히 appleboy/ssh-action에서 secrets를 env 섹션으로 분리하여 스크립트 내에서 환경변수로 참조하는 방식은 CI/CD 보안 모범 사례를 잘 적용한 사례입니다. ✏️ Learnings added
🧠 Learnings usedIf you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
||
| # Docker 컨테이너 배포 | ||
| echo "🐳 Docker 컨테이너 배포" | ||
| cd docker | ||
| docker compose down || true | ||
| docker compose up -d --build | ||
|
|
||
| echo "⏳ 서비스 시작 대기 중..." | ||
| sleep 30 | ||
|
|
||
| # 헬스체크 | ||
| echo "🔍 헬스체크 시작" | ||
| for i in {1..60}; do | ||
| if curl -f http://localhost:8000/health 2>/dev/null; then | ||
| echo "✅ FastAPI 서비스 헬스체크 통과" | ||
| break | ||
| fi | ||
| if [ $i -eq 60 ]; then | ||
| echo "❌ 헬스체크 실패" | ||
| docker logs --tail 20 ururu-ai-service | ||
| exit 1 | ||
| fi | ||
| sleep 5 | ||
| 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 | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Deployment Completion Notification | ||
| if: success() | ||
| - name: Deployment Notification | ||
| if: always() | ||
| run: | | ||
| echo "GitHub Actions deployment pipeline completed successfully." | ||
| echo "Docker image has been pushed to GitHub Container Registry." | ||
| echo "Manual execution required on EC2 server: docker compose pull && docker compose up -d" | ||
| 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" | ||
| fi | ||
|
|
||
| - name: Create Deployment Issue on Failure | ||
| if: failure() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title: 'Production AI Service Deployment Failed', | ||
| body: `## As Is (Current Issue) | ||
|
|
||
| Production AI service automated deployment has failed. | ||
|
|
||
| **Deployment Information:** | ||
| - Commit: ${context.sha} | ||
| - Branch: ${context.ref} | ||
| - Execution Time: ${new Date().toISOString()} | ||
| - Workflow: ${context.workflow} | ||
| ## To Be (Expected Behavior) | ||
|
|
||
| AI service should be deployed successfully and available for frontend AI recommendation features. | ||
|
|
||
| ## Deadline | ||
|
|
||
| Critical fix required within 1 hour | ||
|
|
||
| ## References | ||
|
|
||
| - [Workflow Execution Log](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) | ||
| - [EC2 AI Service Status](http://3.39.69.34:8000/health) | ||
| - [AI API Documentation](http://3.39.69.34:8000/docs) | ||
| `, | ||
| labels: ['urgent', 'ai-service', 'deployment'] | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.