[ 项目 ] 修改CI CD流程 - 4

This commit is contained in:
zeaslity
2023-07-03 11:10:45 +08:00
parent bd63258c76
commit 129f388cfa
3 changed files with 101 additions and 18 deletions

View File

@@ -10,7 +10,7 @@ spring:
port: 20672
username: boge
password: boge8tingH
virtual-host: /wdd
virtual-host: /
listener:
simple:
retry:

View File

@@ -12,7 +12,7 @@ DependLibFiles=(
)
OctopusAgentUrl=https://happybirthday.107421.xyz/octopus-agent/
AgentConfigUrl=https://happybirthday.107421.xyz/agent-config/
RepoSourcePath=https://happybirthday.107421.xyz/shell
OctopusAgentPath=/octopus-agent/shell
##### environment variables ######
@@ -261,38 +261,61 @@ DownloadAllFile() {
}
#######################################
# description
# Globals:
# AgentConfigUrl
# BLUE
# GREEN
# LinuxRelease
# OctopusAgentUrl
# agentConfig
# agentConfigFileList
# Arguments:
# None
#######################################
CheckAndDownloadLatestVersion() {
FunctionStart
colorEcho $BLUE "checking for the latest version"
local latestVersion=$(curl $OctopusAgentUrl | grep -v h1 | grep "a href=" | head -1 | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4-)
rm -rf /octopus-agent/octopus-agent*
cd /octopus-agent
colorEcho $BLUE "start to download the latest version !"
# Agent二进制文件的命名规则为 octopus-agent_linux_amd64_<version>
local latestAgentVersion="octopus-agent_linux_${LinuxRelease}_${latestVersion}"
colorEcho $BLUE ""
colorEcho $BLUE "octopus agent latest version is => [ $latestAgentVersion ]"
colorEcho $BLUE ""
wget -q "$OctopusAgentUrl$latestAgentVersion"
cp "$latestAgentVersion" octopus-agent
chmod +x octopus-agent
echo ""
echo ""
colorEcho $GREEN "---------------- ls the /octopus-agent ----------------------"
ls /octopus-agent/ | grep octopus-agent
echo ""
colorEcho $BLUE "start to download the agent config!"
agentConfigFileList=$(curl $AgentConfigUrl | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4-)
for agentConfig in "${agentConfigFileList[@]}"; do
colorEcho $BLUE "agent config file is => $agentConfig"
wget -q "$AgentConfigUrl$agentConfig"
echo ""
done
echo ""
colorEcho $GREEN "---------------- ls the /octopus-agent ----------------------"
ls /octopus-agent/ | grep ".yaml"
echo ""
FunctionSuccess
FunctionEnd
}
#######################################
# description
# Globals:
@@ -391,7 +414,6 @@ ExecStop=/bin/kill -15 \$MAINPID
WantedBy=multi-user.target
EOF
colorEcho ${BLUE} "开始配置Agent日志输出文件"
# https://www.benzhu.xyz/linux12/
cat >/etc/rsyslog.d/octopus-agent.conf <<EOF
@@ -635,7 +657,7 @@ CleanOldOctopusAgent() {
colorEcho $BLUE "start to kill old octopus-agent"
agentPid=$(ps -ef | grep -v "color="| grep -c "octopus-agent")
agentPid=$(ps -ef | grep -v "color=" | grep -c "octopus-agent")
if [[ $agentPid -gt 0 ]]; then
colorEcho $BLUE "old agent existed ! start to kill"
colorEcho $BLUE "old agent existed ! start to kill"
@@ -645,9 +667,7 @@ CleanOldOctopusAgent() {
rm -rf /etc/systemd/system/octopus-agent.service
fi
FunctionSuccess
fi FunctionSuccess
FunctionEnd
}

View File

@@ -34,10 +34,14 @@ agentVersion=""
### tmp usage
ioavg=""
public_ipv4=""
inner_ipv4=""
public_ipv6=""
inner_ipv6=""
country=""
region=""
city=""
org=""
managePort=""
#### CollectSystemInfo ####
#######################################
@@ -140,6 +144,11 @@ StartIOTest() {
}
#######################################
# description
# Arguments:
# None
#######################################
GetAgentLatestVersion() {
ls /octopus-agent | grep "octopus-agent" | cut -d "-" -f3- | cut -d"." -f1
@@ -216,6 +225,15 @@ Check_Virtualization() {
virt="Dedicated"
fi
}
GetManagePort(){
tmpManagePorts=$(netstat -ntulp | grep sshd | grep -w tcp | grep -v "127.0.0.1"| awk '{print$4}' | cut -d":" -f2)
managePort=$(echo $tmpManagePorts | tr '\n' ' ')
log "manage Port is => $managePort"
}
#######################################
@@ -233,6 +251,7 @@ GetIpv4Info() {
log "start to get system public ip info !"
# public ip info
org="$(wget -q -T10 -O- ipinfo.io/org)"
city="$(wget -q -T10 -O- ipinfo.io/city)"
country="$(wget -q -T10 -O- ipinfo.io/country)"
@@ -240,6 +259,46 @@ GetIpv4Info() {
public_ipv4="$(wget -q -T10 -O- ipinfo.io/ip)"
public_ipv6="$(curl --max-time 5 -6 https://ifconfig.co/ip)"
if [ -z "$public_ipv4" ] ; then
public_ipv4=""
fi
if [ -z "$public_ipv6" ] ; then
public_ipv6=""
fi
if [ -z "$public_ipv4" ] ; then
public_ipv4=""
fi
# inner ipinfo
interface_prefix=(" eth[0-9]{1,2}" " ens[0-9]{1,3}" " eno[0-9]{1,3}" " enp[0-9]{1,2}")
real_interface="eth90"
for interface in "${interface_prefix[@]}"; do
echo $(ip link show) | grep -oE ${interface}
if [[ $? -eq 0 ]]; then
real_interface=$(echo $(ip link show) | grep -oE ${interface} | cut -d" " -f2)
echo "当前主机的真实内网网卡为 => $real_interface"
return
fi
done
# 提取IPv4地址CIDR格式
ipv4_regex="inet (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[0-9]{1,2}"
# 提取IPv6地址CIDR格式
ipv6_regex="inet6 ([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,7})\/[0-9]{1,3}"
# 查找IPv4地址
inner_ipv4=$(echo $(ip addr show $real_interface) | grep -oE $ipv4_regex | cut -d" " -f2)
echo "Interface: $interface, IPv4 Address: $inner_ipv4"
# 查找IPv6地址
inner_ipv6=$(echo $(ip addr show $real_interface) | grep -oE $ipv6_regex | cut -d" " -f2)
echo "Interface: $interface, IPv4 Address: $inner_ipv6"
}
log "start to collect system info !"
@@ -307,6 +366,8 @@ tcpctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}')
# todo
# StartIOTest
GetManagePort
GetIpv4Info
Check_Virtualization
@@ -318,16 +379,18 @@ if [[ $(cat /etc/hostname | cut -d"-" -f 3 | grep -c '^[0-9][0-9]') -gt 0 ]]; th
else
machineNumber=99
fi
agentServerInfoFile="/octopus-agent/octopus-agent.conf "
#cat >/etc/environment.d/octopus-agent.conf <<EOF
cat >/octopus-agent/octopus-agent.conf <<EOF
cat >"$agentServerInfoFile"<<EOF
serverName: ${city}-${hostArch}-${machineNumber}
serverIpPbV4: $public_ipv4
serverIpInV4:
serverIpInV4: $inner_ipv4
serverIpPbV6: $public_ipv6
serverIpInV6:
serverIpInV6: $inner_ipv6
location: "$city $region $country"
provider: $org
managePort: $(netstat -ntulp | grep sshd | grep -w tcp | awk '{print$4}' | cut -d":" -f2)
managePort: $managePort
cpuCore: "$cores @ $freq MHz"
cpuBrand: "$cpuName"
memoryTotal: $tram
@@ -340,8 +403,8 @@ tcpControl: $tcpctrl
virtualization: $virt
ioSpeed: "$ioavg MB/s"
machineId: $(cat /etc/machine-id)
agentVersion: $(ls /octopus-agent | grep "octopus-agent" | cut -d "-" -f4-)
agentVersion: $(ls /octopus-agent | grep "octopus-agent_" | cut -d "_" -f4-)
EOF
log "agent server info has collect complete!"
log "file is => /octopus-agent/octopus-agent.conf"
log "file is => $agentServerInfoFile"