tony.cheng
2026-03-16 38a38d54c66dfe6b85e26ba7f4f3cc3c70ad1814
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
 
:: ============================================
:: Cloud Melody Frontend Deploy Script (Windows)
:: Target Server: 36.140.67.217
:: ============================================
 
set SERVER_IP=36.140.67.217
set SERVER_USER=root
set DEPLOY_PATH=/var/www/cloud-melody-front
set NGINX_CONF_NAME=cloud-melody-front.conf
 
set "GREEN=[92m"
set "YELLOW=[93m"
set "RED=[91m"
set "NC=[0m"
 
cd /d "%~dp0"
 
echo.
echo ============================================
echo     Cloud Melody Frontend Deploy Script
echo ============================================
echo.
 
:: Check ssh and scp
where ssh >nul 2>&1
if %errorlevel% neq 0 (
    echo %RED%[ERROR]%NC% ssh command not found
    echo Please enable OpenSSH Client in Windows Settings
    pause
    exit /b 1
)
 
where scp >nul 2>&1
if %errorlevel% neq 0 (
    echo %RED%[ERROR]%NC% scp command not found
    echo Please enable OpenSSH Client in Windows Settings
    pause
    exit /b 1
)
 
:: Check build directory
if not exist "..\build" (
    echo %YELLOW%[INFO]%NC% build directory not found, building project...
    call :build_project
)
 
:: Deploy
call :deploy_to_server
 
if %errorlevel% equ 0 (
    call :show_result
)
 
pause
exit /b 0
 
:: ============================================
:: Build Project
:: ============================================
:build_project
echo %GREEN%[INFO]%NC% Building project...
 
cd /d "%~dp0.."
 
where npm >nul 2>&1
if %errorlevel% neq 0 (
    echo %RED%[ERROR]%NC% npm not found, please install Node.js
    pause
    exit /b 1
)
 
echo %GREEN%[INFO]%NC% Installing dependencies...
call npm install
 
echo %GREEN%[INFO]%NC% Building production bundle...
call npm run build
 
if not exist "build" (
    echo %RED%[ERROR]%NC% Build failed, build directory not found
    pause
    exit /b 1
)
 
cd /d "%~dp0"
echo %GREEN%[INFO]%NC% Build completed
goto :eof
 
:: ============================================
:: Deploy to Server
:: ============================================
:deploy_to_server
echo.
echo %GREEN%[INFO]%NC% Starting deployment to %SERVER_IP%...
echo.
echo %YELLOW%[IMPORTANT]%NC% You will be prompted for password: pe0DahXt2#
echo.
 
:: Create remote directories
echo %GREEN%[INFO]%NC% Creating remote directories...
ssh %SERVER_USER%@%SERVER_IP% "mkdir -p %DEPLOY_PATH% && mkdir -p /etc/nginx/conf.d"
if %errorlevel% neq 0 (
    echo %RED%[ERROR]%NC% Failed to create remote directories
    exit /b 1
)
 
:: Upload build files
echo %GREEN%[INFO]%NC% Uploading build files...
scp -r ..\build\* %SERVER_USER%@%SERVER_IP%:%DEPLOY_PATH%/
if %errorlevel% neq 0 (
    echo %RED%[ERROR]%NC% Failed to upload build files
    exit /b 1
)
 
:: Upload nginx config
echo %GREEN%[INFO]%NC% Uploading Nginx config...
scp cloud-melody-front.conf %SERVER_USER%@%SERVER_IP%:/etc/nginx/conf.d/
if %errorlevel% neq 0 (
    echo %RED%[ERROR]%NC% Failed to upload Nginx config
    exit /b 1
)
 
:: Restart nginx
echo %GREEN%[INFO]%NC% Configuring and restarting Nginx...
ssh %SERVER_USER%@%SERVER_IP% "nginx -t && systemctl restart nginx && systemctl enable nginx"
if %errorlevel% neq 0 (
    echo %RED%[ERROR]%NC% Failed to restart Nginx
    exit /b 1
)
 
echo.
echo %GREEN%[INFO]%NC% Deployment completed!
goto :eof
 
:: ============================================
:: Show Result
:: ============================================
:show_result
echo.
echo ============================================
echo %GREEN%Deployment Successful!%NC%
echo ============================================
echo.
echo Access URLs:
echo   Frontend: http://%SERVER_IP%:9002
echo   Backend API: http://%SERVER_IP%:9015
echo.
echo Server Info:
echo   IP: %SERVER_IP%
echo   User: %SERVER_USER%
echo   Deploy Path: %DEPLOY_PATH%
echo.
echo Useful Commands:
echo   Check Nginx status: ssh %SERVER_USER%@%SERVER_IP% "systemctl status nginx"
echo   View Nginx logs: ssh %SERVER_USER%@%SERVER_IP% "tail -f /var/log/nginx/error.log"
echo   Restart Nginx: ssh %SERVER_USER%@%SERVER_IP% "systemctl restart nginx"
echo ============================================
goto :eof