Drone自动部署配置文件
.drone.yml
点击查看代码
kind: pipeline # 定义对象类型,还有secret和signature两种类型
type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型
name: build # 定义流水线名称
volumes: # 定义流水线挂载目录,用于共享数据
- name: maven-build
host:
path: /usr/local/nginx/admin-system #jar包目录可以修改从宿主机中挂载的目录
- name: node_modules # 数据卷名称
host: # Host Volume
path: /usr/local/nginx/admin-system/admin/node_modules # 宿主机目录 #绝对路径
steps: # 定义流水线执行步骤,这些步骤将顺序执行
# admin_web-build
- name: web-build
image: node:14
volumes: # 挂载数据卷(此为容器内的目录)
- name: node_modules # 数据卷名称
path: /drone/src/mxy_ui/mxy_admin_web/node_modules # 容器内目录 绝对路径
commands:
- echo =======开始->构建admin-web包=======
- pwd
- cd /drone/src/mxy_ui/mxy_admin_web
- rm -rf package-lock.json
- npm config set registry https://registry.npm.taobao.org
- npm install
- npm run build
- echo =======开始构建blog-web包=======
- cd /drone/src/mxy_ui/mxy_blog_web
- rm -rf package-lock.json
- npm config set registry https://registry.npm.taobao.org
- npm install
- npm run build
- echo =======结束->构建admin-web包=======
# admin_system-package
- name: jar-build # 流水线名称
image: maven:3.8.5-openjdk-8 # 定义创建容器的Docker镜像
volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置
- name: maven-build
path: /usr/local/nginx/admin-system # 将应用打包好的Jar和执行脚本挂载出来
commands:
- echo =======1.开始->构建admin-system.jar包=======
- mvn clean package -DskipTests=true
- echo =======1.1.拷贝打包后的jar包到挂载目录=======
- cp /drone/src/mxy_business/mxy_system/target/mxy_system-0.0.1-SNAPSHOT.jar /usr/local/nginx/admin-system
- echo =======1.2.拷贝Dockerfile到挂载目录=======
- cp /drone/src/mxy_business/mxy_system/target/classes/Dockerfile /usr/local/nginx/admin-system
- echo =======1.3.拷贝service启动脚本到挂载目录=======
- cp /drone/src/mxy_business/mxy_system/target/classes/service.sh /usr/local/nginx/admin-system
- echo =======结束->构建admin-system.jar包=======
- echo =======2.开始->拷贝admin-web包=======
- echo =======2.1.备份原blog-web=======
- cp -r /usr/local/nginx/admin-system/blog/dist /usr/local/nginx/admin-system/blog/backup
- echo =======2.2.删除原blog-web=======
- rm -rf /usr/local/nginx/admin-system/blog/dist
- echo =======2.3.拷贝新blog-web=======
- cp -r /drone/src/mxy_ui/mxy_blog_web/dist /usr/local/nginx/admin-system/blog
- echo =======结束->拷贝admin-web包=======
- echo =======3.开始->拷贝blog-web包=======
- echo =======3.1.备份原admin-web=======
- cp -r /usr/local/nginx/admin-system/admin/dist /usr/local/nginx/admin-system/admin/backup
- echo =======3.2.删除原admin-web=======
- rm -rf /usr/local/nginx/admin-system/admin/dist
- echo =======3.3.拷贝新admin-web=======
- cp -r /drone/src/mxy_ui/mxy_admin_web/dist /usr/local/nginx/admin-system/admin
- echo =======结束->拷贝blog-web包=======
---
kind: pipeline # 定义对象类型,还有secret和signature两种类型
type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型
name: 部署 # 定义流水线名称
depends_on: # 依赖build管道
- build
clone:
disable: true # 禁用拉取
steps: # 定义流水线执行步骤,这些步骤将顺序执行
- name: ssh-start
image: appleboy/drone-ssh
settings:
# 你服务器ip地址,124.221.**.**
host:
from_secret: TEST_SERVER_IP
# 服务器账号
username: root
# 密码登入,M?Y@m^y******
password:
from_secret: TEST_SERVER_PASSWORD
port: 22
script:
- echo =======开始部署=======
- cd /usr/local/nginx/admin-system
- echo =======停止容器=======
# - docker stop mxy-system
- echo =======删除容器=======
# - docker rm mxy-system
- echo =======删除旧镜像=======
- docker rmi -f mxy-system:latest
- echo =======构建新镜像=======
- docker build -t mxy-system:latest .
- echo =======启动新容器=======
- docker run -p 8001:8001 -d mxy-system:latest
- echo =======停止服务=======
- ./service.sh stop
- echo =======启动服务=======
- ./service.sh start
- echo =======查看镜像列表=======
- docker images
- echo =======部署成功=======
- name: email
image: drillster/drone-email
settings:
host: smtp.qq.com
username: xxxx@qq.com
password: cdog********
from: xxxx@qq.com
recipients: [ 2533xxxx@qq.com ]