.drone.yml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. kind: pipeline
  2. type: docker
  3. name: pipeline-example-maven
  4. trigger:
  5. branch:
  6. - develop
  7. clone:
  8. disable: true # 禁用自带的clone
  9. # clone代码
  10. steps:
  11. - name: clone
  12. image: alpine/git
  13. volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
  14. - name: host-mount
  15. path: /data # 将maven下载依赖的目录挂载出来,防止重复下载
  16. commands:
  17. - git clone http://124.222.247.184:3000/root/courtBooking.git
  18. # 把这里改成了自己的仓库地址
  19. # http://124.222.247.184:3000/wteamYD/promotesai-background.git .
  20. - git checkout develop
  21. - cp *.sh /data
  22. when:
  23. event:
  24. - push # 当代码 push 时才重新拉取
  25. # 传输shell脚本到目标主机
  26. - name: scp files
  27. image: ryjer/drone-scp
  28. volumes: #将主机的shell脚本与容器共享
  29. - name: host-mount
  30. path: /data
  31. settings:
  32. host: 42.194.177.220
  33. username: root
  34. password:
  35. from_secret: 42.194.177.220_password # 从Secret中读取SSH密码
  36. port: 22
  37. rm: true
  38. source:
  39. - /data
  40. target:
  41. - /data/sh/
  42. environment:
  43. AUTO_CREATE_DIR: "true" # 自动创建目标目录
  44. when:
  45. event:
  46. - push # 当代码 push 时才重新上传
  47. # 启动shell脚本
  48. - name: spring-start 部署并重启
  49. image: appleboy/drone-ssh # SSH工具镜像
  50. settings:
  51. host: 42.194.177.220 # 远程连接地址
  52. username: root # 远程连接账号
  53. password:
  54. from_secret: 42.194.177.220_password # 从Secret中读取SSH密码
  55. port: 22 # 远程连接端口
  56. command_timeout: 5m # 远程执行命令超时时间
  57. script:
  58. - cd /data/sh # 进入宿主机构建目录
  59. - chmod +x develop.sh # 更改为可执行脚本
  60. - ./develop.sh # 运行脚本打包应用镜像并运行
  61. when:
  62. event:
  63. - push # 当代码 push 时才重新上传
  64. volumes: # 定义流水线挂载目录,用于共享shell脚本
  65. - name: host-mount
  66. host:
  67. path: /mydata/sh/ # 从宿主机中挂载的目录