build.bat 1.59 KB
@echo off

TITLE 打包编译脚本

@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome

echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error

:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init

echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error

:init
echo 选择编译打包的环境:
echo.
echo  1.dev &echo.
echo  2.prd &echo.
echo  q.退出 &echo.&echo.&echo.

:input
set env=""
set/p input= 选择编译打包的环境:
if "%input%"=="1" (
    set env="dev"
) else if "%input%"=="2" (
    set env="prd"
) else if "%input%"=="Q" (
    goto sc_exit
) else if "%input%"=="q" (
     goto sc_exit
) else (
    echo 输入错误请重试
    echo.
    goto init
)

echo 环境: %env%
echo.
echo 开始执行打包命令:&echo.
call mvn clean install package -Dmaven.test.skip=true -P=%env%

for /f "delims=" %%i in ('docker images ^| findstr pre/freya') do set a=%%i
if not "%a%"=="" (
   call docker rmi pre/freya:pre
)

for /f "delims=" %%j in ('docker images ^| findstr freya') do set b=%%j
if not "%b%"=="" (
   call docker tag freya:lastest pre/freya:pre
)

echo 开始编译docker镜像:&echo.
call docker build -t freya:lastest -f ./Dockerfile --no-cache .

echo 按任意键关闭窗口 &echo.
PAUSE >nul

:error
set error_code = 1

:sc_exit
exit