Merge pull request 'feat(cd) add drone' (#3) from master into test
continuous-integration/drone/push Build encountered an error Details
continuous-integration/drone/pr Build encountered an error Details

Reviewed-on: #3
test
bob 2 years ago
commit e617c01a24

@ -0,0 +1,45 @@
kind: pipeline # 定义对象类型还有secret和signature两种类型
type: docker # 定义流水线类型还有kubernetes、exec、ssh等类型
name: jar-deploy # 定义流水线名称
node:
name: centos-runner
steps: # 定义流水线执行步骤,这些步骤将顺序执行
- name: build-package # 流水线名称
image: maven:3.8-openjdk-11 # 定义创建容器的Docker镜像
volumes: # 将容器内目录挂载到宿主机仓库需要开启Trusted设置
- name: maven-cache
path: /root/.m2 # 将maven下载依赖的目录挂载出来防止重复下载
- name: maven-build
path: /app/build # 将应用打包好的Jar和执行脚本挂载出来
commands: # 定义在Docker容器中执行的shell命令
- mvn -T 8 clean package -Dmaven.test.skip=true -pl ruoyi-admin -am # 应用打包命令
- cp target/*.jar /app/build/
- cp ruoyi-admin/Dockerfile /app/build/Dockerfile
- cp run.sh /app/build/run.sh
- name: deploy-start
image: appleboy/drone-ssh # SSH工具镜像
settings:
host: 49.232.170.154 # 远程连接地址
username: root # 远程连接账号
password:
from_secret: ssh_password # 从Secret中读取SSH密码
port: 22 # 远程连接端口
command_timeout: 5m # 远程执行命令超时时间
script:
- cd /app/build # 进入宿主机构建目录
- chmod +x run.sh # 更改为可执行脚本
- ./run.sh # 运行脚本打包应用镜像并运行
volumes: # 定义流水线挂载目录,用于共享数据
- name: maven-build
host:
path: /app/build # 从宿主机中挂载的目录
- name: maven-cache
host:
path: /app/maven/cache
# drone执行触发器
trigger:g
branch:
- test

@ -0,0 +1,12 @@
#!/bin/bash
# 打包编译docker镜像
echo '----build image----start'
docker build -t ruoyi-admin .
echo '----build image----end'
echo '----cd /opt/composes/ruoyi-admin----'
cd /opt/composes/ruoyi-admin
echo '----restart container----'
docker compose up -d
echo '----start container----'

86
ry.sh

@ -1,86 +0,0 @@
#!/bin/bash
AppName=ruoyi-admin.jar
#JVM参数
JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
APP_HOME=`pwd`
LOG_PATH=$APP_HOME/logs/$AppName.log
if [ "$1" = "" ];
then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m"
exit 1
fi
if [ "$AppName" = "" ];
then
echo -e "\033[0;31m 未输入应用名 \033[0m"
exit 1
fi
function start()
{
PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
if [ x"$PID" != x"" ]; then
echo "$AppName is running..."
else
nohup java -jar $JVM_OPTS target/$AppName > /dev/null 2>&1 &
echo "Start $AppName success..."
fi
}
function stop()
{
echo "Stop $AppName"
PID=""
query(){
PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'`
}
query
if [ x"$PID" != x"" ]; then
kill -TERM $PID
echo "$AppName (pid:$PID) exiting..."
while [ x"$PID" != x"" ]
do
sleep 1
query
done
echo "$AppName exited."
else
echo "$AppName already stopped."
fi
}
function restart()
{
stop
sleep 2
start
}
function status()
{
PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l`
if [ $PID != 0 ];then
echo "$AppName is running..."
else
echo "$AppName is not running..."
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
esac
Loading…
Cancel
Save