.drone.yml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. #########################################################################################################
  2. # 1.打包构建lhb-gateway
  3. kind: pipeline
  4. type: docker
  5. name: lhb-gateway-prod
  6. volumes:
  7. - name: mvn_repo
  8. host:
  9. path: /home/ABServer/cache/mvn_repo
  10. - name: mvn_config
  11. host:
  12. path: /home/ABServer/config/mvn
  13. - name: build-artifacts
  14. host:
  15. path: /home/ABServer/webroot/lhb-gateway
  16. - name: dockerfile-source
  17. host:
  18. path: /home/ABServer/config/docker
  19. - name: timezone
  20. host:
  21. path: /etc/localtime
  22. - name: docker-socket
  23. host:
  24. path: /var/run/docker.sock
  25. clone:
  26. disable: false
  27. steps:
  28. # 阶段1: Maven构建
  29. - name: build-project
  30. image: maven:3.9.4-amazoncorretto-17
  31. pull: if-not-exists
  32. volumes:
  33. - name: mvn_repo
  34. path: /usr/share/maven/repo
  35. - name: mvn_config
  36. path: /usr/share/maven/conf
  37. commands:
  38. - mvn clean package -Dmaven.test.skip=true -P prod
  39. - echo "===== 构建产物验证 ====="
  40. - ls -l lhb-gateway/target/*.jar
  41. - '[ -d lhb-gateway/target/lib ] || exit 1'
  42. - '[ -d lhb-gateway/target/config ] || exit 1'
  43. # 阶段2: 准备Docker上下文(关键修正部分)
  44. - name: prepare-docker-context
  45. image: alpine:3.21.3
  46. depends_on: [ build-project ]
  47. volumes:
  48. - name: build-artifacts
  49. path: /context
  50. - name: dockerfile-source
  51. path: /dockerfiles
  52. commands:
  53. - rm -rf /context/*
  54. - cp -v lhb-gateway/target/*.jar /context/
  55. - cp -rv lhb-gateway/target/lib /context/
  56. - cp -rv lhb-gateway/target/config /context/
  57. - cp /dockerfiles/template-min.dockerfile /context/Dockerfile
  58. - sed -i 's/{Xms}/1024m/g' /context/Dockerfile
  59. - sed -i 's/{Xmx}/1024m/g' /context/Dockerfile
  60. - sed -i 's/{ImageName}/lhb-gateway/g' /context/Dockerfile
  61. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  62. - ls -alR /context
  63. # 阶段3: 构建并推送镜像
  64. - name: docker-build-push
  65. image: docker:24.0-cli
  66. depends_on: [ prepare-docker-context ]
  67. volumes:
  68. - name: build-artifacts
  69. path: /context
  70. - name: timezone
  71. path: /etc/localtime
  72. - name: docker-socket
  73. path: /var/run/docker.sock
  74. environment:
  75. HARBOR_USER:
  76. from_secret: harbor_robot
  77. HARBOR_PASS:
  78. from_secret: harbor_token
  79. commands:
  80. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  81. - cd /context
  82. - TAG=$(date +%Y%m%d%H%M%S)
  83. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-gateway:$TAG" .
  84. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-gateway:$TAG"
  85. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-gateway:$TAG"
  86. trigger:
  87. event: [ push ]
  88. branch: [ release-gateway ]
  89. #########################################################################################################
  90. #2.打包构建lhb-quartz-prod
  91. ---
  92. kind: pipeline
  93. type: docker
  94. name: lhb-quartz-prod
  95. volumes:
  96. - name: mvn_repo
  97. host:
  98. path: /home/ABServer/cache/mvn_repo
  99. - name: mvn_config
  100. host:
  101. path: /home/ABServer/config/mvn
  102. - name: build-artifacts
  103. host:
  104. path: /home/ABServer/webroot/lhb-quartz
  105. - name: dockerfile-source
  106. host:
  107. path: /home/ABServer/config/docker
  108. - name: timezone
  109. host:
  110. path: /etc/localtime
  111. - name: docker-socket
  112. host:
  113. path: /var/run/docker.sock
  114. clone:
  115. disable: false
  116. steps:
  117. # 阶段1: Maven构建
  118. - name: build-project
  119. image: maven:3.9.4-amazoncorretto-17
  120. pull: if-not-exists
  121. volumes:
  122. - name: mvn_repo
  123. path: /usr/share/maven/repo
  124. - name: mvn_config
  125. path: /usr/share/maven/conf
  126. commands:
  127. - mvn clean package -Dmaven.test.skip=true -P prod
  128. - echo "===== 构建产物验证 ====="
  129. - ls -l lhb-quartz/target/*.jar
  130. - '[ -d lhb-quartz/target/lib ] || exit 1'
  131. - '[ -d lhb-quartz/target/config ] || exit 1'
  132. # 阶段2: 准备Docker上下文(关键修正部分)
  133. - name: prepare-docker-context
  134. image: alpine:3.21.3
  135. depends_on: [ build-project ]
  136. volumes:
  137. - name: build-artifacts
  138. path: /context
  139. - name: dockerfile-source
  140. path: /dockerfiles
  141. commands:
  142. - rm -rf /context/*
  143. - cp -v lhb-quartz/target/*.jar /context/
  144. - cp -rv lhb-quartz/target/lib /context/
  145. - cp -rv lhb-quartz/target/config /context/
  146. - cp /dockerfiles/template-min.dockerfile /context/Dockerfile
  147. - sed -i 's/{Xms}/256m/g' /context/Dockerfile
  148. - sed -i 's/{Xmx}/256m/g' /context/Dockerfile
  149. - sed -i 's/{ImageName}/lhb-quartz/g' /context/Dockerfile
  150. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  151. - ls -alR /context
  152. # 阶段3: 构建并推送镜像
  153. - name: docker-build-push
  154. image: docker:24.0-cli
  155. depends_on: [ prepare-docker-context ]
  156. volumes:
  157. - name: build-artifacts
  158. path: /context
  159. - name: timezone
  160. path: /etc/localtime
  161. - name: docker-socket
  162. path: /var/run/docker.sock
  163. environment:
  164. HARBOR_USER:
  165. from_secret: harbor_robot
  166. HARBOR_PASS:
  167. from_secret: harbor_token
  168. commands:
  169. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  170. - cd /context
  171. - TAG=$(date +%Y%m%d%H%M%S)
  172. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-quartz:$TAG" .
  173. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-quartz:$TAG"
  174. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-quartz:$TAG"
  175. trigger:
  176. event: [ push ]
  177. branch: [ release-quartz ]
  178. ###########################################################################################################
  179. # 3.打包构建lhb-system-prod
  180. ---
  181. kind: pipeline
  182. type: docker
  183. name: lhb-system-prod
  184. # 定义所有 Volume 映射
  185. volumes:
  186. - name: mvn_repo
  187. host:
  188. path: /home/ABServer/cache/mvn_repo
  189. - name: mvn_config
  190. host:
  191. path: /home/ABServer/config/mvn
  192. - name: build-artifacts # 构建产物临时目录
  193. host:
  194. path: /home/ABServer/webroot/lhb-system
  195. - name: dockerfile-source
  196. host:
  197. path: /home/ABServer/config/docker
  198. - name: timezone
  199. host:
  200. path: /etc/localtime
  201. - name: docker-socket
  202. host:
  203. path: /var/run/docker.sock
  204. clone:
  205. disable: false
  206. steps:
  207. # 阶段1: Maven 构建
  208. - name: build-project
  209. image: maven:3.9.4-amazoncorretto-17
  210. pull: if-not-exists
  211. volumes:
  212. - name: mvn_repo
  213. path: /usr/share/maven/repo
  214. - name: mvn_config
  215. path: /usr/share/maven/conf
  216. commands:
  217. - mvn clean package -Dmaven.test.skip=true -P prod
  218. - echo "===== 构建产物生成验证 ====="
  219. - ls -l lhb-system/lhb-system-biz/target/*.jar
  220. - '[ -d lhb-system/lhb-system-biz/target/lib ] || exit 1'
  221. - '[ -d lhb-system/lhb-system-biz/target/config ] || exit 1'
  222. # 阶段2: 准备 Docker 构建上下文
  223. - name: prepare-docker-context
  224. image: alpine:3.21.3
  225. depends_on: [ build-project ]
  226. volumes:
  227. - name: build-artifacts
  228. path: /context
  229. - name: dockerfile-source
  230. path: /dockerfiles
  231. commands:
  232. - rm -rf /context/*
  233. - cp -v lhb-system/lhb-system-biz/target/*.jar /context/
  234. - cp -rv lhb-system/lhb-system-biz/target/lib /context/
  235. - cp -rv lhb-system/lhb-system-biz/target/config /context/
  236. - cp /dockerfiles/template-biz-min.dockerfile /context/Dockerfile
  237. - sed -i 's/{Xms}/512m/g' /context/Dockerfile
  238. - sed -i 's/{Xmx}/512m/g' /context/Dockerfile
  239. - sed -i 's/{ImageName}/lhb-system/g' /context/Dockerfile
  240. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  241. - echo "===== 构建上下文文件列表 ====="
  242. - ls -laR /context
  243. # 阶段3: 构建并推送镜像
  244. - name: docker-build-push
  245. image: docker:24.0-cli
  246. depends_on: [ prepare-docker-context ]
  247. volumes:
  248. - name: build-artifacts
  249. path: /context
  250. - name: timezone
  251. path: /etc/localtime
  252. - name: docker-socket
  253. path: /var/run/docker.sock
  254. environment:
  255. HARBOR_USER:
  256. from_secret: harbor_robot
  257. HARBOR_PASS:
  258. from_secret: harbor_token
  259. commands:
  260. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  261. - cd /context
  262. - TAG=$(date +%Y%m%d%H%M%S)
  263. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-system:$TAG" .
  264. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-system:$TAG"
  265. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-system:$TAG"
  266. trigger:
  267. event: [ push ]
  268. branch: [ release-system ]
  269. ##########################################################################################################
  270. # 4.打包构建lhb-basic
  271. ---
  272. kind: pipeline
  273. type: docker
  274. name: lhb-basic-prod
  275. # 定义所有 Volume 映射
  276. volumes:
  277. - name: mvn_repo
  278. host:
  279. path: /home/ABServer/cache/mvn_repo
  280. - name: mvn_config
  281. host:
  282. path: /home/ABServer/config/mvn
  283. - name: build-artifacts # 构建产物临时目录
  284. host:
  285. path: /home/ABServer/webroot/lhb-basic
  286. - name: dockerfile-source
  287. host:
  288. path: /home/ABServer/config/docker
  289. - name: timezone
  290. host:
  291. path: /etc/localtime
  292. - name: docker-socket
  293. host:
  294. path: /var/run/docker.sock
  295. clone:
  296. disable: false
  297. steps:
  298. # 阶段1: Maven 构建
  299. - name: build-project
  300. image: maven:3.9.4-amazoncorretto-17
  301. pull: if-not-exists
  302. volumes:
  303. - name: mvn_repo
  304. path: /usr/share/maven/repo
  305. - name: mvn_config
  306. path: /usr/share/maven/conf
  307. commands:
  308. - mvn clean package -Dmaven.test.skip=true -P prod
  309. - echo "===== 构建产物生成验证 ====="
  310. - ls -l lhb-basic/lhb-basic-biz/target/*.jar
  311. - '[ -d lhb-basic/lhb-basic-biz/target/lib ] || exit 1'
  312. - '[ -d lhb-basic/lhb-basic-biz/target/config ] || exit 1'
  313. # 阶段2: 准备 Docker 构建上下文
  314. - name: prepare-docker-context
  315. image: alpine:3.21.3
  316. depends_on: [ build-project ]
  317. volumes:
  318. - name: build-artifacts
  319. path: /context
  320. - name: dockerfile-source
  321. path: /dockerfiles
  322. commands:
  323. - rm -rf /context/*
  324. - cp -v lhb-basic/lhb-basic-biz/target/*.jar /context/
  325. - cp -rv lhb-basic/lhb-basic-biz/target/lib /context/
  326. - cp -rv lhb-basic/lhb-basic-biz/target/config /context/
  327. - cp /dockerfiles/template-biz-min.dockerfile /context/Dockerfile
  328. - sed -i 's/{Xms}/512m/g' /context/Dockerfile
  329. - sed -i 's/{Xmx}/512m/g' /context/Dockerfile
  330. - sed -i 's/{ImageName}/lhb-basic/g' /context/Dockerfile
  331. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  332. - echo "===== 构建上下文文件列表 ====="
  333. - ls -laR /context
  334. # 阶段3: 构建并推送镜像
  335. - name: docker-build-push
  336. image: docker:24.0-cli
  337. depends_on: [ prepare-docker-context ]
  338. volumes:
  339. - name: build-artifacts
  340. path: /context
  341. - name: timezone
  342. path: /etc/localtime
  343. - name: docker-socket
  344. path: /var/run/docker.sock
  345. environment:
  346. HARBOR_USER:
  347. from_secret: harbor_robot
  348. HARBOR_PASS:
  349. from_secret: harbor_token
  350. commands:
  351. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  352. - cd /context
  353. - TAG=$(date +%Y%m%d%H%M%S)
  354. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-basic:$TAG" .
  355. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-basic:$TAG"
  356. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-basic:$TAG"
  357. trigger:
  358. event: [ push ]
  359. branch: [ release-basic ]
  360. #############################################################################################
  361. # #
  362. # #
  363. # #
  364. # #
  365. # #
  366. #############################################################################################
  367. # 测试分支打包
  368. # 1.打包构建test-lhb-gateway
  369. ---
  370. kind: pipeline
  371. type: docker
  372. name: test-lhb-gateway
  373. # 定义所有Volume映射
  374. volumes:
  375. - name: mvn_repo
  376. host:
  377. path: /home/ABServer/drone/cache/mvn_repo
  378. - name: mvn_config
  379. host:
  380. path: /home/ABServer/drone/config/mvn
  381. - name: build-artifacts
  382. host:
  383. path: /home/ABServer/drone/webroot/test-lhb-gateway
  384. - name: dockerfile-source
  385. host:
  386. path: /home/ABServer/drone/config/docker
  387. - name: timezone
  388. host:
  389. path: /etc/localtime
  390. - name: docker-socket
  391. host:
  392. path: /var/run/docker.sock
  393. - name: delpoyment
  394. host:
  395. path: /home/ABServer/drone/config/shell
  396. clone:
  397. disable: false
  398. steps:
  399. # 阶段1: Maven构建
  400. - name: build-project
  401. image: maven:3.9.4-amazoncorretto-17
  402. pull: if-not-exists
  403. volumes:
  404. - name: mvn_repo
  405. path: /usr/share/maven/repo
  406. - name: mvn_config
  407. path: /usr/share/maven/conf
  408. commands:
  409. - mvn clean package -Dmaven.test.skip=true -P test
  410. - echo "===== 构建产物验证 ====="
  411. - ls -l lhb-gateway/target/*.jar
  412. - '[ -d lhb-gateway/target/lib ] || exit 1'
  413. - '[ -d lhb-gateway/target/config ] || exit 1'
  414. # 阶段2: 准备Docker上下文
  415. - name: prepare-docker-context
  416. image: alpine:3.21.3
  417. depends_on: [ build-project ]
  418. volumes:
  419. - name: build-artifacts
  420. path: /context
  421. - name: dockerfile-source
  422. path: /dockerfiles
  423. commands:
  424. - rm -rf /context/*
  425. - cp -v lhb-gateway/target/*.jar /context/
  426. - cp -rv lhb-gateway/target/lib /context/
  427. - cp -rv lhb-gateway/target/config /context/
  428. - cp /dockerfiles/template-test.dockerfile /context/Dockerfile
  429. - sed -i 's/{Xms}/512m/g' /context/Dockerfile
  430. - sed -i 's/{Xmx}/512m/g' /context/Dockerfile
  431. - sed -i 's/{ImageName}/lhb-gateway/g' /context/Dockerfile
  432. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  433. - ls -alR /context
  434. # 阶段3: 构建并推送镜像
  435. - name: docker-build-push
  436. image: docker:24.0-cli
  437. depends_on: [ prepare-docker-context ]
  438. volumes:
  439. - name: build-artifacts
  440. path: /context
  441. - name: timezone
  442. path: /etc/localtime
  443. - name: docker-socket
  444. path: /var/run/docker.sock
  445. - name: delpoyment
  446. path: /home
  447. environment:
  448. HARBOR_USER:
  449. from_secret: harbor_robot
  450. HARBOR_PASS:
  451. from_secret: harbor_token
  452. commands:
  453. - cd /context
  454. - TAG=test-$(date +%Y%m%d%H%M%S)
  455. - echo "$TAG" > /home/TAG.txt
  456. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  457. - docker build -t "harbor.kexiaoshuang.com/test/lhb-gateway:$TAG" .
  458. - docker push "harbor.kexiaoshuang.com/test/lhb-gateway:$TAG"
  459. - docker rmi "harbor.kexiaoshuang.com/test/lhb-gateway:$TAG"
  460. # 阶段四:测试环境部署服务
  461. - name: trigger-deploy
  462. image: curlimages/curl:latest
  463. depends_on: [ docker-build-push ]
  464. volumes:
  465. - name: delpoyment
  466. path: /shared
  467. commands:
  468. - TAG=$(cat /shared/TAG.txt)
  469. - echo "TAG=$TAG"
  470. - cd /shared
  471. - sh /shared/trigger-deploy.sh $TAG lhb-gateway laihaoba
  472. trigger:
  473. event: [ push ]
  474. branch: [ test-gateway-new ]
  475. #########################################################################################################
  476. #2.打包构建test-lhb-quartz
  477. ---
  478. kind: pipeline
  479. type: docker
  480. name: test-lhb-quartz
  481. volumes:
  482. - name: mvn_repo
  483. host:
  484. path: /home/ABServer/drone/cache/mvn_repo
  485. - name: mvn_config
  486. host:
  487. path: /home/ABServer/drone/config/mvn
  488. - name: build-artifacts
  489. host:
  490. path: /home/ABServer/drone/webroot/test-lhb-quartz
  491. - name: dockerfile-source
  492. host:
  493. path: /home/ABServer/drone/config/docker
  494. - name: timezone
  495. host:
  496. path: /etc/localtime
  497. - name: docker-socket
  498. host:
  499. path: /var/run/docker.sock
  500. - name: delpoyment
  501. host:
  502. path: /home/ABServer/drone/config/shell
  503. clone:
  504. disable: false
  505. steps:
  506. # 阶段1: Maven构建
  507. - name: build-project
  508. image: maven:3.9.4-amazoncorretto-17
  509. pull: if-not-exists
  510. volumes:
  511. - name: mvn_repo
  512. path: /usr/share/maven/repo
  513. - name: mvn_config
  514. path: /usr/share/maven/conf
  515. commands:
  516. - mvn clean package -Dmaven.test.skip=true -P test
  517. - echo "===== 构建产物验证 ====="
  518. - ls -l lhb-quartz/target/*.jar
  519. - '[ -d lhb-quartz/target/lib ] || exit 1'
  520. - '[ -d lhb-quartz/target/config ] || exit 1'
  521. # 阶段2: 准备Docker上下文(关键修正部分)
  522. - name: prepare-docker-context
  523. image: alpine:3.21.3
  524. depends_on: [ build-project ]
  525. volumes:
  526. - name: build-artifacts
  527. path: /context
  528. - name: dockerfile-source
  529. path: /dockerfiles
  530. commands:
  531. - rm -rf /context/*
  532. - cp -v lhb-quartz/target/*.jar /context/
  533. - cp -rv lhb-quartz/target/lib /context/
  534. - cp -rv lhb-quartz/target/config /context/
  535. - cp /dockerfiles/template-test.dockerfile /context/Dockerfile
  536. - sed -i 's/{Xms}/256m/g' /context/Dockerfile
  537. - sed -i 's/{Xmx}/256m/g' /context/Dockerfile
  538. - sed -i 's/{ImageName}/lhb-quartz/g' /context/Dockerfile
  539. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  540. - echo "=============构建上下文文件列表==============="
  541. - ls -alR /context
  542. # 阶段3: 构建并推送镜像
  543. - name: docker-build-push
  544. image: docker:24.0-cli
  545. depends_on: [ prepare-docker-context ]
  546. volumes:
  547. - name: build-artifacts
  548. path: /context
  549. - name: timezone
  550. path: /etc/localtime
  551. - name: docker-socket
  552. path: /var/run/docker.sock
  553. - name: delpoyment
  554. path: /home
  555. environment:
  556. HARBOR_USER:
  557. from_secret: harbor_robot
  558. HARBOR_PASS:
  559. from_secret: harbor_token
  560. commands:
  561. - cd /context
  562. - TAG=test-$(date +%Y%m%d%H%M%S)
  563. - echo "$TAG" > /home/TAG.txt
  564. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  565. - docker build -t "harbor.kexiaoshuang.com/test/lhb-quartz:$TAG" .
  566. - docker push "harbor.kexiaoshuang.com/test/lhb-quartz:$TAG"
  567. - docker rmi "harbor.kexiaoshuang.com/test/lhb-quartz:$TAG"
  568. # 阶段四:测试环境部署服务
  569. - name: trigger-deploy
  570. image: curlimages/curl:latest
  571. depends_on: [ docker-build-push ]
  572. volumes:
  573. - name: delpoyment
  574. path: /shared
  575. commands:
  576. - TAG=$(cat /shared/TAG.txt)
  577. - echo "TAG=$TAG"
  578. - cd /shared
  579. - sh /shared/trigger-deploy.sh $TAG lhb-quartz laihaoba
  580. trigger:
  581. event: [ push ]
  582. branch: [ test-quartz-new ]
  583. ###########################################################################################################
  584. # 3.打包构建test-lhb-system
  585. ---
  586. kind: pipeline
  587. type: docker
  588. name: test-lhb-system
  589. # 定义所有 Volume 映射
  590. volumes:
  591. - name: mvn_repo
  592. host:
  593. path: /home/ABServer/drone/cache/mvn_repo
  594. - name: mvn_config
  595. host:
  596. path: /home/ABServer/drone/config/mvn
  597. - name: build-artifacts # 构建产物临时目录
  598. host:
  599. path: /home/ABServer/drone/webroot/test-lhb-system
  600. - name: dockerfile-source
  601. host:
  602. path: /home/ABServer/drone/config/docker
  603. - name: timezone
  604. host:
  605. path: /etc/localtime
  606. - name: docker-socket
  607. host:
  608. path: /var/run/docker.sock
  609. - name: delpoyment
  610. host:
  611. path: /home/ABServer/drone/config/shell
  612. clone:
  613. disable: false
  614. steps:
  615. # 阶段1: Maven 构建
  616. - name: build-project
  617. image: maven:3.9.4-amazoncorretto-17
  618. pull: if-not-exists
  619. volumes:
  620. - name: mvn_repo
  621. path: /usr/share/maven/repo
  622. - name: mvn_config
  623. path: /usr/share/maven/conf
  624. commands:
  625. - mvn clean package -Dmaven.test.skip=true -P test
  626. - echo "===== 构建产物生成验证 ====="
  627. - ls -l lhb-system/lhb-system-biz/target/*.jar
  628. - '[ -d lhb-system/lhb-system-biz/target/lib ] || exit 1'
  629. - '[ -d lhb-system/lhb-system-biz/target/config ] || exit 1'
  630. # 阶段2: 准备 Docker 构建上下文
  631. - name: prepare-docker-context
  632. image: alpine:3.21.3
  633. depends_on: [ build-project ]
  634. volumes:
  635. - name: build-artifacts
  636. path: /context
  637. - name: dockerfile-source
  638. path: /dockerfiles
  639. commands:
  640. - rm -rf /context/*
  641. - cp -v lhb-system/lhb-system-biz/target/*.jar /context/
  642. - cp -rv lhb-system/lhb-system-biz/target/lib /context/
  643. - cp -rv lhb-system/lhb-system-biz/target/config /context/
  644. - cp /dockerfiles/template-biz-test.dockerfile /context/Dockerfile
  645. - sed -i 's/{Xms}/512m/g' /context/Dockerfile
  646. - sed -i 's/{Xmx}/512m/g' /context/Dockerfile
  647. - sed -i 's/{ImageName}/lhb-system/g' /context/Dockerfile
  648. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  649. - echo "===== 构建上下文文件列表 ====="
  650. - ls -laR /context
  651. # 阶段3: 构建并推送镜像
  652. - name: docker-build-push
  653. image: docker:24.0-cli
  654. depends_on: [ prepare-docker-context ]
  655. volumes:
  656. - name: build-artifacts
  657. path: /context
  658. - name: timezone
  659. path: /etc/localtime
  660. - name: docker-socket
  661. path: /var/run/docker.sock
  662. - name: delpoyment
  663. path: /home
  664. environment:
  665. HARBOR_USER:
  666. from_secret: harbor_robot
  667. HARBOR_PASS:
  668. from_secret: harbor_token
  669. commands:
  670. - cd /context
  671. - TAG=test-$(date +%Y%m%d%H%M%S)
  672. - echo "$TAG" > /home/TAG.txt
  673. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  674. - docker build -t "harbor.kexiaoshuang.com/test/lhb-system:$TAG" .
  675. - docker push "harbor.kexiaoshuang.com/test/lhb-system:$TAG"
  676. - docker rmi "harbor.kexiaoshuang.com/test/lhb-system:$TAG"
  677. # 阶段四:测试环境部署服务
  678. - name: trigger-deploy
  679. image: curlimages/curl:latest
  680. depends_on: [ docker-build-push ]
  681. volumes:
  682. - name: delpoyment
  683. path: /shared
  684. commands:
  685. - TAG=$(cat /shared/TAG.txt)
  686. - echo "TAG=$TAG"
  687. - cd /shared
  688. - sh /shared/trigger-deploy.sh $TAG lhb-system laihaoba
  689. trigger:
  690. event: [ push ]
  691. branch: [ test-system-new ]
  692. ##########################################################################################################
  693. # 4.打包构建test-lhb-basic
  694. ---
  695. kind: pipeline
  696. type: docker
  697. name: test-lhb-basic
  698. # 定义所有 Volume 映射
  699. volumes:
  700. - name: mvn_repo
  701. host:
  702. path: /home/ABServer/drone/cache/mvn_repo
  703. - name: mvn_config
  704. host:
  705. path: /home/ABServer/drone/config/mvn
  706. - name: build-artifacts # 构建产物临时目录
  707. host:
  708. path: /home/ABServer/drone/webroot/test-lhb-basic
  709. - name: dockerfile-source
  710. host:
  711. path: /home/ABServer/drone/config/docker
  712. - name: timezone
  713. host:
  714. path: /etc/localtime
  715. - name: docker-socket
  716. host:
  717. path: /var/run/docker.sock
  718. - name: delpoyment
  719. host:
  720. path: /home/ABServer/drone/config/shell
  721. clone:
  722. disable: false
  723. steps:
  724. # 阶段1: Maven 构建
  725. - name: build-project
  726. image: maven:3.9.4-amazoncorretto-17
  727. pull: if-not-exists
  728. volumes:
  729. - name: mvn_repo
  730. path: /usr/share/maven/repo
  731. - name: mvn_config
  732. path: /usr/share/maven/conf
  733. commands:
  734. - mvn clean package -Dmaven.test.skip=true -P test
  735. - echo "===== 构建产物生成验证 ====="
  736. - ls -l lhb-basic/lhb-basic-biz/target/*.jar
  737. - '[ -d lhb-basic/lhb-basic-biz/target/lib ] || exit 1'
  738. - '[ -d lhb-basic/lhb-basic-biz/target/config ] || exit 1'
  739. # 阶段2: 准备 Docker 构建上下文
  740. - name: prepare-docker-context
  741. image: alpine:3.21.3
  742. depends_on: [ build-project ]
  743. volumes:
  744. - name: build-artifacts
  745. path: /context
  746. - name: dockerfile-source
  747. path: /dockerfiles
  748. commands:
  749. - rm -rf /context/*
  750. - cp -v lhb-basic/lhb-basic-biz/target/*.jar /context/
  751. - cp -rv lhb-basic/lhb-basic-biz/target/lib /context/
  752. - cp -rv lhb-basic/lhb-basic-biz/target/config /context/
  753. - cp /dockerfiles/template-biz-test.dockerfile /context/Dockerfile
  754. - sed -i 's/{Xms}/512m/g' /context/Dockerfile
  755. - sed -i 's/{Xmx}/512m/g' /context/Dockerfile
  756. - sed -i 's/{ImageName}/lhb-basic/g' /context/Dockerfile
  757. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  758. - echo "===== 构建上下文文件列表 ====="
  759. - ls -laR /context
  760. # 阶段3: 构建并推送镜像
  761. - name: docker-build-push
  762. image: docker:24.0-cli
  763. depends_on: [ prepare-docker-context ]
  764. volumes:
  765. - name: build-artifacts
  766. path: /context
  767. - name: timezone
  768. path: /etc/localtime
  769. - name: docker-socket
  770. path: /var/run/docker.sock
  771. - name: delpoyment
  772. path: /home
  773. environment:
  774. HARBOR_USER:
  775. from_secret: harbor_robot
  776. HARBOR_PASS:
  777. from_secret: harbor_token
  778. commands:
  779. - cd /context
  780. - TAG=test-$(date +%Y%m%d%H%M%S)
  781. - echo "$TAG" > /home/TAG.txt
  782. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  783. - docker build -t "harbor.kexiaoshuang.com/test/lhb-basic:$TAG" .
  784. - docker push "harbor.kexiaoshuang.com/test/lhb-basic:$TAG"
  785. - docker rmi "harbor.kexiaoshuang.com/test/lhb-basic:$TAG"
  786. # 阶段四:测试环境部署服务
  787. - name: trigger-deploy
  788. image: curlimages/curl:latest
  789. depends_on: [ docker-build-push ]
  790. volumes:
  791. - name: delpoyment
  792. path: /shared
  793. commands:
  794. - TAG=$(cat /shared/TAG.txt)
  795. - echo "TAG=$TAG"
  796. - cd /shared
  797. - sh /shared/trigger-deploy.sh $TAG lhb-basic laihaoba
  798. trigger:
  799. event: [ push ]
  800. branch: [ test-basic-new ]