mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 11:07:06 +00:00
(improvement)(chat) Support specifying spring.profiles.active at runtime to optimize the entire Docker deployment script. (#1302)
This commit is contained in:
@@ -7,9 +7,16 @@ call %sbinDir%/supersonic-common.bat %*
|
|||||||
|
|
||||||
set "command=%~1"
|
set "command=%~1"
|
||||||
set "service=%~2"
|
set "service=%~2"
|
||||||
|
set "profile=%~3"
|
||||||
|
|
||||||
if "%service%"=="" (
|
if "%service%"=="" (
|
||||||
set "service=%standalone_service%"
|
set "service=%standalone_service%"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if "%profile%"=="" (
|
||||||
|
set "profile=local"
|
||||||
|
)
|
||||||
|
|
||||||
set "model_name=%service%"
|
set "model_name=%service%"
|
||||||
|
|
||||||
cd %baseDir%
|
cd %baseDir%
|
||||||
@@ -32,30 +39,29 @@ if "%command%"=="restart" (
|
|||||||
goto :EOF
|
goto :EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
: start
|
:start
|
||||||
call :runJavaService
|
call :runJavaService
|
||||||
goto :EOF
|
goto :EOF
|
||||||
|
|
||||||
|
:stop
|
||||||
: stop
|
|
||||||
call :stopJavaService
|
call :stopJavaService
|
||||||
goto :EOF
|
goto :EOF
|
||||||
|
|
||||||
: runJavaService
|
:runJavaService
|
||||||
echo 'java service starting, see logs in logs/'
|
echo 'java service starting, see logs in logs/'
|
||||||
set "libDir=%baseDir%\lib"
|
set "libDir=%baseDir%\lib"
|
||||||
set "confDir=%baseDir%\conf"
|
set "confDir=%baseDir%\conf"
|
||||||
set "webDir=%baseDir%\webapp"
|
set "webDir=%baseDir%\webapp"
|
||||||
set "logDir=%baseDir%\logs"
|
set "logDir=%baseDir%\logs"
|
||||||
set "classpath=%baseDir%;%webDir%;%libDir%\*;%confDir%"
|
set "classpath=%baseDir%;%webDir%;%libDir%\*;%confDir%"
|
||||||
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 -Dspring.profiles.active=%profile% -Xms1024m -Xmx2048m -cp %CLASSPATH% %MAIN_CLASS%"
|
||||||
if not exist %logDir% mkdir %logDir%
|
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
|
||||||
|
|
||||||
: stopJavaService
|
: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."
|
||||||
|
|||||||
@@ -5,10 +5,16 @@ source $sbinDir/supersonic-common.sh
|
|||||||
|
|
||||||
command=$1
|
command=$1
|
||||||
service=$2
|
service=$2
|
||||||
|
profile=$3
|
||||||
|
|
||||||
if [ -z "$service" ]; then
|
if [ -z "$service" ]; then
|
||||||
service=${STANDALONE_SERVICE}
|
service=${STANDALONE_SERVICE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$profile" ]; then
|
||||||
|
profile="local"
|
||||||
|
fi
|
||||||
|
|
||||||
model_name=$service
|
model_name=$service
|
||||||
cd $baseDir
|
cd $baseDir
|
||||||
|
|
||||||
@@ -53,59 +59,53 @@ function runJavaService {
|
|||||||
JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}')
|
JAVA_HOME=$(ls /usr/jdk64/jdk* -d 2>/dev/null | xargs | awk '{print "'$local_app_name'"}')
|
||||||
fi
|
fi
|
||||||
export PATH=$JAVA_HOME/bin:$PATH
|
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
|
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
|
mkdir -p $javaRunDir/logs
|
||||||
if [[ "$is_test" == "true" ]]; then
|
java -Dspring.profiles.active="$profile" $command >/dev/null 2>$javaRunDir/logs/error.log &
|
||||||
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 start()
|
function start() {
|
||||||
{
|
|
||||||
local_app_name=$1
|
local_app_name=$1
|
||||||
echo "Starting ${local_app_name}"
|
echo "Starting ${local_app_name}"
|
||||||
pid=$(ps aux |grep ${local_app_name} | grep -v grep | awk '{print $2}')
|
pid=$(ps aux | grep ${local_app_name} | grep -v grep | awk '{print $2}')
|
||||||
if [[ "$pid" == "" ]]; then
|
if [[ "$pid" == "" ]]; then
|
||||||
runJavaService ${local_app_name}
|
runJavaService ${local_app_name}
|
||||||
else
|
else
|
||||||
echo "Process (PID = $pid) is running."
|
echo "Process (PID = $pid) is running."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo "Start success"
|
echo "Start success"
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop()
|
function stop() {
|
||||||
{
|
echo "Stopping $1"
|
||||||
echo "Stopping $1"
|
|
||||||
pid=$(ps aux | grep $1 | grep -v grep | awk '{print $2}')
|
pid=$(ps aux | grep $1 | grep -v grep | awk '{print $2}')
|
||||||
if [[ "$pid" == "" ]]; then
|
if [[ "$pid" == "" ]]; then
|
||||||
echo "Process $1 is not running !"
|
echo "Process $1 is not running!"
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
kill -9 $pid
|
kill -9 $pid
|
||||||
echo "Process (PID = $pid) is killed !"
|
echo "Process (PID = $pid) is killed!"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
echo "Stop success"
|
echo "Stop success"
|
||||||
}
|
}
|
||||||
|
|
||||||
setMainClass
|
setMainClass
|
||||||
setAppName
|
setAppName
|
||||||
case "$command" in
|
case "$command" in
|
||||||
start)
|
start)
|
||||||
start ${app_name}
|
start ${app_name}
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
stop $app_name
|
stop $app_name
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
stop ${app_name}
|
stop ${app_name}
|
||||||
start ${app_name}
|
start ${app_name}
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Use command {start|stop|restart} to run."
|
echo "Use command {start|stop|restart} to run."
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
@@ -26,4 +26,4 @@ WORKDIR /usr/src/app/supersonic-standalone-${SUPERSONIC_VERSION}
|
|||||||
EXPOSE 9080
|
EXPOSE 9080
|
||||||
# Command to run the supersonic daemon
|
# Command to run the supersonic daemon
|
||||||
RUN chmod +x bin/supersonic-daemon.sh
|
RUN chmod +x bin/supersonic-daemon.sh
|
||||||
CMD ["bash", "-c", "bin/supersonic-daemon.sh restart && tail -f /dev/null"]
|
CMD ["bash", "-c", "bin/supersonic-daemon.sh restart prd && tail -f /dev/null"]
|
||||||
36
docker/docker-build.bat
Normal file
36
docker/docker-build.bat
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
REM Function to execute the build script
|
||||||
|
:execute_build_script
|
||||||
|
echo Executing build script: assembly\bin\supersonic-build.bat
|
||||||
|
call assembly\bin\supersonic-build.bat
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Build script failed. Exiting.
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
goto :eof
|
||||||
|
|
||||||
|
REM Function to build the Docker image
|
||||||
|
:build_docker_image
|
||||||
|
set "version=%1"
|
||||||
|
echo Building Docker image: supersonic:%version%
|
||||||
|
docker build --no-cache --build-arg SUPERSONIC_VERSION=%version% -t supersonic:%version% -f docker\Dockerfile .
|
||||||
|
if %errorlevel% neq 0 (
|
||||||
|
echo Docker build failed. Exiting.
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
echo Docker image supersonic:%version% built successfully.
|
||||||
|
goto :eof
|
||||||
|
|
||||||
|
REM Main script execution
|
||||||
|
set "VERSION=%1"
|
||||||
|
if "%VERSION%"=="" (
|
||||||
|
echo Usage: %0 ^<version^>
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
call :execute_build_script
|
||||||
|
call :build_docker_image %VERSION%
|
||||||
|
|
||||||
|
endlocal
|
||||||
@@ -19,7 +19,7 @@ services:
|
|||||||
- 8.8.4.4
|
- 8.8.4.4
|
||||||
|
|
||||||
db_init:
|
db_init:
|
||||||
image: supersonic:0.9.2-SNAPSHOT
|
image: supersonicbi/supersonic:0.9.2-SNAPSHOT
|
||||||
container_name: supersonic_db_init
|
container_name: supersonic_db_init
|
||||||
depends_on:
|
depends_on:
|
||||||
- mysql
|
- mysql
|
||||||
@@ -51,7 +51,7 @@ services:
|
|||||||
- 8.8.4.4
|
- 8.8.4.4
|
||||||
|
|
||||||
java_backend:
|
java_backend:
|
||||||
image: supersonic:0.9.2-SNAPSHOT
|
image: supersonicbi/supersonic:0.9.2-SNAPSHOT
|
||||||
container_name: supersonic_java_backend
|
container_name: supersonic_java_backend
|
||||||
environment:
|
environment:
|
||||||
DB_HOST: supersonic_mysql
|
DB_HOST: supersonic_mysql
|
||||||
|
|||||||
Reference in New Issue
Block a user