.drone.yml 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. kind: pipeline # 定义对象类型,还有secret和signature两种类型
  2. type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型
  3. name: drone-study # 定义流水线名称
  4. steps: # 定义流水线执行步骤,这些步骤将顺序执行
  5. - name: package # 1. 流水线名称(maven打包)
  6. pull: if-not-exists
  7. image: maven:ibmjava-alpine # 定义创建容器的Docker镜像
  8. volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
  9. - name: maven-cache
  10. path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载
  11. # 挂载宿主机的目录
  12. - name: maven-build
  13. path: /app/build/drone-study # 将应用打包好的Jar和执行脚本挂载出来
  14. commands: # 定义在Docker容器中执行的shell命令,这里是复制到maven镜像容器里面的,区分开项目就行了
  15. - mvn clean package -Dmaven.test.skip=true
  16. - cp target/drone.jar /app/build/drone-study/drone.jar
  17. - cp Dockerfile /app/build/drone-study/Dockerfile
  18. - cp run.sh /app/build/drone-study/run.sh
  19. - name: build-start # 2. 流水线名称(ssh默认人工操作打包好的jar包)
  20. image: appleboy/drone-ssh # ssh工具镜像
  21. # when:
  22. # branch:
  23. # include:
  24. # - master
  25. # exclude:
  26. # - dev
  27. settings:
  28. host: 123.60.43.219 # 远程连接地址,可以是IP可以是域名
  29. username: root # 远程连接账号
  30. password: Ab18315108835 #明文密码
  31. # password:
  32. # from_secret: ssh_password # 从Secret中读取SSH密码
  33. key:
  34. from_secret: ssh_key # 从Secret中读取SSH密钥
  35. port: 22 # 远程连接端口
  36. command_timeout: 10m # 远程执行命令超时时间
  37. script_stop: false # 设置为false,遇到第一次错误会继续运行后面的命令
  38. script:
  39. - cd /www/wwwroot/data/maven/build/drone-study # 进入宿主机构建目录,可根据自己选择目录
  40. - chmod +x run.sh # 更改为可执行脚本
  41. - ./run.sh # 运行脚本打包应用镜像并运行
  42. # - name: re-start
  43. # image: appleboy/drone-ssh
  44. # when:
  45. # branch:
  46. # include:
  47. # - dev
  48. # exclude:
  49. # - master
  50. # settings:
  51. # host: weiye.link
  52. # username: root
  53. # key:
  54. # from_secret: ssh_key
  55. # port: 22
  56. # command_timeout: 20m
  57. # script_stop: false
  58. # script:
  59. # - cd /www/wwwroot/data/maven/build/drone-study
  60. # - chmod +x restart.sh # 更改为可执行脚本
  61. # - ./restart.sh # 重启docker容器
  62. # - name: notify # 3. 通知(这里使用了钉钉通知,可以使用微信通知、邮件通知等)
  63. # pull: if-not-exists
  64. # image: guoxudongdocker/drone-dingtalk:latest
  65. # settings:
  66. # token:
  67. # from_secret: dingtalk_token
  68. # type: markdown
  69. # message_color: true
  70. # message_pic: true
  71. # sha_link: true
  72. # when:
  73. # status: [failure, success]
  74. volumes: # 定义流水线挂载目录,用于共享数据
  75. - name: maven-build
  76. host:
  77. path: /www/wwwroot/data/maven/build/drone-study # 从宿主机中挂载的目录
  78. - name: maven-cache
  79. host:
  80. path: /www/wwwroot/data/maven/cache