63 lines
1.7 KiB
YAML
63 lines
1.7 KiB
YAML
kind: pipeline
|
||
type: docker
|
||
name: myProject
|
||
|
||
steps:
|
||
# 1.maven打包
|
||
- name: maven compile
|
||
pull: if-not-exists
|
||
# 构建镜像的maven+jdk选择,最好选择满足匹配你的项目版本的
|
||
image: matderosa/maven-3.8-openjdk-17-gcc8.5
|
||
volumes:
|
||
# maven构建缓存
|
||
- name: maven-cache
|
||
path: /root/.m2
|
||
# 挂载宿主机的目录
|
||
- name: maven-build
|
||
path: /demo/build
|
||
commands:
|
||
# 开始打包maven工程
|
||
- mvn clean package -Dmaven.test.skip=true
|
||
# 将打包后的文件复制到宿主机映射目录
|
||
- pwd
|
||
- ls -l
|
||
- cp target/*.jar /demo/build
|
||
- cp Dockerfile /demo/build
|
||
- cp start.sh /demo/build
|
||
- ls /demo/build
|
||
|
||
- name: deploy-start
|
||
pull: if-not-exists
|
||
image: appleboy/drone-ssh # SSH工具镜像
|
||
settings:
|
||
host: 106.52.175.114 # 远程连接地址
|
||
username: root # 远程连接账号
|
||
password:
|
||
from_secret: ssh_password # 从Secret中读取SSH密码
|
||
port: 22 # 远程连接端口
|
||
command_timeout: 5m # 远程执行命令超时时间
|
||
script:
|
||
- cd /demo/build # 进入宿主机构建目录
|
||
- chmod +x start.sh # 更改为可执行脚本
|
||
- ./start.sh # 运行脚本打包应用镜像并运行
|
||
when:
|
||
event:
|
||
- promote
|
||
|
||
volumes: # 定义流水线挂载目录,用于共享数据
|
||
- name: maven-build
|
||
host:
|
||
path: /home/projects/demo/maven/build # 从宿主机中挂载的目录
|
||
- name: maven-cache
|
||
host:
|
||
path: /home/projects/demo/maven/cache
|
||
- name: docker
|
||
host:
|
||
path: /var/run/docker.sock
|
||
|
||
|
||
# drone执行触发器
|
||
trigger:
|
||
branch:
|
||
- main
|