drone-start/.drone.yml

153 lines
4.6 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

kind: pipeline
type: docker
name: pipeline-example-maven
clone:
disable: true # 禁用自带的clone
steps:
- name: clone
image: alpine/git
commands:
- git clone http://119.91.218.235:3000/zeiss/drone-start.git .
- git checkout $DRONE_COMMIT
when:
event:
- push # 当代码 push 时才重新拉取
- name: Maven编译
image: maven:3.8-openjdk-8
volumes: # 将容器内目录挂载到宿主机仓库需要开启Trusted设置
- name: maven-cache
path: /root/.m2 # 将maven下载依赖的目录挂载出来防止重复下载
- name: maven-build
path: /app/build # 将应用打包好的Jar和执行脚本挂载出来
commands: # 定义在Docker容器中执行的shell命令
- mvn clean package # 应用打包命令
- rm -rf /app/build/*
- cp -r $PWD/**/**/*.jar /app/build
- cp -r $PWD/**/Dockerfile_* /app/build
- cp run.sh /app/build/run.sh
- pwd
- ls -l
- cd /app/build && ls -l
when:
event:
- push # 当代码 push 时才重新编译
- name: web-start 打包发布
image: appleboy/drone-ssh # SSH工具镜像
settings:
host: 119.91.218.235 # 远程连接地址
username: root # 远程连接账号
password:
from_secret: ssh_key # 从Secret中读取SSH密码
port: 22 # 远程连接端口
command_timeout: 5m # 远程执行命令超时时间
script:
- cd /root/opt/module/project/test # 进入宿主机构建目录
- chmod +x run.sh # 更改为可执行脚本
- ./run.sh "web-start" 8081 # 运行脚本打包应用镜像并运行
when:
event:
- promote
target:
- web-start
- name: web2-start scp 打包发布
pull: if-not-exists
image: appleboy/drone-ssh # SSH工具镜像
envs:
PRIVATE_SSH_KEY:
from_secret: ssh_pwd
settings:
host: 106.52.175.114 # 远程连接地址
username: root # 远程连接账号
password:
from_secret: ssh_key2 # 从Secret中读取SSH密码
port: 22 # 远程连接端口
command_timeout: 5m # 远程执行命令超时时间
script:
- cd /apps/project/ # 进入宿主机构建目录
- echo "------test1-----------"
- echo $PRIVATE_SSH_KEY
- echo $PRIVATE_SSH_KEY
- echo "-----test-------"
- sshpass -p "$PRIVATE_SSH_KEY" scp root@119.91.218.235:/root/opt/module/project/test/*.jar /apps/project/
- ls -l
when:
event:
- promote
target:
- web2-start # 判断promote 的 Target 参数 只有当相同时触发
- name: web3-start scp
image: kroniak/ssh-client
environment:
PRIVATE_SSH_KEY:
from_secret: ssh_key2
REMOTE_HOST: "root@106.52.175.114"
volumes:
- name: maven-build
path: /root/opt/module/project/test
commands:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- echo "$PRIVATE_SSH_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- scp -r $REMOTE_HOST:/apps/project/test/* /root/opt/module/project/test
- echo "scp -r $REMOTE_HOST:/apps/project/test/* /root/opt/module/project/test"
when:
event:
- promote
target:
- web3-start # 判断promote 的 Target 参数 只有当相同时触发
- name: scp files drone-scp
image: appleboy/drone-scp
settings:
host: 106.52.175.114
username: root
password:
from_secret: ssh_key3
port: 22
command_timeout: 1000m
script_stop: true
tar_tmp_path: /apps/tmp
target: /apps/project/test/
source: /app/build
when:
event:
- promote
target:
- web4-start # 判断promote 的 Target 参数 只有当相同时触发
- name: web-start5 打包发布
image: appleboy/drone-ssh # SSH工具镜像
settings:
host: 119.91.218.235 # 远程连接地址
username: root # 远程连接账号
password:
from_secret: ssh_key # 从Secret中读取SSH密码
port: 22 # 远程连接端口
command_timeout: 5m # 远程执行命令超时时间
script:
- tar -cvzf /tmp/test.tar.gz /app/build/*.jar
- pwd
- ls -l
when:
event:
- promote
target:
- web5-start
volumes: # 定义流水线挂载目录,用于共享数据
- name: maven-build
host:
path: /root/opt/module/project/test # 从宿主机中挂载的目录
- name: maven-cache
host:
path: /opt/module/maven