实现内网环境Linux部署JPom代替Jenkins构建和推送镜像并发布
1. 准备一个干净的Linux(CentOS、Ubantu)系统(如果自己能预装docker、java、maven、node最好)
这次JPom的部署我们就直接使用Linux安装而非Docker安装 考虑到有的项目环境是纯内网环境
1.1 安装 java maven node
官网的安装文档 https://jpom.top/pages/db3065/
一般公司都需要指定具体的版本 比如我们现在java用的就是 corretto-11 node用的是14.17.1 所以我直接修改了install.sh 指定了使用(可以替换成自己的)
- linux-corretto-jdk-11.tar.gz
- linux-maven-3.9.6-nexus.tar.gz
- linux-node-14.17.1-x64.tar.gz
使用bash install.sh 执行
#!/bin/bash
command_exists() {
command -v "$@" >/dev/null 2>&1
}
function checkCommand() {
command=$(which "$1")
if [[ ! -x "$command" ]]; then
if command_exists "$1"; then
echo "$1"
else
echo "not found"
fi
else
echo "$command"
fi
}
function mustMkdir() {
dir="$1"
mkdir -p "$dir"
if [ ! -d "$dir" ]; then
echo "ERROR: 目录创建失败: $dir"
fi
echo "$dir"
}
function findProfile() {
user="$(id -un 2>/dev/null || true)"
profileName=""
if [ "$user" != 'root' ]; then
array=("$HOME/.bash_profile" "$HOME/.bashrc" "$HOME/.bash_login")
for element in "${array[@]}"; do
if [ -f "$element" ]; then
profileName=$element
break
fi
done
if [ -z "$profileName" ]; then
cat >&2 <<-EOF
ERROR: 没有找到可用的环境变量文件
EOF
exit 1
fi
else
profileName="/etc/profile"
fi
echo "$profileName"
}
# 安装 jdk
function installJdkFn() {
javaCommand=$(checkCommand java)
if [[ "$javaCommand" == "not found" ]]; then
echo "不存在 java 环境,开始尝试安装"
useDir=$(mustMkdir /usr/java)
userProfileName=$(findProfile)
if grep -q "CLASSPATH" "$userProfileName"; then
echo