mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-13 13:07:32 +00:00
(improvement)(assembly)Improve release scripts to make file structure cleaner.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,6 +8,7 @@ log/
|
|||||||
*.bin
|
*.bin
|
||||||
*.log
|
*.log
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
*.zip
|
||||||
*.lib
|
*.lib
|
||||||
assembly/runtime/*
|
assembly/runtime/*
|
||||||
**/dist/
|
**/dist/
|
||||||
|
|||||||
@@ -1,58 +1,79 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -x
|
|
||||||
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
||||||
chmod +x $sbinDir/supersonic-common.sh
|
chmod +x $sbinDir/supersonic-common.sh
|
||||||
source $sbinDir/supersonic-common.sh
|
source $sbinDir/supersonic-common.sh
|
||||||
|
cd $projectDir
|
||||||
|
MVN_VERSION=$(mvn help:evaluate -Dexpression=project.version | grep -e '^[^\[]')
|
||||||
|
|
||||||
cd $baseDir
|
cd $baseDir
|
||||||
|
|
||||||
service=$1
|
service=$1
|
||||||
#1. build backend java modules
|
if [ -z "$service" ]; then
|
||||||
rm -fr ${buildDir}/*.tar.gz
|
service=${STANDALONE_SERVICE}
|
||||||
rm -fr dist
|
|
||||||
set +x
|
|
||||||
mvn -f $baseDir/../ clean package -DskipTests
|
|
||||||
# check build result
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Failed to build backend Java modules."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#2. move package to build
|
function buildJavaService {
|
||||||
cp $baseDir/../launchers/headless/target/*.tar.gz ${buildDir}/supersonic-headless.tar.gz
|
model_name=$1
|
||||||
cp $baseDir/../launchers/chat/target/*.tar.gz ${buildDir}/supersonic-chat.tar.gz
|
echo "starting building supersonic-${model_name} service"
|
||||||
cp $baseDir/../launchers/standalone/target/*.tar.gz ${buildDir}/supersonic-standalone.tar.gz
|
mvn -f $projectDir/launchers/${model_name} clean package -DskipTests
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to build backend Java modules."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
cp $projectDir/launchers/${model_name}/target/*.tar.gz ${buildDir}/
|
||||||
|
echo "finished building supersonic-${model_name} service"
|
||||||
|
}
|
||||||
|
|
||||||
#3. build frontend webapp
|
function buildWebapp {
|
||||||
chmod +x $baseDir/../webapp/start-fe-prod.sh
|
echo "starting building supersonic webapp"
|
||||||
cd ../webapp
|
chmod +x $projectDir/webapp/start-fe-prod.sh
|
||||||
sh ./start-fe-prod.sh
|
cd $projectDir/webapp
|
||||||
cp -fr ./supersonic-webapp.tar.gz ${buildDir}/
|
sh ./start-fe-prod.sh
|
||||||
|
cp -fr ./supersonic-webapp.tar.gz ${buildDir}/
|
||||||
|
# check build result
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Failed to build frontend webapp."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "finished building supersonic webapp"
|
||||||
|
}
|
||||||
|
|
||||||
# check build result
|
function packageRelease {
|
||||||
if [ $? -ne 0 ]; then
|
model_name=$1
|
||||||
echo "Failed to build frontend webapp."
|
release_dir=supersonic-${model_name}-${MVN_VERSION}
|
||||||
exit 1
|
service_name=launchers-${model_name}-${MVN_VERSION}
|
||||||
fi
|
echo "starting packaging supersonic release"
|
||||||
#4. copy webapp to java classpath
|
cd $buildDir
|
||||||
cd $buildDir
|
mkdir $release_dir
|
||||||
tar xvf supersonic-webapp.tar.gz
|
# package webapp
|
||||||
mv supersonic-webapp webapp
|
tar xvf supersonic-webapp.tar.gz
|
||||||
cp -fr webapp ../../launchers/headless/target/classes
|
mv supersonic-webapp webapp
|
||||||
cp -fr webapp ../../launchers/chat/target/classes
|
json='{"env": "'$model_name'"}'
|
||||||
cp -fr webapp ../../launchers/standalone/target/classes
|
echo $json > webapp/supersonic.config.json
|
||||||
rm -fr ${buildDir}/webapp
|
mv webapp $release_dir/
|
||||||
|
# package java service
|
||||||
|
tar xvf $service_name-bin.tar.gz
|
||||||
|
mv $service_name/* $release_dir/
|
||||||
|
# generate zip file
|
||||||
|
zip -r $release_dir.zip $release_dir
|
||||||
|
# delete intermediate files
|
||||||
|
rm -rf supersonic-webapp.tar.gz
|
||||||
|
rm -rf $service_name-bin.tar.gz
|
||||||
|
rm -rf $service_name
|
||||||
|
echo "finished packaging supersonic release"
|
||||||
|
}
|
||||||
|
|
||||||
#5. build backend python modules
|
#1. build backend services
|
||||||
if [ "$service" == "pyllm" ]; then
|
if [ "$service" == $PYLLM_SERVICE ]; then
|
||||||
echo "start installing python modules with pip: ${pip_path}"
|
echo "start installing python modules required by supersonic-pyllm: ${pip_path}"
|
||||||
requirementPath=$baseDir/../headless/python/requirements.txt
|
requirementPath=$projectDir/headless/python/requirements.txt
|
||||||
${pip_path} install -r ${requirementPath}
|
${pip_path} install -r ${requirementPath}
|
||||||
echo "install python modules success"
|
echo "install python modules success"
|
||||||
fi
|
elif [ "$service" == "webapp" ]; then
|
||||||
|
buildWebapp
|
||||||
#6. reset runtime
|
cp -fr webapp $projectDir/launchers/$STANDALONE_SERVICE/target/classes
|
||||||
rm -fr $runtimeDir/supersonic*
|
else
|
||||||
moveAllToRuntime
|
buildJavaService $service
|
||||||
setEnvToWeb chat
|
buildWebapp
|
||||||
setEnvToWeb headless
|
packageRelease $service
|
||||||
|
fi
|
||||||
@@ -6,105 +6,19 @@ pip_path=${PIP_PATH:-"pip3"}
|
|||||||
|
|
||||||
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
||||||
baseDir=$(cd "$sbinDir/.." && pwd -P)
|
baseDir=$(cd "$sbinDir/.." && pwd -P)
|
||||||
runtimeDir=$baseDir/../runtime
|
runtimeDir=$baseDir/runtime
|
||||||
buildDir=$baseDir/build
|
buildDir=$baseDir/build
|
||||||
|
projectDir=$baseDir/..
|
||||||
|
|
||||||
readonly CHAT_APP_NAME="supersonic_chat"
|
readonly CHAT_APP_NAME="supersonic_chat"
|
||||||
readonly HEADLESS_APP_NAME="supersonic_headless"
|
readonly HEADLESS_APP_NAME="supersonic_headless"
|
||||||
readonly PYLLM_APP_NAME="supersonic_pyllm"
|
readonly PYLLM_APP_NAME="supersonic_pyllm"
|
||||||
readonly STANDALONE_APP_NAME="supersonic_standalone"
|
readonly STANDALONE_APP_NAME="supersonic_standalone"
|
||||||
|
|
||||||
readonly CHAT_SERVICE="chat"
|
readonly CHAT_SERVICE="chat"
|
||||||
readonly HEADLESS_SERVICE="headless"
|
readonly HEADLESS_SERVICE="headless"
|
||||||
readonly PYLLM_SERVICE="pyllm"
|
readonly PYLLM_SERVICE="pyllm"
|
||||||
readonly STANDALONE_SERVICE="standalone"
|
readonly STANDALONE_SERVICE="standalone"
|
||||||
|
|
||||||
readonly PYLLM_HOST="127.0.0.1"
|
readonly PYLLM_HOST="127.0.0.1"
|
||||||
readonly PYLLM_PORT="9092"
|
readonly PYLLM_PORT="9092"
|
||||||
|
|
||||||
function setEnvToWeb {
|
|
||||||
model_name=$1
|
|
||||||
json='{"env": "'$model_name'"}'
|
|
||||||
echo $json > ${runtimeDir}/supersonic-${model_name}/webapp/supersonic.config.json
|
|
||||||
echo $json > $baseDir/../launchers/${model_name}/target/classes/webapp/supersonic.config.json
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveToRuntime {
|
|
||||||
model_name=$1
|
|
||||||
file="${buildDir}/supersonic-${model_name}.tar.gz"
|
|
||||||
if [ -f "$file" ]; then
|
|
||||||
tar -zxvf "$file" -C ${runtimeDir}
|
|
||||||
mv ${runtimeDir}/launchers-${model_name}-* ${runtimeDir}/supersonic-${model_name}
|
|
||||||
mkdir -p ${runtimeDir}/supersonic-${model_name}/webapp
|
|
||||||
cp -fr ${buildDir}/webapp/* ${runtimeDir}/supersonic-${model_name}/webapp
|
|
||||||
else
|
|
||||||
echo "File $file does not exist. Skipping the move to runtime."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function moveAllToRuntime {
|
|
||||||
mkdir -p ${runtimeDir}
|
|
||||||
tar xvf ${buildDir}/supersonic-webapp.tar.gz -C ${buildDir}
|
|
||||||
mv ${buildDir}/supersonic-webapp ${buildDir}/webapp
|
|
||||||
|
|
||||||
moveToRuntime chat
|
|
||||||
moveToRuntime headless
|
|
||||||
moveToRuntime standalone
|
|
||||||
rm -fr ${buildDir}/webapp
|
|
||||||
}
|
|
||||||
|
|
||||||
# run java service
|
|
||||||
function runJavaService {
|
|
||||||
javaRunDir=${runtimeDir}/supersonic-${model_name}
|
|
||||||
local_app_name=$1
|
|
||||||
libDir=$javaRunDir/lib
|
|
||||||
confDir=$javaRunDir/conf
|
|
||||||
|
|
||||||
CLASSPATH=""
|
|
||||||
CLASSPATH=$CLASSPATH:$confDir
|
|
||||||
|
|
||||||
for jarPath in $libDir/*.jar; do
|
|
||||||
CLASSPATH=$CLASSPATH:$jarPath
|
|
||||||
done
|
|
||||||
|
|
||||||
export CLASSPATH
|
|
||||||
export LANG="zh_CN.UTF-8"
|
|
||||||
|
|
||||||
cd $javaRunDir
|
|
||||||
if [[ "$JAVA_HOME" == "" ]]; then
|
|
||||||
JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}')
|
|
||||||
fi
|
|
||||||
export PATH=$JAVA_HOME/bin:$PATH
|
|
||||||
command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Dapp_name=${local_app_name} -Xms1024m -Xmx2048m "$main_class
|
|
||||||
|
|
||||||
mkdir -p $javaRunDir/logs
|
|
||||||
if [[ "$is_test" == "true" ]]; then
|
|
||||||
java -Dspring.profiles.active="dev" $command >/dev/null 2>$javaRunDir/logs/error.log &
|
|
||||||
else
|
|
||||||
java $command $javaRunDir >/dev/null 2>$javaRunDir/logs/error.log &
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# run python service
|
|
||||||
function runPythonService {
|
|
||||||
pythonRunDir=${runtimeDir}/supersonic-${model_name}/pyllm
|
|
||||||
cd $pythonRunDir
|
|
||||||
nohup ${python_path} supersonic_pyllm.py > $pythonRunDir/pyllm.log 2>&1 &
|
|
||||||
# add health check
|
|
||||||
for i in {1..10}
|
|
||||||
do
|
|
||||||
echo "pyllm health check attempt $i..."
|
|
||||||
response=$(curl -s http://${PYLLM_HOST}:${PYLLM_PORT}/health)
|
|
||||||
echo "pyllm health check response: $response"
|
|
||||||
status_ok="Healthy"
|
|
||||||
if [[ $response == *$status_ok* ]] ; then
|
|
||||||
echo "pyllm Health check passed."
|
|
||||||
break
|
|
||||||
else
|
|
||||||
if [ "$i" -eq 10 ]; then
|
|
||||||
echo "pyllm Health check failed after 10 attempts."
|
|
||||||
echo "May still downloading model files. Please check pyllm.log in runtime directory."
|
|
||||||
fi
|
|
||||||
echo "Retrying after 5 seconds..."
|
|
||||||
sleep 5
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,61 +1,102 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -x
|
|
||||||
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
sbinDir=$(cd "$(dirname "$0")"; pwd)
|
||||||
chmod +x $sbinDir/supersonic-common.sh
|
chmod +x $sbinDir/supersonic-common.sh
|
||||||
source $sbinDir/supersonic-common.sh
|
source $sbinDir/supersonic-common.sh
|
||||||
|
|
||||||
# 1.init environment parameters
|
|
||||||
if [ ! -d "$runtimeDir" ]; then
|
|
||||||
echo "the runtime dir does not exist move all to runtime"
|
|
||||||
moveAllToRuntime
|
|
||||||
fi
|
|
||||||
set +x
|
|
||||||
|
|
||||||
command=$1
|
command=$1
|
||||||
service=$2
|
service=$2
|
||||||
if [ -z "$service" ]; then
|
if [ -z "$service" ]; then
|
||||||
service=${STANDALONE_SERVICE}
|
service=${STANDALONE_SERVICE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
app_name=$STANDALONE_APP_NAME
|
|
||||||
main_class="com.tencent.supersonic.StandaloneLauncher"
|
|
||||||
model_name=$service
|
model_name=$service
|
||||||
|
|
||||||
if [ "$service" == "pyllm" ]; then
|
if [ "$service" == "pyllm" ]; then
|
||||||
model_name=${STANDALONE_SERVICE}
|
model_name=${STANDALONE_SERVICE}
|
||||||
export llmProxy=PythonLLMProxy
|
export llmProxy=PythonLLMProxy
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $baseDir
|
cd $baseDir
|
||||||
|
|
||||||
# 2.set main class
|
|
||||||
function setMainClass {
|
function setMainClass {
|
||||||
if [ "$service" == $CHAT_SERVICE ]; then
|
if [ "$service" == $CHAT_SERVICE ]; then
|
||||||
main_class="com.tencent.supersonic.ChatLauncher"
|
main_class="com.tencent.supersonic.ChatLauncher"
|
||||||
elif [ "$service" == $HEADLESS_SERVICE ]; then
|
elif [ "$service" == $HEADLESS_SERVICE ]; then
|
||||||
main_class="com.tencent.supersonic.HeadlessLauncher"
|
main_class="com.tencent.supersonic.HeadlessLauncher"
|
||||||
|
else
|
||||||
|
main_class="com.tencent.supersonic.StandaloneLauncher"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
setMainClass
|
|
||||||
# 3.set app name
|
|
||||||
function setAppName {
|
function setAppName {
|
||||||
if [ "$service" == $CHAT_SERVICE ]; then
|
if [ "$service" == $CHAT_SERVICE ]; then
|
||||||
app_name=$CHAT_APP_NAME
|
app_name=$CHAT_APP_NAME
|
||||||
elif [ "$service" == $HEADLESS_SERVICE ]; then
|
elif [ "$service" == $HEADLESS_SERVICE ]; then
|
||||||
app_name=$HEADLESS_APP_NAME
|
app_name=$HEADLESS_APP_NAME
|
||||||
elif [ "$service" == $PYLLM_SERVICE ]; then
|
else
|
||||||
app_name=$PYLLM_APP_NAME
|
app_name=$STANDALONE_APP_NAME
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
setAppName
|
|
||||||
|
|
||||||
function reloadExamples {
|
function reloadExamples {
|
||||||
pythonRunDir=${runtimeDir}/supersonic-${model_name}/pyllm
|
cd $baseDir/pyllm/sql
|
||||||
cd $pythonRunDir/sql
|
|
||||||
${python_path} examples_reload_run.py
|
${python_path} examples_reload_run.py
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runJavaService {
|
||||||
|
javaRunDir=$baseDir
|
||||||
|
local_app_name=$1
|
||||||
|
libDir=$baseDir/lib
|
||||||
|
confDir=$baseDir/conf
|
||||||
|
|
||||||
|
CLASSPATH=""
|
||||||
|
CLASSPATH=$CLASSPATH:$confDir
|
||||||
|
|
||||||
|
for jarPath in $libDir/*.jar; do
|
||||||
|
CLASSPATH=$CLASSPATH:$jarPath
|
||||||
|
done
|
||||||
|
|
||||||
|
export CLASSPATH
|
||||||
|
export LANG="zh_CN.UTF-8"
|
||||||
|
|
||||||
|
cd $javaRunDir
|
||||||
|
if [[ "$JAVA_HOME" == "" ]]; then
|
||||||
|
JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}')
|
||||||
|
fi
|
||||||
|
export PATH=$JAVA_HOME/bin:$PATH
|
||||||
|
command="-Dfile.encoding="UTF-8" -Duser.language="Zh" -Duser.region="CN" -Duser.timezone="GMT+08" -Dapp_name=${local_app_name} -Xms1024m -Xmx2048m "$main_class
|
||||||
|
|
||||||
|
mkdir -p $javaRunDir/logs
|
||||||
|
if [[ "$is_test" == "true" ]]; then
|
||||||
|
java -Dspring.profiles.active="dev" $command >/dev/null 2>$javaRunDir/logs/error.log &
|
||||||
|
else
|
||||||
|
java $command $javaRunDir >/dev/null 2>$javaRunDir/logs/error.log &
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function runPythonService {
|
||||||
|
pythonRunDir=$baseDir/pyllm
|
||||||
|
cd $pythonRunDir
|
||||||
|
nohup ${python_path} supersonic_pyllm.py > $pythonRunDir/pyllm.log 2>&1 &
|
||||||
|
# add health check
|
||||||
|
for i in {1..10}
|
||||||
|
do
|
||||||
|
echo "pyllm health check attempt $i..."
|
||||||
|
response=$(curl -s http://${PYLLM_HOST}:${PYLLM_PORT}/health)
|
||||||
|
echo "pyllm health check response: $response"
|
||||||
|
status_ok="Healthy"
|
||||||
|
if [[ $response == *$status_ok* ]] ; then
|
||||||
|
echo "pyllm Health check passed."
|
||||||
|
break
|
||||||
|
else
|
||||||
|
if [ "$i" -eq 10 ]; then
|
||||||
|
echo "pyllm Health check failed after 10 attempts."
|
||||||
|
echo "May still downloading model files. Please check pyllm.log in runtime directory."
|
||||||
|
fi
|
||||||
|
echo "Retrying after 5 seconds..."
|
||||||
|
sleep 5
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
function start()
|
function start()
|
||||||
{
|
{
|
||||||
@@ -93,18 +134,16 @@ function reload()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 4. execute command operation
|
setMainClass
|
||||||
|
setAppName
|
||||||
case "$command" in
|
case "$command" in
|
||||||
start)
|
start)
|
||||||
if [ "$service" == $PYLLM_SERVICE ]; then
|
if [ "$service" == $PYLLM_SERVICE ]; then
|
||||||
echo "Starting $app_name"
|
echo "Starting $PYLLM_APP_NAME"
|
||||||
start $app_name
|
start $PYLLM_APP_NAME
|
||||||
echo "Starting $STANDALONE_APP_NAME"
|
|
||||||
start $STANDALONE_APP_NAME
|
|
||||||
else
|
|
||||||
echo "Starting $app_name"
|
|
||||||
start $app_name
|
|
||||||
fi
|
fi
|
||||||
|
echo "Starting ${app_name}"
|
||||||
|
start ${app_name}
|
||||||
echo "Start success"
|
echo "Start success"
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
@@ -121,20 +160,15 @@ case "$command" in
|
|||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
if [ "$service" == $PYLLM_SERVICE ]; then
|
if [ "$service" == $PYLLM_SERVICE ]; then
|
||||||
echo "Stopping ${app_name}"
|
echo "Stopping $PYLLM_APP_NAME"
|
||||||
stop ${app_name}
|
stop $PYLLM_APP_NAME
|
||||||
echo "Stopping ${STANDALONE_APP_NAME}"
|
echo "Starting $PYLLM_APP_NAME"
|
||||||
stop $STANDALONE_APP_NAME
|
start $PYLLM_APP_NAME
|
||||||
echo "Starting ${app_name}"
|
|
||||||
start ${app_name}
|
|
||||||
echo "Starting ${STANDALONE_APP_NAME}"
|
|
||||||
start $STANDALONE_APP_NAME
|
|
||||||
else
|
|
||||||
echo "Stopping ${app_name}"
|
|
||||||
stop ${app_name}
|
|
||||||
echo "Starting ${app_name}"
|
|
||||||
start ${app_name}
|
|
||||||
fi
|
fi
|
||||||
|
echo "Stopping ${app_name}"
|
||||||
|
stop ${app_name}
|
||||||
|
echo "Starting ${app_name}"
|
||||||
|
start ${app_name}
|
||||||
echo "Restart success"
|
echo "Restart success"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
|||||||
@@ -26,6 +26,12 @@
|
|||||||
<fileMode>0777</fileMode>
|
<fileMode>0777</fileMode>
|
||||||
<directoryMode>0755</directoryMode>
|
<directoryMode>0755</directoryMode>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
|
<fileSet>
|
||||||
|
<directory>${project.basedir}/../../assembly/bin</directory>
|
||||||
|
<outputDirectory>bin</outputDirectory>
|
||||||
|
<fileMode>0777</fileMode>
|
||||||
|
<directoryMode>0755</directoryMode>
|
||||||
|
</fileSet>
|
||||||
</fileSets>
|
</fileSets>
|
||||||
|
|
||||||
<dependencySets>
|
<dependencySets>
|
||||||
|
|||||||
Reference in New Issue
Block a user