.drone.yml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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/{ImageName}/lhb-gateway/g' /context/Dockerfile
  59. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  60. - ls -alR /context
  61. # 阶段3: 构建并推送镜像
  62. - name: docker-build-push
  63. image: docker:24.0-cli
  64. depends_on: [ prepare-docker-context ]
  65. volumes:
  66. - name: build-artifacts
  67. path: /context
  68. - name: timezone
  69. path: /etc/localtime
  70. - name: docker-socket
  71. path: /var/run/docker.sock
  72. environment:
  73. HARBOR_USER:
  74. from_secret: harbor_robot
  75. HARBOR_PASS:
  76. from_secret: harbor_token
  77. commands:
  78. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  79. - cd /context
  80. - TAG=$(date +%Y%m%d%H%M%S)
  81. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-gateway:$TAG" .
  82. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-gateway:$TAG"
  83. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-gateway:$TAG"
  84. trigger:
  85. event: [ push ]
  86. branch: [ release-lhb-gateway ]
  87. #########################################################################################################
  88. #2.打包构建lhb-quartz-prod
  89. ---
  90. kind: pipeline
  91. type: docker
  92. name: lhb-quartz-prod
  93. volumes:
  94. - name: mvn_repo
  95. host:
  96. path: /home/ABServer/cache/mvn_repo
  97. - name: mvn_config
  98. host:
  99. path: /home/ABServer/config/mvn
  100. - name: build-artifacts
  101. host:
  102. path: /home/ABServer/webroot/lhb-quartz
  103. - name: dockerfile-source
  104. host:
  105. path: /home/ABServer/config/docker
  106. - name: timezone
  107. host:
  108. path: /etc/localtime
  109. - name: docker-socket
  110. host:
  111. path: /var/run/docker.sock
  112. clone:
  113. disable: false
  114. steps:
  115. # 阶段1: Maven构建
  116. - name: build-project
  117. image: maven:3.9.4-amazoncorretto-17
  118. pull: if-not-exists
  119. volumes:
  120. - name: mvn_repo
  121. path: /usr/share/maven/repo
  122. - name: mvn_config
  123. path: /usr/share/maven/conf
  124. commands:
  125. - mvn clean package -Dmaven.test.skip=true -P prod
  126. - echo "===== 构建产物验证 ====="
  127. - ls -l lhb-quartz/target/*.jar
  128. - '[ -d lhb-quartz/target/lib ] || exit 1'
  129. - '[ -d lhb-quartz/target/config ] || exit 1'
  130. # 阶段2: 准备Docker上下文(关键修正部分)
  131. - name: prepare-docker-context
  132. image: alpine:3.21.3
  133. depends_on: [ build-project ]
  134. volumes:
  135. - name: build-artifacts
  136. path: /context
  137. - name: dockerfile-source
  138. path: /dockerfiles
  139. commands:
  140. - rm -rf /context/*
  141. - cp -v lhb-quartz/target/*.jar /context/
  142. - cp -rv lhb-quartz/target/lib /context/
  143. - cp -rv lhb-quartz/target/config /context/
  144. - cp /dockerfiles/template-min.dockerfile /context/Dockerfile
  145. - sed -i 's/{ImageName}/lhb-quartz/g' /context/Dockerfile
  146. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  147. - ls -alR /context
  148. # 阶段3: 构建并推送镜像
  149. - name: docker-build-push
  150. image: docker:24.0-cli
  151. depends_on: [ prepare-docker-context ]
  152. volumes:
  153. - name: build-artifacts
  154. path: /context
  155. - name: timezone
  156. path: /etc/localtime
  157. - name: docker-socket
  158. path: /var/run/docker.sock
  159. environment:
  160. HARBOR_USER:
  161. from_secret: harbor_robot
  162. HARBOR_PASS:
  163. from_secret: harbor_token
  164. commands:
  165. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  166. - cd /context
  167. - TAG=$(date +%Y%m%d%H%M%S)
  168. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-quartz:$TAG" .
  169. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-quartz:$TAG"
  170. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-quartz:$TAG"
  171. trigger:
  172. event: [ push ]
  173. branch: [ release-lhb-quartz ]
  174. ###########################################################################################################
  175. # 3.打包构建lhb-system-prod
  176. ---
  177. kind: pipeline
  178. type: docker
  179. name: lhb-system-prod
  180. # 定义所有 Volume 映射
  181. volumes:
  182. - name: mvn_repo
  183. host:
  184. path: /home/ABServer/cache/mvn_repo
  185. - name: mvn_config
  186. host:
  187. path: /home/ABServer/config/mvn
  188. - name: build-artifacts # 构建产物临时目录
  189. host:
  190. path: /home/ABServer/webroot/lhb-system
  191. - name: dockerfile-source
  192. host:
  193. path: /home/ABServer/config/docker
  194. - name: timezone
  195. host:
  196. path: /etc/localtime
  197. - name: docker-socket
  198. host:
  199. path: /var/run/docker.sock
  200. clone:
  201. disable: false
  202. steps:
  203. # 阶段1: Maven 构建
  204. - name: build-project
  205. image: maven:3.9.4-amazoncorretto-17
  206. pull: if-not-exists
  207. volumes:
  208. - name: mvn_repo
  209. path: /usr/share/maven/repo
  210. - name: mvn_config
  211. path: /usr/share/maven/conf
  212. commands:
  213. - mvn clean package -Dmaven.test.skip=true -P prod
  214. - echo "===== 构建产物生成验证 ====="
  215. - ls -l lhb-system/lhb-system-biz/target/*.jar
  216. - '[ -d lhb-system/lhb-system-biz/target/lib ] || exit 1'
  217. - '[ -d lhb-system/lhb-system-biz/target/config ] || exit 1'
  218. # 阶段2: 准备 Docker 构建上下文
  219. - name: prepare-docker-context
  220. image: alpine:3.21.3
  221. depends_on: [ build-project ]
  222. volumes:
  223. - name: build-artifacts
  224. path: /context
  225. - name: dockerfile-source
  226. path: /dockerfiles
  227. commands:
  228. - rm -rf /context/*
  229. - cp -v lhb-system/lhb-system-biz/target/*.jar /context/
  230. - cp -rv lhb-system/lhb-system-biz/target/lib /context/
  231. - cp -rv lhb-system/lhb-system-biz/target/config /context/
  232. - cp /dockerfiles/template-biz-min.dockerfile /context/Dockerfile
  233. - sed -i 's/{ImageName}/lhb-system/g' /context/Dockerfile
  234. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  235. - echo "===== 构建上下文文件列表 ====="
  236. - ls -laR /context
  237. # 阶段3: 构建并推送镜像
  238. - name: docker-build-push
  239. image: docker:24.0-cli
  240. depends_on: [ prepare-docker-context ]
  241. volumes:
  242. - name: build-artifacts
  243. path: /context
  244. - name: timezone
  245. path: /etc/localtime
  246. - name: docker-socket
  247. path: /var/run/docker.sock
  248. environment:
  249. HARBOR_USER:
  250. from_secret: harbor_robot
  251. HARBOR_PASS:
  252. from_secret: harbor_token
  253. commands:
  254. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  255. - cd /context
  256. - TAG=$(date +%Y%m%d%H%M%S)
  257. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-system:$TAG" .
  258. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-system:$TAG"
  259. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-system:$TAG"
  260. trigger:
  261. event: [ push ]
  262. branch: [ release-lhb-system ]
  263. ##########################################################################################################
  264. # 4.打包构建lhb-basic
  265. ---
  266. kind: pipeline
  267. type: docker
  268. name: lhb-basic-prod
  269. # 定义所有 Volume 映射
  270. volumes:
  271. - name: mvn_repo
  272. host:
  273. path: /home/ABServer/cache/mvn_repo
  274. - name: mvn_config
  275. host:
  276. path: /home/ABServer/config/mvn
  277. - name: build-artifacts # 构建产物临时目录
  278. host:
  279. path: /home/ABServer/webroot/lhb-basic
  280. - name: dockerfile-source
  281. host:
  282. path: /home/ABServer/config/docker
  283. - name: timezone
  284. host:
  285. path: /etc/localtime
  286. - name: docker-socket
  287. host:
  288. path: /var/run/docker.sock
  289. clone:
  290. disable: false
  291. steps:
  292. # 阶段1: Maven 构建
  293. - name: build-project
  294. image: maven:3.9.4-amazoncorretto-17
  295. pull: if-not-exists
  296. volumes:
  297. - name: mvn_repo
  298. path: /usr/share/maven/repo
  299. - name: mvn_config
  300. path: /usr/share/maven/conf
  301. commands:
  302. - mvn clean package -Dmaven.test.skip=true -P prod
  303. - echo "===== 构建产物生成验证 ====="
  304. - ls -l lhb-basic/lhb-basic-biz/target/*.jar
  305. - '[ -d lhb-basic/lhb-basic-biz/target/lib ] || exit 1'
  306. - '[ -d lhb-basic/lhb-basic-biz/target/config ] || exit 1'
  307. # 阶段2: 准备 Docker 构建上下文
  308. - name: prepare-docker-context
  309. image: alpine:3.21.3
  310. depends_on: [ build-project ]
  311. volumes:
  312. - name: build-artifacts
  313. path: /context
  314. - name: dockerfile-source
  315. path: /dockerfiles
  316. commands:
  317. - rm -rf /context/*
  318. - cp -v lhb-basic/lhb-basic-biz/target/*.jar /context/
  319. - cp -rv lhb-basic/lhb-basic-biz/target/lib /context/
  320. - cp -rv lhb-basic/lhb-basic-biz/target/config /context/
  321. - cp /dockerfiles/template-biz-min.dockerfile /context/Dockerfile
  322. - sed -i 's/{ImageName}/lhb-basic/g' /context/Dockerfile
  323. - echo -e "*\n!*.jar\n!lib/\n!config/\n!Dockerfile" > /context/.dockerignore
  324. - echo "===== 构建上下文文件列表 ====="
  325. - ls -laR /context
  326. # 阶段3: 构建并推送镜像
  327. - name: docker-build-push
  328. image: docker:24.0-cli
  329. depends_on: [ prepare-docker-context ]
  330. volumes:
  331. - name: build-artifacts
  332. path: /context
  333. - name: timezone
  334. path: /etc/localtime
  335. - name: docker-socket
  336. path: /var/run/docker.sock
  337. environment:
  338. HARBOR_USER:
  339. from_secret: harbor_robot
  340. HARBOR_PASS:
  341. from_secret: harbor_token
  342. commands:
  343. - docker login -u "$HARBOR_USER" -p "$HARBOR_PASS" harbor.kexiaoshuang.com
  344. - cd /context
  345. - TAG=$(date +%Y%m%d%H%M%S)
  346. - docker build -t "harbor.kexiaoshuang.com/laihaoba/lhb-basic:$TAG" .
  347. - docker push "harbor.kexiaoshuang.com/laihaoba/lhb-basic:$TAG"
  348. - docker rmi "harbor.kexiaoshuang.com/laihaoba/lhb-basic:$TAG"
  349. trigger:
  350. event: [ push ]
  351. branch: [ release-lhb-basic ]
  352. ############################################################################################
  353. # 测试分支打包
  354. # 1.lhb-gateway-test
  355. ---
  356. kind: pipeline
  357. type: docker
  358. name: lhb-gateway-test
  359. volumes: # 声明数据卷
  360. - name: mvn_repo # 数据卷名称
  361. # Host Volume, 挂载到宿主机上的卷轴
  362. host:
  363. # 宿主机的绝对路径
  364. path: /home/ABServer/cache/mvn_repo
  365. - name: mvn_config
  366. host:
  367. path: /home/ABServer/config/mvn/
  368. - name: targetDir
  369. host:
  370. path: /lhb-gateway
  371. clone:
  372. disable: false # 启用代码拉取
  373. steps:
  374. - name: build-project
  375. image: maven:3.9.4-amazoncorretto-17
  376. pull: if-not-exists
  377. depends_on: [clone] # 依赖的步骤
  378. volumes: # 挂载数据卷
  379. - name: mvn_repo # 数据卷名称
  380. path: /usr/share/maven/repo # 容器内目录 绝对路径
  381. - name: targetDir
  382. path: /drone/src/dist/
  383. - name: mvn_config
  384. path: /usr/share/maven/conf/
  385. commands: # 执行命令
  386. - rm -rf /drone/src/dist/*
  387. - mvn clean package -Dmaven.test.skip=true -P test
  388. - cp /drone/src/lhb-gateway/target/*.jar /drone/src/dist/ && cp -r /drone/src/lhb-gateway/target/lib /drone/src/dist/ && cp -r /drone/src/lhb-gateway/target/config /drone/src/dist/ # 复制文件
  389. when:
  390. status:
  391. - success # 当前步骤成功时执行
  392. - name: scp-project
  393. image: appleboy/drone-scp
  394. pull: if-not-exists
  395. depends_on: [build-project] # 依赖的步骤
  396. volumes: # 挂载数据卷
  397. - name: targetDir # 数据卷名称
  398. path: /lhb-gateway # 容器内目录 绝对路径
  399. settings:
  400. host:
  401. from_secret: host
  402. username:
  403. from_secret: username
  404. password:
  405. from_secret: userpwd
  406. port: 22
  407. command_timeout: 2m
  408. target: /home/ABServer/deploy-ready/
  409. source:
  410. - echo ====开始拷贝=======
  411. - /lhb-gateway/*.jar
  412. - /lhb-gateway/lib
  413. - /lhb-gateway/config
  414. - echo ====结束拷贝=======
  415. when:
  416. status:
  417. - success # 当前步骤成功时执行
  418. - name: deploy-project
  419. image: appleboy/drone-ssh
  420. pull: if-not-exists
  421. depends_on: [scp-project] # 依赖的步骤
  422. settings:
  423. host:
  424. from_secret: host
  425. username:
  426. from_secret: username
  427. password:
  428. from_secret: userpwd
  429. port: 22
  430. command_timeout: 2m
  431. script:
  432. - echo ====开始部署=======
  433. - cd /home/ABServer/
  434. - cp -r /home/ABServer/deploy-ready/lhb-gateway /home/ABServer/webroot/
  435. - docker stop lhb-gateway && docker rm lhb-gateway && docker-compose up -d lhb-gateway
  436. # - docker restart nodeServer1
  437. - echo ====部署成功=======
  438. trigger:
  439. branch:
  440. include:
  441. - test-gateway
  442. event:
  443. include:
  444. - pull_request
  445. - push
  446. ############################################################################################
  447. ---
  448. kind: pipeline
  449. type: docker
  450. name: lhb-quartz-test
  451. volumes: # 声明数据卷
  452. - name: mvn_repo # 数据卷名称
  453. # Host Volume, 挂载到宿主机上的卷轴
  454. host:
  455. # 宿主机的绝对路径
  456. path: /home/ABServer/cache/mvn_repo
  457. - name: mvn_config
  458. host:
  459. path: /home/ABServer/config/mvn/
  460. - name: targetDir
  461. host:
  462. path: /lhb-quartz
  463. clone:
  464. disable: false # 启用代码拉取
  465. steps:
  466. - name: build-project
  467. image: maven:3.9.4-amazoncorretto-17
  468. pull: if-not-exists
  469. depends_on: [clone] # 依赖的步骤
  470. volumes: # 挂载数据卷
  471. - name: mvn_repo # 数据卷名称
  472. path: /usr/share/maven/repo # 容器内目录 绝对路径
  473. - name: targetDir
  474. path: /drone/src/dist/
  475. - name: mvn_config
  476. path: /usr/share/maven/conf/
  477. commands: # 执行命令
  478. - rm -rf /drone/src/dist/*
  479. - mvn clean package -Dmaven.test.skip=true -P test
  480. - cp /drone/src/lhb-quartz/target/*.jar /drone/src/dist/ && cp -r /drone/src/lhb-quartz/target/lib /drone/src/dist/ && cp -r /drone/src/lhb-quartz/target/config /drone/src/dist/ # 复制文件
  481. when:
  482. status:
  483. - success # 当前步骤成功时执行
  484. - name: scp-project
  485. image: appleboy/drone-scp
  486. pull: if-not-exists
  487. depends_on: [build-project] # 依赖的步骤
  488. volumes: # 挂载数据卷
  489. - name: targetDir # 数据卷名称
  490. path: /lhb-quartz # 容器内目录 绝对路径
  491. settings:
  492. host:
  493. from_secret: host
  494. username:
  495. from_secret: username
  496. password:
  497. from_secret: userpwd
  498. port: 22
  499. command_timeout: 2m
  500. target: /home/ABServer/deploy-ready/
  501. source:
  502. - echo ====开始拷贝=======
  503. - /lhb-quartz/*.jar
  504. - /lhb-quartz/lib
  505. - /lhb-quartz/config
  506. - echo ====结束拷贝=======
  507. when:
  508. status:
  509. - success # 当前步骤成功时执行
  510. - name: deploy-project
  511. image: appleboy/drone-ssh
  512. pull: if-not-exists
  513. depends_on: [scp-project] # 依赖的步骤
  514. settings:
  515. host:
  516. from_secret: host
  517. username:
  518. from_secret: username
  519. password:
  520. from_secret: userpwd
  521. port: 22
  522. command_timeout: 2m
  523. script:
  524. - echo ====开始部署=======
  525. - cd /home/ABServer/
  526. - rm -rf /home/ABServer/webroot/lhb-quartz/*
  527. - cp -r /home/ABServer/deploy-ready/lhb-quartz /home/ABServer/webroot/
  528. - docker restart lhb-quartz
  529. - rm -rf /home/ABServer/deploy-ready/lhb-quartz/*
  530. # - docker restart nodeServer1
  531. - echo ====部署成功=======
  532. trigger:
  533. branch:
  534. include:
  535. - test-quartz
  536. event:
  537. include:
  538. - pull_request
  539. - push
  540. ############################################################################################
  541. ---
  542. kind: pipeline
  543. type: docker
  544. name: lhb-system-test
  545. volumes: # 声明数据卷
  546. - name: mvn_repo # 数据卷名称
  547. # Host Volume, 挂载到宿主机上的卷轴
  548. host:
  549. # 宿主机的绝对路径
  550. path: /home/ABServer/cache/mvn_repo
  551. - name: mvn_config
  552. host:
  553. path: /home/ABServer/config/mvn/
  554. - name: targetDir
  555. host:
  556. path: /lhb-system
  557. clone:
  558. disable: false # 启用代码拉取
  559. steps:
  560. - name: build-project
  561. image: maven:3.9.4-amazoncorretto-17
  562. pull: if-not-exists
  563. depends_on: [clone] # 依赖的步骤
  564. volumes: # 挂载数据卷
  565. - name: mvn_repo # 数据卷名称
  566. path: /usr/share/maven/repo # 容器内目录 绝对路径
  567. - name: targetDir
  568. path: /drone/src/lhb/dist/
  569. - name: mvn_config
  570. path: /usr/share/maven/conf/
  571. commands: # 执行命令
  572. - rm -rf /drone/src/lhb/dist/*
  573. - mvn clean package -Dmaven.test.skip=true -P test
  574. - cp /drone/src/lhb-system/lhb-system-biz/target/*.jar /drone/src/lhb/dist/ && cp -r /drone/src/lhb-system/lhb-system-biz/target/lib /drone/src/lhb/dist/ && cp -r /drone/src/lhb-system/lhb-system-biz/target/config /drone/src/lhb/dist/ # 复制文件
  575. when:
  576. status:
  577. - success # 当前步骤成功时执行
  578. - name: scp-project
  579. image: appleboy/drone-scp
  580. pull: if-not-exists
  581. depends_on: [build-project] # 依赖的步骤
  582. volumes: # 挂载数据卷
  583. - name: targetDir # 数据卷名称
  584. path: /lhb-system # 容器内目录 绝对路径
  585. settings:
  586. host:
  587. from_secret: host
  588. username:
  589. from_secret: username
  590. password:
  591. from_secret: userpwd
  592. port: 22
  593. command_timeout: 2m
  594. target: /home/ABServer/deploy-ready/
  595. source:
  596. - echo ====开始拷贝=======
  597. - /lhb-system/*.jar
  598. - /lhb-system/lib
  599. - /lhb-system/config
  600. - echo ====结束拷贝=======
  601. when:
  602. status:
  603. - success # 当前步骤成功时执行
  604. - name: deploy-project
  605. image: appleboy/drone-ssh
  606. pull: if-not-exists
  607. depends_on: [scp-project] # 依赖的步骤
  608. settings:
  609. host:
  610. from_secret: host
  611. username:
  612. from_secret: username
  613. password:
  614. from_secret: userpwd
  615. port: 22
  616. command_timeout: 2m
  617. script:
  618. - echo ====开始部署=======
  619. - cd /home/ABServer/
  620. - rm -rf /home/ABServer/webroot/lhb-system/*
  621. - cp -r /home/ABServer/deploy-ready/lhb-system /home/ABServer/webroot/
  622. - docker stop lhb-system && docker rm lhb-system && docker-compose up -d lhb-system
  623. - rm -rf /home/ABServer/deploy-ready/lhb-system/*
  624. # - docker restart nodeServer1
  625. - echo ====部署成功=======
  626. trigger:
  627. branch:
  628. include:
  629. - test-system
  630. event:
  631. include:
  632. - pull_request
  633. - push
  634. ############################################################################################
  635. ---
  636. kind: pipeline
  637. type: docker
  638. name: lhb-basic-test
  639. volumes: # 声明数据卷
  640. - name: mvn_repo # 数据卷名称
  641. # Host Volume, 挂载到宿主机上的卷轴
  642. host:
  643. # 宿主机的绝对路径
  644. path: /home/ABServer/cache/mvn_repo
  645. - name: mvn_config
  646. host:
  647. path: /home/ABServer/config/mvn/
  648. - name: targetDir
  649. host:
  650. path: /lhb-basic
  651. clone:
  652. disable: false # 启用代码拉取
  653. steps:
  654. - name: build-project
  655. image: maven:3.9.4-amazoncorretto-17
  656. pull: if-not-exists
  657. depends_on: [clone] # 依赖的步骤
  658. volumes: # 挂载数据卷
  659. - name: mvn_repo # 数据卷名称
  660. path: /usr/share/maven/repo # 容器内目录 绝对路径
  661. - name: targetDir
  662. path: /drone/src/lhb/dist/
  663. - name: mvn_config
  664. path: /usr/share/maven/conf/
  665. commands: # 执行命令
  666. - rm -rf /drone/src/lhb/dist/*
  667. - mvn clean package -Dmaven.test.skip=true -P test
  668. - cp /drone/src/lhb-basic/lhb-basic-biz/target/*.jar /drone/src/lhb/dist/ && cp -r /drone/src/lhb-basic/lhb-basic-biz/target/lib /drone/src/lhb/dist/ && cp -r /drone/src/lhb-basic/lhb-basic-biz/target/config /drone/src/lhb/dist/ # 复制文件
  669. when:
  670. status:
  671. - success # 当前步骤成功时执行
  672. - name: scp-project
  673. image: appleboy/drone-scp
  674. pull: if-not-exists
  675. depends_on: [build-project] # 依赖的步骤
  676. volumes: # 挂载数据卷
  677. - name: targetDir # 数据卷名称
  678. path: /lhb-basic # 容器内目录 绝对路径
  679. settings:
  680. host:
  681. from_secret: host
  682. username:
  683. from_secret: username
  684. password:
  685. from_secret: userpwd
  686. port: 22
  687. command_timeout: 2m
  688. target: /home/ABServer/deploy-ready/
  689. source:
  690. - echo ====开始拷贝=======
  691. - /lhb-basic/*.jar
  692. - /lhb-basic/lib
  693. - /lhb-basic/config
  694. - echo ====结束拷贝=======
  695. when:
  696. status:
  697. - success # 当前步骤成功时执行
  698. - name: deploy-project
  699. image: appleboy/drone-ssh
  700. pull: if-not-exists
  701. depends_on: [scp-project] # 依赖的步骤
  702. settings:
  703. host:
  704. from_secret: host
  705. username:
  706. from_secret: username
  707. password:
  708. from_secret: userpwd
  709. port: 22
  710. command_timeout: 2m
  711. script:
  712. - echo ====开始部署=======
  713. - cd /home/ABServer/
  714. - rm -rf /home/ABServer/webroot/lhb-basic/*
  715. - cp -r /home/ABServer/deploy-ready/lhb-basic /home/ABServer/webroot/
  716. - docker stop lhb-basic && docker rm lhb-basic && docker-compose up -d lhb-basic
  717. - rm -rf /home/ABServer/deploy-ready/lhb-basic/*
  718. # - docker restart nodeServer1
  719. - echo ====部署成功=======
  720. trigger:
  721. branch:
  722. include:
  723. - test-basic
  724. event:
  725. include:
  726. - pull_request
  727. - push