【Shell】SpringCloud自动构建运行maven+git
概述
可使用自动构建部署可视化平台,本篇仅提供shell方式
目录结构
-deploy.sh //下面的脚本
-shell
-脚本把jar拷贝出来到这
-jar包运行的脚本在shell中配置shell_path会在脚本最后执行
-项目名字(project_name)
-pom.xml
-...
shell
Windows写完放到Linux出现"xxx.sh /bin/bash^M: 坏的解释器:没有那个文件或目录”
sed -i ‘s/\r$//’ xxx.sh
#! /bin/bash
# git下载后文件名
project_name="project_test"
# 运行jar包脚本,一般直接放在该脚本同目录的shell文件夹中,最终所有jar包会移动到该目录下
shell_path="/opt/run.sh"
# git ssh项目地址
giturl="git@codeup.aliyun.com:。。。.git"
# 分支
branch="master"
if [ ! -d "./shell" ]; then
mkdir shell
fi
# git拉取
if [ -d "./$project_name" ]; then
echo "git fetch"
cd $project_name
git fetch origin $branch
else
echo "git clone"
git clone -b $branch $giturl
cd $project_name
fi
# 复制.jar文件到./shell
mvn package -f ./pom.xml
echo "maven package jar finish"
if [ ! -d "./jar-package" ]; then
mkdir jar-package
fi
shopt -s globstar
for file in **/*.jar; do
if [[ "$file" != *"SNAPSHOT"* ]]; then
mv "$file" "./jar-package"
fi
done
rm -rf ./shell/*.jar
mv ./jar-package/* ../shell
cd ../shell
echo "jar merge to ./shell,running...."
# shell启动.jar文件
sh $shell_path
前端
wget https://nodejs.org/dist/v16.4.2/node-v16.4.2-linux-x64.tar.gz
tar -xvf node-v16.4.2-linux-x64.tar.gz
mkdir -p /usr/local/nodejs
# 建立node软链接
ln -s /usr/local/nodejs/bin/node /usr/local/bin
# 建立npm 软链接
ln -s /usr/local/nodejs/bin/npm /usr/local/bin
# 设置国内淘宝镜像源
npm config set registry https://registry.npm.taobao.org
# 查看设置信息
npm config list
#! /bin/bash
# git下载后文件名
project_name=""
# git ssh下载地址
giturl="git@codeup.aliyun.com:.git"
# 分支
branch="master"
# npm打包后文件名
vue_output_name="vue-out"
# 打包文件放置路径一般为nginx的html路径
deploy_path="/usr/local/nginx/html"
# 打包代码
build_sh="npm run build:production"
if [ -d "./$project_name" ]; then
echo "git fetch"
cd $project_name
git fetch origin $branch
else
echo "git clone"
git clone -b $branch $giturl
cd $project_name
fi
# npm install
$build_sh
if [ -d "$deploy_path/$vue_output_name" ]; then
echo "rm old file"
rm -rf $deploy_path/$vue_output_name
fi
mv $vue_output_name $deploy_path
安装Node和Maven
#!/bin/bash
# define
mvn_install(){
if [ ! -d "/usr/local/apache-maven-3.8.8-bin" ]; then
echo "apache_maven_install..."
wget https://mirrors.aliyun.com/apache/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz
tar -xvf apache-maven-3.8.8-bin.tar.gz -C /usr/local/
rm -rf apache-maven-3.8.8-bin.tar.gz
echo 'MAVEN_HOME=/usr/local/apache-maven-3.8.8-bin' >> /etc/profile
echo 'export PATH=${MAVEN_HOME}/bin:${PATH}' >> /etc/profile
source /etc/profile
echo "apache_maven_install success"
else
echo "error:apache-maven-3.8.8-bin.tar.gz has been exist"
exit 1
fi
}
node_install(){
if [ ! -d "/usr/local/node" ]; then
echo "node_install..."
wget https://mirrors.aliyun.com/nodejs-release/v16.4.2/node-v16.4.2-linux-x64.tar.gz
tar -xvf node-v16.4.2-linux-x64.tar.gz -C /usr/local/
mv /usr/local/node-v16.4.2-linux-x64 /usr/local/node
rm -rf node-v16.4.2-linux-x64
rm -rf node-v16.4.2-linux-x64.tar.gz
echo 'NODEJS_HOME=/usr/local/node' >> /etc/profile
echo 'export PATH=$NODEJS_HOME/bin:${PATH}' >> /etc/profile
source /etc/profile
echo "node_install success"
else
echo "error:/usr/local/node has been exist"
exit 1
fi
}
ssh_key_install(){
if [ ! -f "~/.ssh/id_rsa.pub" ]; then
echo "git rsa ssh command below:"
echo 'ssh-keygen -t rsa -C "your email"'
else
echo "ssh pub key exist"
fi
}
# install maven
if command -v which mvn >/dev/null 2>&1 && which mvn >/dev/null 2>&1; then
echo "mvn exist"
else
echo "warn:mvn not exist"
mvn_install
fi
# install node
if command -v which node >/dev/null 2>&1 && which node >/dev/null 2>&1; then
echo "node exist"
else
echo "warn:node not exist"
node_install
fi
# git
if command -v which git >/dev/null 2>&1 && which git >/dev/null 2>&1; then
echo "git exist"
ssh_key_install
else
echo "warn:git not exist,need to install"
exit 1
fi
原文地址:https://blog.csdn.net/qq_45742250/article/details/135365631
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!