(improvement)(assembly)Improve release scripts(bat) to make file structure cleaner. (#1007)

This commit is contained in:
LXW
2024-05-17 15:50:20 +08:00
committed by GitHub
parent 7949efea75
commit a1d6f1c596
5 changed files with 149 additions and 130 deletions

1
.gitignore vendored
View File

@@ -19,3 +19,4 @@ assembly/runtime/*
chm_db/ chm_db/
__pycache__/ __pycache__/
/dict /dict
assembly/build/*-SNAPSHOT

View File

@@ -1,72 +1,98 @@
@echo off @echo off
setlocal setlocal enabledelayedexpansion
chcp 65001 chcp 65001
set "sbinDir=%~dp0"
set "baseDir=%~dp0.." call supersonic-common.bat %*
set "buildDir=%baseDir%\build"
set "runtimeDir=%baseDir%\..\runtime"
set "pip_path=pip3"
set "service=%~1" set "service=%~1"
cd %projectDir%
if "%service%"=="" (
set service=%standalone_service%
)
rem 1. build backend java modules call mvn help:evaluate -Dexpression=project.version > temp.txt
del /q "%buildDir%\*.tar.gz" 2>NUL for /f "delims=" %%i in (temp.txt) do (
call mvn -f "%baseDir%\..\pom.xml" clean package -DskipTests set line=%%i
if not "!line:~0,1!"=="[" (
set MVN_VERSION=!line!
)
)
del temp.txt
cd %baseDir%
if "%service%"=="%pyllm_service%" (
echo start installing python modules required by supersonic-pyllm: %pip_path%
%pip_path% install -r %projectDir%\headless\python\requirements.txt"
echo install python modules success
goto :EOF
) else if "%service%"=="webapp" (
call :buildWebapp
tar xvf supersonic-webapp.tar.gz
move /y supersonic-webapp webapp
move /y webapp %projectDir%\launchers\%STANDALONE_SERVICE%\target\classes
goto :EOF
) else (
call :buildJavaService
call :buildWebapp
call :packageRelease
goto :EOF
)
:buildJavaService
set "model_name=%service%"
echo "starting building supersonic-%model_name% service"
call mvn -f %projectDir%\launchers\%model_name% clean package -DskipTests
IF ERRORLEVEL 1 ( IF ERRORLEVEL 1 (
ECHO Failed to build backend Java modules. ECHO Failed to build backend Java modules.
EXIT /B 1 EXIT /B 1
) )
copy /y %projectDir%\launchers\%model_name%\target\*.tar.gz %buildDir%\
echo "finished building supersonic-%model_name% service"
goto :EOF
rem 2. move package to build
echo f|xcopy "%baseDir%\..\launchers\standalone\target\*.tar.gz" "%buildDir%\supersonic-standalone.tar.gz"
rem 3. build frontend webapp :buildWebapp
cd "%baseDir%\..\webapp" echo "starting building supersonic webapp"
cd %projectDir%\webapp
call start-fe-prod.bat call start-fe-prod.bat
copy /y "%baseDir%\..\webapp\supersonic-webapp.tar.gz" "%buildDir%\" copy /y supersonic-webapp.tar.gz %buildDir%\
rem check build result
IF ERRORLEVEL 1 ( IF ERRORLEVEL 1 (
ECHO Failed to build frontend webapp. ECHO Failed to build frontend webapp.
EXIT /B 1 EXIT /B 1
) )
echo "finished building supersonic webapp"
goto :EOF
rem 4. copy webapp to java classpath
cd "%buildDir%"
tar -zxvf supersonic-webapp.tar.gz
move supersonic-webapp webapp
move webapp ..\..\launchers\standalone\target\classes
rem 5. build backend python modules :packageRelease
if "%service%"=="pyllm" ( set "model_name=%service%"
echo "start installing python modules with pip: ${pip_path}" set "release_dir=supersonic-%model_name%-%MVN_VERSION%"
set requirementPath="%baseDir%/../headless/python/requirements.txt" set "service_name=launchers-%model_name%-%MVN_VERSION%"
%pip_path% install -r %requirementPath% echo "starting packaging supersonic release"
echo "install python modules success" cd %buildDir%
if exist %release_dir% rmdir /s /q %release_dir%
if exist %release_dir%.zip del %release_dir%.zip
mkdir %release_dir%
rem package webapp
tar xvf supersonic-webapp.tar.gz
move /y supersonic-webapp webapp
echo {"env": ""} > webapp\supersonic.config.json
move /y webapp %release_dir%
rem package java service
tar xvf %service_name%-bin.tar.gz
for /d %%D in ("%service_name%\*") do (
move "%%D" "%release_dir%"
) )
rem generate zip file
call :BUILD_RUNTIME powershell Compress-Archive -Path %release_dir% -DestinationPath %release_dir%.zip
del %service_name%-bin.tar.gz
:BUILD_RUNTIME del supersonic-webapp.tar.gz
rem 6. reset runtime rmdir /s /q %service_name%
IF EXIST "%runtimeDir%" ( echo "finished packaging supersonic release"
echo begin to delete dir : %runtimeDir% goto :EOF
rd /s /q "%runtimeDir%"
) ELSE (
echo %runtimeDir% does not exist, create directly
)
mkdir "%runtimeDir%"
tar -zxvf "%buildDir%\supersonic-standalone.tar.gz" -C "%runtimeDir%"
for /d %%f in ("%runtimeDir%\launchers-standalone-*") do (
move "%%f" "%runtimeDir%\supersonic-standalone"
)
rem 7. copy webapp to runtime
tar -zxvf "%buildDir%\supersonic-webapp.tar.gz" -C "%buildDir%"
if not exist "%runtimeDir%\supersonic-standalone\webapp" mkdir "%runtimeDir%\supersonic-standalone\webapp"
xcopy /s /e /h /y "%buildDir%\supersonic-webapp\*" "%runtimeDir%\supersonic-standalone\webapp"
if not exist "%runtimeDir%\supersonic-standalone\conf\webapp" mkdir "%runtimeDir%\supersonic-standalone\conf\webapp"
xcopy /s /e /h /y "%runtimeDir%\supersonic-standalone\webapp\*" "%runtimeDir%\supersonic-standalone\conf\webapp"
rd /s /q "%buildDir%\supersonic-webapp"
endlocal endlocal

View File

@@ -0,0 +1,9 @@
set "sbinDir=%~dp0"
set "baseDir=%~dp0.."
set "buildDir=%baseDir%\build"
set "main_class=com.tencent.supersonic.StandaloneLauncher"
set "python_path=python"
set "pip_path=pip3"
set "standalone_service=standalone"
set "pyllm_service=pyllm"
set "projectDir=%baseDir%\.."

View File

@@ -1,118 +1,101 @@
@echo off @echo off
setlocal setlocal
chcp 65001 chcp 65001
set "sbinDir=%~dp0"
set "baseDir=%~dp0.."
set "runtimeDir=%baseDir%\..\runtime"
set "buildDir=%baseDir%\build"
set "main_class=com.tencent.supersonic.StandaloneLauncher"
set "python_path=python"
set "pip_path=pip3"
set "standalone_service=standalone"
set "pyllm_service=pyllm"
set "javaRunDir=%runtimeDir%\supersonic-standalone" call supersonic-common.bat %*
set "pythonRunDir=%runtimeDir%\supersonic-standalone\pyllm"
set "command=%~1" set "command=%~1"
set "service=%~2" set "service=%~2"
if "%service%"=="" ( if "%service%"=="" (
set "service=%standalone_service%" set "service=%standalone_service%"
) )
set "model_name=%service%"
IF "%service%"=="pyllm" ( IF "%service%"=="pyllm" (
SET "llmProxy=PythonLLMProxy" set "llmProxy=PythonLLMProxy"
set "model_name=%standalone_service%"
) )
call :BUILD_RUNTIME cd %baseDir%
if "%command%"=="restart" ( if "%command%"=="restart" (
call :STOP call :stop
call :START call :start
goto :EOF goto :EOF
) else if "%command%"=="start" ( ) else if "%command%"=="start" (
call :START call :start
goto :EOF goto :EOF
) else if "%command%"=="stop" ( ) else if "%command%"=="stop" (
call :STOP call :stop
goto :EOF goto :EOF
) else if "%command%"=="reload" ( ) else if "%command%"=="reload" (
call :RELOAD_EXAMPLE call :reloadExamples
goto :EOF goto :EOF
) else ( ) else (
echo "Use command {start|stop|restart} to run." echo "Use command {start|stop|restart} to run."
goto :EOF goto :EOF
) )
:START
: start
if "%service%"=="%pyllm_service%" ( if "%service%"=="%pyllm_service%" (
call :START_PYTHON call :runPythonService
call :START_JAVA call :runJavaService
goto :EOF goto :EOF
) )
call :START_JAVA call :runJavaService
goto :EOF goto :EOF
:STOP
call :STOP_PYTHON : stop
call :STOP_JAVA call :stopPythonService
call :stopJavaService
goto :EOF goto :EOF
:START_PYTHON
echo 'python service starting, see logs in pyllm/pyllm.log' : reloadExamples
cd "%pythonRunDir%" set "pythonRunDir=%baseDir%\pyllm"
start /B %python_path% supersonic_pyllm.py > %pythonRunDir%\pyllm.log 2>&1 cd "%pythonRunDir%\sql"
timeout /t 10 >nul start %python_path% examples_reload_run.py
echo 'python service started'
goto :EOF goto :EOF
:START_JAVA
: runJavaService
echo 'java service starting, see logs in logs/' echo 'java service starting, see logs in logs/'
cd "%javaRunDir%" set "libDir=%baseDir%\lib"
if not exist "%runtimeDir%\supersonic-standalone\logs" mkdir "%runtimeDir%\supersonic-standalone\logs" set "confDir=%baseDir%\conf"
set "libDir=%runtimeDir%\supersonic-standalone\lib" set "webDir=%baseDir%\webapp"
set "confDir=%runtimeDir%\supersonic-standalone\conf" set "logDir=%baseDir%\logs"
set "webDir=%runtimeDir%\supersonic-standalone\webapp" set "classpath=%baseDir%;%webDir%;%libDir%\*;%confDir%"
set "classpath=%confDir%;%webDir%;%libDir%\*"
set "java-command=-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Xms1024m -Xmx2048m -cp %CLASSPATH% %MAIN_CLASS%" set "java-command=-Dfile.encoding=UTF-8 -Duser.language=Zh -Duser.region=CN -Duser.timezone=GMT+08 -Xms1024m -Xmx2048m -cp %CLASSPATH% %MAIN_CLASS%"
if not exist %logDir% mkdir %logDir%
start /B java %java-command% >nul 2>&1 start /B java %java-command% >nul 2>&1
timeout /t 10 >nul timeout /t 10 >nul
echo 'java service started' echo 'java service started'
goto :EOF goto :EOF
:STOP_PYTHON
: runPythonService
echo 'python service starting, see logs in pyllm\pyllm.log'
set "pythonRunDir=%baseDir%\pyllm"
start /B %python_path% %pythonRunDir%\supersonic_pyllm.py > %pythonRunDir%\pyllm.log 2>&1
timeout /t 10 >nul
echo 'python service started'
goto :EOF
: stopPythonService
for /f "tokens=2" %%i in ('tasklist ^| findstr /i "python"') do ( for /f "tokens=2" %%i in ('tasklist ^| findstr /i "python"') do (
taskkill /PID %%i /F taskkill /PID %%i /F
echo "python service (PID = %%i) is killed." echo "python service (PID = %%i) is killed."
) )
goto :EOF goto :EOF
:STOP_JAVA
: stopJavaService
for /f "tokens=2" %%i in ('tasklist ^| findstr /i "java"') do ( for /f "tokens=2" %%i in ('tasklist ^| findstr /i "java"') do (
taskkill /PID %%i /F taskkill /PID %%i /F
echo "java service (PID = %%i) is killed." echo "java service (PID = %%i) is killed."
) )
goto :EOF goto :EOF
:RELOAD_EXAMPLE endlocal
cd "%runtimeDir%\supersonic-standalone\pyllm\sql"
start %python_path% examples_reload_run.py
goto :EOF
:BUILD_RUNTIME
rem 6. reset runtime
if exist "%runtimeDir%" goto :EOF
mkdir "%runtimeDir%"
tar -zxvf "%buildDir%\supersonic-standalone.tar.gz" -C "%runtimeDir%"
for /d %%f in ("%runtimeDir%\launchers-standalone-*") do (
move "%%f" "%runtimeDir%\supersonic-standalone"
)
rem 7. copy webapp to runtime
tar -zxvf "%buildDir%\supersonic-webapp.tar.gz" -C "%buildDir%"
if not exist "%runtimeDir%\supersonic-standalone\webapp" mkdir "%runtimeDir%\supersonic-standalone\webapp"
xcopy /s /e /h /y "%buildDir%\supersonic-webapp\*" "%runtimeDir%\supersonic-standalone\webapp"
if not exist "%runtimeDir%\supersonic-standalone\conf\webapp" mkdir "%runtimeDir%\supersonic-standalone\conf\webapp"
xcopy /s /e /h /y "%runtimeDir%\supersonic-standalone\webapp\*" "%runtimeDir%\supersonic-standalone\conf\webapp"
rd /s /q "%buildDir%\supersonic-webapp"

2
webapp/.gitignore vendored
View File

@@ -15,8 +15,8 @@
/supersonic-webapp /supersonic-webapp
../assembly/build/supersonic-webapp.tar.gz
supersonic-webapp.tar.gz supersonic-webapp.tar.gz
package-lock.json package-lock.json
yarn.lock yarn.lock