You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.0 KiB
Bash

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# Stock Oracle Portainer 빠른 배포 스크립트
set -e
echo "🚀 Stock Oracle Portainer 빠른 배포 시작..."
# 색상 정의
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 함수 정의
print_status() {
echo -e "${BLUE} $1${NC}"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
# Step 1: 필수 도구 확인
print_status "필수 도구 확인 중..."
if ! command -v docker &> /dev/null; then
print_error "Docker가 설치되지 않았습니다."
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
print_error "Docker Compose가 설치되지 않았습니다."
exit 1
fi
print_success "Docker 및 Docker Compose 설치 확인"
# Step 2: 환경 변수 확인
print_status "환경 변수 확인 중..."
if [ -z "$SEC_EMAIL" ]; then
print_warning "SEC_EMAIL 환경 변수가 설정되지 않았습니다."
read -p "SEC API 이메일 주소를 입력하세요: " SEC_EMAIL
export SEC_EMAIL
fi
print_success "환경 변수 설정 완료"
# Step 3: Portainer 설치 확인
print_status "Portainer 상태 확인 중..."
if ! docker ps | grep -q portainer; then
print_warning "Portainer가 실행되지 않고 있습니다. 설치를 시작합니다..."
./portainer/install-portainer.sh
print_status "Portainer 초기화를 위해 30초 대기 중..."
sleep 30
else
print_success "Portainer가 이미 실행 중입니다."
fi
# Step 4: SSL 인증서 생성
print_status "SSL 인증서 확인 중..."
if [ ! -f "portainer/nginx/ssl/cert.pem" ]; then
print_warning "SSL 인증서가 없습니다. 생성을 시작합니다..."
./portainer/generate-ssl.sh
else
print_success "SSL 인증서가 이미 존재합니다."
fi
# Step 5: 환경 파일 생성
print_status "환경 파일 설정 중..."
if [ ! -f ".env" ]; then
cp portainer/.env.portainer .env
# 환경 변수 자동 설정
sed -i.bak "s/your-email@example.com/$SEC_EMAIL/g" .env
# 보안 패스워드 생성
POSTGRES_PASS=$(openssl rand -base64 32 | tr -d /=+ | cut -c -16)
REDIS_PASS=$(openssl rand -base64 32 | tr -d /=+ | cut -c -16)
sed -i.bak "s/change_this_password_in_production/$POSTGRES_PASS/g" .env
sed -i.bak "s/change_this_redis_password/$REDIS_PASS/g" .env
rm .env.bak
print_success "환경 파일 생성 및 설정 완료"
else
print_success "환경 파일이 이미 존재합니다."
fi
# Step 6: Docker 이미지 빌드
print_status "Docker 이미지 빌드 중..."
docker build -t stock-oracle-api:latest .
print_success "Docker 이미지 빌드 완료"
# Step 7: 스택 배포
print_status "Stock Oracle 스택 배포 중..."
docker-compose -f portainer/docker-compose.portainer.yml down --remove-orphans
docker-compose -f portainer/docker-compose.portainer.yml up -d
print_success "스택 배포 완료"
# Step 8: 서비스 상태 확인
print_status "서비스 상태 확인 중..."
sleep 10
# 서비스 헬스체크
services=("stock-oracle-postgres" "stock-oracle-redis" "stock-oracle-api" "stock-oracle-nginx")
all_healthy=true
for service in "${services[@]}"; do
if docker ps --format "table {{.Names}}\t{{.Status}}" | grep -q "$service.*Up"; then
print_success "$service: 실행 중"
else
print_error "$service: 실행 실패"
all_healthy=false
fi
done
# Step 9: API 접속 테스트
print_status "API 접속 테스트 중..."
sleep 15
if curl -k -s https://localhost/docs > /dev/null; then
print_success "API 서버 접속 성공"
else
print_error "API 서버 접속 실패"
all_healthy=false
fi
# Step 10: 결과 출력
echo ""
echo "=================================="
echo "🎉 Stock Oracle 배포 결과"
echo "=================================="
if [ "$all_healthy" = true ]; then
print_success "모든 서비스가 성공적으로 배포되었습니다!"
echo ""
echo "📊 접속 정보:"
echo " - API 문서: https://localhost/docs"
echo " - Portainer: https://localhost:9443"
echo " - API 엔드포인트: https://localhost/api/v1/"
echo ""
echo "🧪 테스트 실행:"
echo " python tests/run_all_tests.py"
echo ""
echo "🔧 관리:"
echo " - 컨테이너 상태: docker-compose -f portainer/docker-compose.portainer.yml ps"
echo " - 로그 확인: docker-compose -f portainer/docker-compose.portainer.yml logs"
echo " - 중지: docker-compose -f portainer/docker-compose.portainer.yml down"
else
print_error "일부 서비스 배포에 실패했습니다."
echo ""
echo "🔍 문제 해결:"
echo " - 로그 확인: docker-compose -f portainer/docker-compose.portainer.yml logs"
echo " - 상태 확인: docker-compose -f portainer/docker-compose.portainer.yml ps"
echo " - 재시작: docker-compose -f portainer/docker-compose.portainer.yml restart"
exit 1
fi