develop.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #安装maven
  2. if ! command -v mvn >/dev/null 2>&1; then
  3. echo "Installing Maven"
  4. # 下载Maven
  5. wget https://archive.apache.org/dist/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
  6. # 解压Maven
  7. tar -xzf apache-maven-3.8.1-bin.tar.gz -C /opt
  8. # 设置Maven环境变量
  9. echo 'export PATH=/opt/apache-maven-3.8.1/bin:$PATH' >> ~/.bashrc
  10. # 更改Maven镜像
  11. mkdir -p ~/.m2
  12. echo -e "<settings>\n <mirrors>\n <mirror>\n <id>aliyun-maven</id>\n <mirrorOf>*</mirrorOf>\n <name>Aliyun Maven</name>\n <url>https://maven.aliyun.com/repository/public</url>\n </mirror>\n </mirrors>\n</settings>" > ~/.m2/settings.xml
  13. source ~/.bashrc
  14. else
  15. echo "Maven is already installed"
  16. fi
  17. #安装git
  18. sudo yum install -y git
  19. #安装依赖
  20. sudo yum install -y yum-utils device-mapper-persistent-data lvm2
  21. #设置源
  22. sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  23. sudo yum makecache fast
  24. # 检查Docker是否已安装
  25. if ! command -v docker &> /dev/null
  26. then
  27. # 如果Docker未安装,执行安装步骤
  28. sudo yum install -y docker-ce
  29. sudo systemctl start docker
  30. fi
  31. # 检查Docker Compose是否已安装
  32. if ! command -v docker-compose &> /dev/null
  33. then
  34. # 如果Docker Compose未安装,执行安装步骤
  35. sudo curl -L "https://github.com/docker/compose/releases/download/v2.17.1/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
  36. sudo chmod +x /usr/local/bin/docker-compose
  37. fi
  38. # 显示版本号
  39. docker-compose -v
  40. #拉取代码打包
  41. APP_NAME="promotesai"
  42. mkdir -p /data/app/${APP_NAME}
  43. mkdir -p /data/app/${APP_NAME}/config
  44. cd /data/app/${APP_NAME}
  45. # 设置私有仓库信息
  46. repo_url="http://admin_lsl:Lsl18718383742@124.222.247.184:3000/wteamYD/promotesai-background.git"
  47. repo_branch="develop"
  48. # 克隆私有仓库代码
  49. # 删除目标路径(如果存在)
  50. if [ -d "promotesai-background" ]; then
  51. # 更新代码
  52. echo "更新代码"
  53. cd promotesai-background
  54. git pull origin ${repo_branch}
  55. else
  56. echo "拉取代码"
  57. git clone ${repo_url}
  58. cd promotesai-background
  59. git checkout -b ${repo_branch}
  60. git pull origin ${repo_branch}
  61. echo "Code successfully pulled from the private repository."
  62. fi
  63. # Maven打包
  64. echo 开始打包
  65. mvn clean package
  66. #echo 拷贝文件
  67. #cp -r ./config /data/app/${APP_NAME}
  68. # 定义应用组名:项目名
  69. group_name="promotesai"
  70. # 定义应用名称:客户端
  71. app_client_name="client-api"
  72. # 定义应用名称:管理端
  73. app_manager_name="manager-api"
  74. # 定义应用版本:最新版
  75. app_version='latest'
  76. # 定义应用环境
  77. profile_active='prod'
  78. echo '----stop container----'
  79. docker stop ${app_client_name}
  80. docker stop ${app_manager_name}
  81. echo '----rm container----'
  82. docker rm ${app_client_name}
  83. docker rm ${app_manager_name}
  84. echo '----rm image----'
  85. docker rmi ${group_name}/${app_client_name}:${app_version}
  86. docker rmi ${group_name}/${app_manager_name}:${app_version}
  87. # 构建客户端容器运行
  88. cd ${app_client_name}
  89. docker build -t ${group_name}/${app_client_name}:${app_version} --build-arg JAR_FILE=./target/client-api-0.0.1-SNAPSHOT.jar .
  90. echo '----build image----'
  91. docker run -p 8889:8889 --name ${app_client_name} \
  92. -e TZ="Asia/Shanghai" \
  93. -v /etc/localtime:/etc/localtime \
  94. -d ${group_name}/${app_client_name}:${app_version}
  95. echo '----start container----'
  96. # 构建管理端容器运行
  97. cd ../${app_manager_name}
  98. docker build -t ${group_name}/${app_manager_name}:${app_version} --build-arg JAR_FILE=./target/manager-api-0.0.1-SNAPSHOT.jar .
  99. echo '----build image----'
  100. docker run -p 8887:8887 --name ${app_manager_name} \
  101. -e TZ="Asia/Shanghai" \
  102. -v /etc/localtime:/etc/localtime \
  103. -d ${group_name}/${app_manager_name}:${app_version}
  104. echo '----start container----'