CASTAD-v0.1/deploy.sh

157 lines
4.4 KiB
Bash

#!/bin/bash
# 색상 정의
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}=== BizVibe 배포 자동화 스크립트 ===${NC}"
# 1. 현재 경로 확인
PROJECT_ROOT=$(pwd)
DIST_PATH="$PROJECT_ROOT/dist"
echo -e "${GREEN}[1] 현재 프로젝트 경로:${NC} $PROJECT_ROOT"
# 2. 시스템 의존성 설치 (Puppeteer/Chromium 용)
echo -e "${GREEN}[1.5] Installing Puppeteer system dependencies...${NC}"
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update && sudo apt-get install -y \
ca-certificates \
fonts-liberation \
libasound2t64 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgbm1 \
libgcc1 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
lsb-release \
wget \
xdg-utils \
fonts-noto-cjk
if [ $? -ne 0 ]; then
echo -e "${RED}❌ System dependency installation failed!${NC}"
# 의존성 설치 실패해도 일단 진행 (이미 설치된 경우 등 고려)
else
echo -e "${GREEN}✅ System dependencies installed successfully.${NC}"
fi
else
echo -e "${YELLOW}⚠️ 'apt-get' not found. Skipping system dependency installation. Ensure dependencies are installed manually.${NC}"
fi
# 3. 프로젝트 빌드
echo -e "${GREEN}[2] Building project...${NC}"
npm run build:all
if [ $? -ne 0 ]; then
echo -e "${RED}❌ 빌드 실패! 오류를 확인해주세요.${NC}"
exit 1
fi
echo -e "${GREEN}✅ 빌드 완료!${NC}"
# 3. Nginx 설정 파일 생성 (경로 자동 적용)
echo -e "${GREEN}[3] Nginx 설정 파일 생성 중...${NC}"
NGINX_CONF="nginx_bizvibe.conf"
DOMAIN_NAME="bizvibe.ktenterprise.net" # 기본 도메인 (필요 시 수정)
cat > $NGINX_CONF <<EOF
server {
listen 80;
server_name $DOMAIN_NAME;
# 1. 프론트엔드 (React 빌드 결과물)
location / {
root $DIST_PATH;
index index.html;
try_files \$uri \$uri/ /index.html;
}
# 2. 백엔드 API 프록시
location /api {
proxy_pass http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host \$host;
proxy_cache_bypass \$http_upgrade;
}
# 3. 영상 생성 및 다운로드 프록시
location /render {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host \$host;
}
location /downloads {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host \$host;
}
location /temp {
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host \$host;
}
}
EOF
echo -e "${GREEN}✅ Nginx 설정 파일($NGINX_CONF) 생성 완료! (Root 경로: $DIST_PATH)${NC}"
# 4. PM2로 백엔드 시작
echo -e "${GREEN}[4] PM2로 백엔드 서버 시작...${NC}"
# PM2 설치 확인 및 설치
if ! command -v pm2 &> /dev/null
then
echo -e "${YELLOW}PM2가 설치되어 있지 않습니다. 설치를 시도합니다...${NC}"
npm install -g pm2
fi
# 기존 프로세스 재시작 또는 새로 시작
pm2 restart bizvibe-backend 2>/dev/null || pm2 start server/index.js --name "bizvibe-backend"
pm2 save
echo -e "${GREEN}✅ 백엔드 서버 구동 완료!${NC}"
# 5. 최종 안내 (sudo 필요 작업)
echo -e ""
echo -e "${BLUE}=== 🎉 배포 준비 완료! 남은 단계 ===${NC}"
echo -e "${YELLOW}다음 명령어를 복사하여 실행하면 Nginx 설정이 적용됩니다 (관리자 권한 필요):${NC}"
echo -e ""
echo -e "1. 설정 파일 이동:"
echo -e " ${GREEN}sudo cp $NGINX_CONF /etc/nginx/sites-available/bizvibe${NC}"
echo -e ""
echo -e "2. 사이트 활성화:"
echo -e " ${GREEN}sudo ln -s /etc/nginx/sites-available/bizvibe /etc/nginx/sites-enabled/${NC}"
echo -e ""
echo -e "3. Nginx 문법 검사 및 재시작:"
echo -e " ${GREEN}sudo nginx -t && sudo systemctl reload nginx${NC}"
echo -e ""