@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