publish_docker.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. # -p:允许后面跟一个字符串作为提示 -r:保证读入的是原始内容,不会发生任何转义
  3. read -r -p "请输入Dockedr镜像版本:" version
  4. echo "即将构建的 server 镜像:powerjob-server:$version"
  5. echo "即将构建的 agent 镜像:powerjob-agent:$version"
  6. read -r -p "任意键继续:"
  7. # 一键部署脚本,请勿挪动脚本
  8. cd `dirname $0`/../.. || exit
  9. read -r -p "是否进行maven构建(y/n):" needmvn
  10. if [ "$needmvn" = "y" ] || [ "$needmvn" = "Y" ]; then
  11. echo "================== 构建 jar =================="
  12. # mvn clean package -Pdev -DskipTests -U -e -pl powerjob-server,powerjob-worker-agent -am
  13. # -U:强制检查snapshot库 -pl:指定需要构建的模块,多模块逗号分割 -am:同时构建依赖模块,一般与pl连用 -Pxxx:指定使用的配置文件
  14. mvn clean package -Pdev -DskipTests -U -e
  15. echo "================== 拷贝 jar =================="
  16. /bin/cp -rf powerjob-server/powerjob-server-starter/target/*.jar powerjob-server/docker/powerjob-server.jar
  17. /bin/cp -rf powerjob-worker-agent/target/*.jar powerjob-worker-agent/powerjob-agent.jar
  18. ls -l powerjob-server/docker/powerjob-server.jar
  19. ls -l powerjob-worker-agent/powerjob-agent.jar
  20. fi
  21. echo "================== 关闭老应用 =================="
  22. docker stop powerjob-server
  23. docker stop powerjob-agent
  24. docker stop powerjob-agent2
  25. echo "================== 删除老容器 =================="
  26. docker container rm powerjob-server
  27. docker container rm powerjob-agent
  28. docker container rm powerjob-agent2
  29. read -r -p "是否重新构建镜像(y/n):" rebuild
  30. if [ "$rebuild" = "y" ] || [ "$rebuild" = "Y" ]; then
  31. echo "================== 删除旧镜像 =================="
  32. docker rmi -f tjqq/powerjob-server:$version
  33. docker rmi -f powerjob/powerjob-server:$version
  34. docker rmi -f tjqq/powerjob-agent:$version
  35. docker rmi -f powerjob/powerjob-agent:$version
  36. docker rmi -f powerjob/powerjob-mysql:$version
  37. docker rmi -f powerjob/powerjob-worker-samples:$version
  38. echo "================== 构建 powerjob-server 镜像 =================="
  39. docker build -t tjqq/powerjob-server:$version powerjob-server/docker/. || exit
  40. echo "================== 构建 powerjob-agent 镜像 =================="
  41. docker build -t tjqq/powerjob-agent:$version powerjob-worker-agent/. || exit
  42. echo "================== 构建 powerjob-mysql 镜像 =================="
  43. docker build -t powerjob/powerjob-mysql:$version others/. || exit
  44. echo "================== 构建 powerjob-worker-samples 镜像 =================="
  45. docker build -t powerjob/powerjob-worker-samples:$version powerjob-worker-samples/. || exit
  46. read -r -p "是否正式发布该镜像(y/n):" needrelease
  47. if [ "$needrelease" = "y" ] || [ "$needrelease" = "Y" ]; then
  48. read -r -p "三思!请确保当前处于已发布的Master分支!(y/n):" needrelease
  49. if [ "$needrelease" = "y" ] || [ "$needrelease" = "Y" ]; then
  50. echo "================== 正在推送 server 镜像到中央仓库 =================="
  51. docker push tjqq/powerjob-server:$version
  52. echo "================== 正在推送 agent 镜像到中央仓库 =================="
  53. docker push tjqq/powerjob-agent:$version
  54. echo "================== 正在推送 powerjob-mysql 镜像到中央仓库 =================="
  55. docker push powerjob/powerjob-mysql:$version
  56. echo "================== 正在推送 samples 镜像到中央仓库 =================="
  57. docker push powerjob/powerjob-worker-samples:$version
  58. echo "================== 双写推送 =================="
  59. docker tag tjqq/powerjob-server:$version powerjob/powerjob-server:$version
  60. docker push powerjob/powerjob-server:$version
  61. docker tag tjqq/powerjob-agent:$version powerjob/powerjob-agent:$version
  62. docker push powerjob/powerjob-agent:$version
  63. echo "================== 更新 LATEST 版本 =================="
  64. docker tag powerjob/powerjob-server:$version powerjob/powerjob-server:latest
  65. docker push powerjob/powerjob-server:latest
  66. docker tag powerjob/powerjob-agent:$version powerjob/powerjob-agent:latest
  67. docker push powerjob/powerjob-agent:latest
  68. docker tag powerjob/powerjob-mysql:$version powerjob/powerjob-mysql:latest
  69. docker push powerjob/powerjob-mysql:latest
  70. docker tag powerjob/powerjob-worker-samples:$version powerjob/powerjob-worker-samples:latest
  71. docker push powerjob/powerjob-worker-samples:latest
  72. echo "================== Docker 推送完毕 =================="
  73. fi
  74. fi
  75. fi
  76. read -r -p "是否启动 server & agent(y/n):" startup
  77. if [ "$startup" = "y" ] || [ "$startup" = "Y" ]; then
  78. # 启动应用(端口映射、数据路径挂载)
  79. ## -d:后台运行
  80. ## -p:指定端口映射,主机端口:容器端口
  81. ## --name:指定容器名称
  82. ## -v(--volume):挂载目录,宿主机目录:docker内目录,写入docker内路径的数据会被直接写到宿主机上,常用于日志文件
  83. ## --net=host:容器和宿主机共享网络(容器直接使用宿主机IP,性能最好,但网络隔离较差)
  84. echo "================== 准备启动 powerjob-server =================="
  85. docker run -d \
  86. --name powerjob-server \
  87. -p 7700:7700 -p 10086:10086 -p 10010:10010 -p 5001:5005 -p 10001:10000 \
  88. -e JVMOPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10000 -Dcom.sun.management.jmxremote.rmi.port=10000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
  89. -e PARAMS="--spring.profiles.active=pre" \
  90. -e TZ="Asia/Shanghai" \
  91. -v ~/docker/powerjob-server:/root/powerjob-server -v ~/.m2:/root/.m2 \
  92. tjqq/powerjob-server:$version
  93. sleep 1
  94. # tail -f -n 1000 ~/docker/powerjob-server/logs/powerjob-server-application.log
  95. sleep 30
  96. echo "================== 准备启动 powerjob-client =================="
  97. serverIP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' powerjob-server)
  98. serverAddress="$serverIP:7700"
  99. echo "使用的Server地址:$serverAddress"
  100. docker run -d \
  101. --name powerjob-agent \
  102. -p 27777:27777 -p 5002:5005 -p 10002:10000 \
  103. -e JVMOPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10000 -Dcom.sun.management.jmxremote.rmi.port=10000 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false" \
  104. -e PARAMS="--app powerjob-agent-test --server $serverAddress" \
  105. -v ~/docker/powerjob-agent:/root \
  106. tjqq/powerjob-agent:$version
  107. docker run -d \
  108. --name powerjob-agent2 \
  109. -p 27778:27777 -p 5003:5005 -p 10003:10000 \
  110. -e JVMOPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" \
  111. -e PARAMS="--app powerjob-agent-test --server $serverAddress" \
  112. -v ~/docker/powerjob-agent2:/root \
  113. tjqq/powerjob-agent:$version
  114. tail -f -n 100 ~/docker/powerjob-agent/powerjob/logs/powerjob-agent-application.log
  115. fi