111 lines
3.6 KiB
PowerShell
111 lines
3.6 KiB
PowerShell
# ============================================================
|
|
# zio-server 홈페이지 배포 스크립트 (Windows PowerShell)
|
|
# 실행: .\deploy\03_deploy.ps1 -ServerIP "140.238.xxx.xxx"
|
|
# ============================================================
|
|
|
|
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$ServerIP,
|
|
[string]$KeyPath = "$env:USERPROFILE\.ssh\zio-server",
|
|
[string]$User = "ubuntu"
|
|
)
|
|
|
|
$GREEN = "`e[32m"
|
|
$YELLOW = "`e[33m"
|
|
$CYAN = "`e[36m"
|
|
$NC = "`e[0m"
|
|
|
|
function Log-Info { param($msg) Write-Host "${GREEN}[OK]${NC} $msg" }
|
|
function Log-Section { param($msg) Write-Host "`n${CYAN}=== $msg ===${NC}" }
|
|
function Log-Warn { param($msg) Write-Host "${YELLOW}[!]${NC} $msg" }
|
|
|
|
$SSH = "ssh -i `"$KeyPath`" -o StrictHostKeyChecking=no ${User}@${ServerIP}"
|
|
$SCP = "scp -i `"$KeyPath`" -o StrictHostKeyChecking=no"
|
|
$ROOT = "C:\GUARDiA\workspace\zioinfo-web"
|
|
|
|
Log-Section "1. React 프론트엔드 빌드"
|
|
Set-Location "$ROOT\frontend"
|
|
|
|
# vite.config.js 빌드 경로를 임시 dist로 변경
|
|
$viteCfg = Get-Content "vite.config.js" -Raw
|
|
$buildCfg = $viteCfg -replace "outDir: '.*?'", "outDir: 'dist'"
|
|
$buildCfg | Set-Content "vite.config.js" -Encoding utf8
|
|
|
|
npm run build
|
|
if ($LASTEXITCODE -ne 0) { Write-Error "빌드 실패"; exit 1 }
|
|
Log-Info "React 빌드 완료 → frontend/dist/"
|
|
|
|
Log-Section "2. 빌드 파일 서버 업로드"
|
|
Invoke-Expression "$SSH 'rm -rf /var/www/zioinfo/* && mkdir -p /var/www/zioinfo'"
|
|
Invoke-Expression "$SCP -r `"$ROOT\frontend\dist\*`" ${User}@${ServerIP}:/var/www/zioinfo/"
|
|
Log-Info "정적 파일 업로드 완료"
|
|
|
|
Log-Section "3. Spring Boot JAR 빌드"
|
|
Set-Location "$ROOT"
|
|
if (Test-Path "pom.xml") {
|
|
# Maven 빌드 (Spring Boot 백엔드)
|
|
$mvnw = if (Test-Path "mvnw.cmd") { ".\mvnw.cmd" } else { "mvn" }
|
|
& $mvnw clean package -DskipTests -q
|
|
$jar = Get-ChildItem "target\*.jar" -Exclude "*sources*" | Select-Object -First 1
|
|
if ($jar) {
|
|
Log-Info "JAR 빌드 완료: $($jar.Name)"
|
|
Invoke-Expression "$SCP `"$($jar.FullName)`" ${User}@${ServerIP}:/opt/zioinfo/app/zioinfo.jar"
|
|
Log-Info "JAR 업로드 완료"
|
|
}
|
|
} else {
|
|
Log-Warn "pom.xml 없음 — Spring Boot 배포 스킵 (정적 파일만 배포)"
|
|
}
|
|
|
|
Log-Section "4. systemd 서비스 등록 (Spring Boot)"
|
|
$serviceScript = @'
|
|
# Spring Boot 서비스 설정
|
|
sudo tee /etc/systemd/system/zioinfo.service > /dev/null <<SERVICE
|
|
[Unit]
|
|
Description=Zioinfo Spring Boot Application
|
|
After=network.target
|
|
|
|
[Service]
|
|
User=ubuntu
|
|
WorkingDirectory=/opt/zioinfo/app
|
|
ExecStart=/usr/bin/java -jar -Xms256m -Xmx512m /opt/zioinfo/app/zioinfo.jar
|
|
Restart=on-failure
|
|
RestartSec=10
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
SERVICE
|
|
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable zioinfo
|
|
sudo systemctl restart zioinfo 2>/dev/null || echo "서비스 시작 대기 중..."
|
|
'@
|
|
|
|
if (Test-Path "$ROOT\target\*.jar") {
|
|
Invoke-Expression "$SSH '$serviceScript'"
|
|
Log-Info "Spring Boot 서비스 등록 완료"
|
|
}
|
|
|
|
Log-Section "5. Nginx 재시작 및 최종 확인"
|
|
$checkScript = @"
|
|
sudo systemctl reload nginx
|
|
echo '--- Nginx 상태 ---'
|
|
sudo systemctl is-active nginx
|
|
echo '--- 포트 확인 ---'
|
|
ss -tlnp | grep -E ':80|:443|:8080'
|
|
echo '--- 디스크 사용량 ---'
|
|
df -h /
|
|
echo '--- 메모리 ---'
|
|
free -h
|
|
"@
|
|
Invoke-Expression "$SSH '$checkScript'"
|
|
|
|
Log-Section "✅ 배포 완료!"
|
|
Write-Host ""
|
|
Write-Host "${GREEN}홈페이지 주소:${NC} http://$ServerIP"
|
|
Write-Host "${GREEN}SSH 접속:${NC} ssh -i `"$KeyPath`" ubuntu@$ServerIP"
|
|
Write-Host ""
|
|
Write-Host "${YELLOW}브라우저에서 확인:${NC}"
|
|
Start-Process "http://$ServerIP"
|