Files
TK-FB-Project/deploy/tkfb-package/api.hyungi.net/deploy.sh
Hyungi Ahn 2b1c7bfb88 feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등
- 순찰/점검 기능 개선 (zone-detail 페이지 추가)
- 출근/근태 시스템 개선 (연차 조회, 근무현황)
- 작업분석 대분류 그룹화 및 마이그레이션 스크립트
- 모바일 네비게이션 UI 추가
- NAS 배포 도구 및 문서 추가

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 14:41:01 +09:00

98 lines
3.0 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 색상 정의
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} API 서버 배포 스크립트${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# 현재 디렉토리 확인
if [ ! -f "package.json" ]; then
echo -e "${RED}❌ 오류: package.json을 찾을 수 없습니다.${NC}"
echo -e "${RED} api.hyungi.net 디렉토리에서 실행해주세요.${NC}"
exit 1
fi
echo -e "${BLUE}📂 현재 디렉토리:${NC} $(pwd)"
echo ""
# 1. Git Pull
echo -e "${YELLOW}1⃣ Git Pull 시작...${NC}"
git pull
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Git Pull 실패${NC}"
exit 1
fi
echo -e "${GREEN}✅ Git Pull 완료${NC}"
echo ""
# 2. NPM Install (package.json 변경 확인)
echo -e "${YELLOW}2⃣ 의존성 확인 중...${NC}"
if git diff HEAD@{1} HEAD --name-only | grep -q "package.json"; then
echo -e "${YELLOW}📦 package.json 변경 감지 - npm install 실행${NC}"
npm install
if [ $? -ne 0 ]; then
echo -e "${RED}❌ npm install 실패${NC}"
exit 1
fi
echo -e "${GREEN}✅ npm install 완료${NC}"
else
echo -e "${GREEN}✅ package.json 변경 없음 - 건너뜀${NC}"
fi
echo ""
# 3. 데이터베이스 마이그레이션
echo -e "${YELLOW}3⃣ 데이터베이스 마이그레이션 시작...${NC}"
echo -e "${YELLOW}⚠️ 주의: 마이그레이션 전 데이터베이스 백업을 권장합니다.${NC}"
echo ""
read -p "마이그레이션을 실행하시겠습니까? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
npm run db:migrate
if [ $? -ne 0 ]; then
echo -e "${RED}❌ 마이그레이션 실패${NC}"
echo -e "${YELLOW}💡 롤백이 필요하면 다음 명령어를 실행하세요:${NC}"
echo -e "${YELLOW} npm run db:rollback${NC}"
exit 1
fi
echo -e "${GREEN}✅ 마이그레이션 완료${NC}"
else
echo -e "${YELLOW}⏭️ 마이그레이션 건너뜀${NC}"
fi
echo ""
# 4. PM2 재시작
echo -e "${YELLOW}4⃣ PM2 서버 재시작...${NC}"
if command -v pm2 &> /dev/null; then
pm2 reload ecosystem.config.js --env production
if [ $? -ne 0 ]; then
echo -e "${RED}❌ PM2 reload 실패${NC}"
exit 1
fi
echo -e "${GREEN}✅ PM2 reload 완료${NC}"
echo ""
# PM2 상태 확인
echo -e "${BLUE}📊 PM2 프로세스 상태:${NC}"
pm2 list
else
echo -e "${YELLOW}⚠️ PM2가 설치되지 않았습니다. 수동으로 서버를 재시작해주세요.${NC}"
fi
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} ✅ 배포 완료!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "${BLUE}📝 배포 후 확인사항:${NC}"
echo -e " 1. API 서버 응답 확인: curl http://localhost:20005/health"
echo -e " 2. 로그 확인: pm2 logs hyungi-api"
echo -e " 3. 에러 발생 시: pm2 logs hyungi-api --err"
echo ""