1、mvn install后,双击这个bat,实现docker build后上传到124服务器,并且重启124服务器
**@echo offsetlocal:: 定义镜像名称和版本变量
set IMAGE_NAME=web
set IMAGE_VERSION=1.3.1:: 清理本地文件
echo Cleaning up...
del service-%IMAGE_NAME%_%IMAGE_VERSION%.tar:: 删除原先的镜像
echo Deleting old image...
docker rmi -f %IMAGE_NAME%:%IMAGE_VERSION%
if %errorlevel% neq 0 (echo Failed to delete old image.pauseexit /b 1
):: 构建镜像
echo Building new image...
docker build -t "%IMAGE_NAME%:%IMAGE_VERSION%" .
if %errorlevel% neq 0 (echo Failed to build new image.pauseexit /b 1
):: 转化为tar包
echo Saving image as tar file...
docker save -o service-%IMAGE_NAME%_%IMAGE_VERSION%.tar %IMAGE_NAME%:%IMAGE_VERSION%
if %errorlevel% neq 0 (echo Failed to save tar file.pauseexit /b 1
):: 上传到服务器
echo Uploading tar file to server...
"C:\Program Files\PuTTY\pscp.exe" -pw opopop service-%IMAGE_NAME%_%IMAGE_VERSION%.tar op@192.168.20.124:/home/op/compose < NUL
if %errorlevel% neq 0 (echo Failed to upload tar file to server.pauseexit /b 1
):: 在服务器上执行 docker load
echo Loading image on server...
"C:\Program Files\PuTTY\plink.exe" -pw opopop op@192.168.20.124 "docker load -i /home/op/compose/service-%IMAGE_NAME%_%IMAGE_VERSION%.tar" < NUL
if %errorlevel% neq 0 (echo Failed to load image on server.pauseexit /b 1
):: 在服务器上执行停止脚本
echo Stopping containers on server...
"C:\Program Files\PuTTY\plink.exe" -pw opopop op@192.168.20.124 "cd /home/op/compose && /home/op/compose/stop.sh" < NUL
if %errorlevel% neq 0 (echo Failed to stop containers on server.pauseexit /b 1
):: 在服务器上执行启动脚本
echo Starting containers on server...
"C:\Program Files\PuTTY\plink.exe" -pw opopop op@192.168.20.124 "cd /home/op/compose && /home/op/compose/start.sh" < NUL
if %errorlevel% neq 0 (echo Failed to start containers on server.pauseexit /b 1
):: 清理本地文件
echo Cleaning up...
del service-%IMAGE_NAME%_%IMAGE_VERSION%.tarecho Done!
pause
**