Commit 95139855 authored by “李磊”'s avatar “李磊”
Browse files

feat: 支持makefile

parent 89455b57
.pre-build:
mkdir -p bin/
# all=表示对所有go包应用后面的表示标志
# -N 禁用优化
# -l 禁用内联
# -ldflags 用来设置链接器的标志
# -X 在编译时设置包中的变量的值
build: .pre-build
go build -gcflags='all=-N -l' -ldflags "-X agent/cmd/agent/config.Version=`./branch_info.sh get_version` -X agent/cmd/agent/config.BuildCommit=`git rev-list -1 HEAD`" -o bin/linkfog_agent ./cmd/agent
bin/linkfog_agent -v | tee version
#!/bin/bash
branch=`git branch --show-current`
if [ -n "$BRANCH_NAME" ]; then # 通过环境变量传入
branch=$BRANCH_NAME
fi
version=$branch-`date +%Y-%m-%d-%H`
spcode=""
if [[ $branch =~ ^release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then # match release/5.1.3
version=${BASH_REMATCH[1]}
elif [[ $branch =~ ^(sp[0-9]+)/release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then # match sp96/release/5.2.0
spcode=${BASH_REMATCH[1]}
version=${BASH_REMATCH[2]}
else
version=`echo "$version" | sed 's#/#-#g;s#%2F#-#g'`
fi
case "$1" in
get_version)
echo $version
;;
get_spcode)
echo $spcode
;;
*)
if [ -z "$1" ]; then
echo "version: $version"
echo "spcode: $spcode"
else
echo "usage: $0 [get_version|get_spcode]"
fi
;;
esac
...@@ -14,6 +14,7 @@ var ( ...@@ -14,6 +14,7 @@ var (
PluginDir = WorkDir + "/plugin" PluginDir = WorkDir + "/plugin"
Version = ""
BuildCommit = "" BuildCommit = ""
MonitorLogUnModDuration = 600 * time.Second MonitorLogUnModDuration = 600 * time.Second
......
...@@ -54,7 +54,7 @@ func (a *Agent) Start() error { ...@@ -54,7 +54,7 @@ func (a *Agent) Start() error {
if option.Opt.EnableMonitorDaemon { if option.Opt.EnableMonitorDaemon {
l.Info("======start monitor_daemon======") l.Info("======start monitor_daemon======")
param := fmt.Sprintf("%s=false", option.ArgEnableMonitorDaemon) param := fmt.Sprintf("-%s=false", option.ArgEnableMonitorDaemon)
cmdline := strings.Replace( cmdline := strings.Replace(
strings.Join(append(os.Args, param), " "), "", "", -1) strings.Join(append(os.Args, param), " "), "", "", -1)
opts := []monitor_daemon.MonitorDaemonOpt{ opts := []monitor_daemon.MonitorDaemonOpt{
...@@ -109,8 +109,10 @@ func (a *Agent) Stop() error { ...@@ -109,8 +109,10 @@ func (a *Agent) Stop() error {
} }
func genVersion() string { func genVersion() string {
if len(config.BuildCommit) > 5 {
return "" return fmt.Sprintf("%s_%s", config.Version, config.BuildCommit[:6])
}
return fmt.Sprintf("%s_%s", config.Version, config.BuildCommit)
} }
func initSvcCfg() error { func initSvcCfg() error {
......
...@@ -2,7 +2,7 @@ module agent ...@@ -2,7 +2,7 @@ module agent
go 1.23.2 go 1.23.2
replace linkfog.com/public => web.lueluesay.top/git/lil/public v0.0.0-20241014113926-be062ca04146 replace linkfog.com/public => web.lueluesay.top/git/lil/public v0.0.0-20241014123850-a3280358a869
replace linkfog.com/pluginx => web.lueluesay.top/git/lil/pluginx v0.0.0-20241014064823-a6e286ccb5cd replace linkfog.com/pluginx => web.lueluesay.top/git/lil/pluginx v0.0.0-20241014064823-a6e286ccb5cd
......
...@@ -53,5 +53,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= ...@@ -53,5 +53,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
web.lueluesay.top/git/lil/pluginx v0.0.0-20241014064823-a6e286ccb5cd h1:KaqJZ9MQkJ2mQDHXe9pm5MIgW5xpzNekj4OYSYn4cR4= web.lueluesay.top/git/lil/pluginx v0.0.0-20241014064823-a6e286ccb5cd h1:KaqJZ9MQkJ2mQDHXe9pm5MIgW5xpzNekj4OYSYn4cR4=
web.lueluesay.top/git/lil/pluginx v0.0.0-20241014064823-a6e286ccb5cd/go.mod h1:DL73qsfCIFfH2K6tdOLPj9tRcZ8AYxfPrkcTebYXr5o= web.lueluesay.top/git/lil/pluginx v0.0.0-20241014064823-a6e286ccb5cd/go.mod h1:DL73qsfCIFfH2K6tdOLPj9tRcZ8AYxfPrkcTebYXr5o=
web.lueluesay.top/git/lil/public v0.0.0-20241014113926-be062ca04146 h1:Y9ZcWzfBrrRlS8LS/XkwURMeUfjGPQkjiokK6YG+2wI= web.lueluesay.top/git/lil/public v0.0.0-20241014123850-a3280358a869 h1:I/NVw5BkrtHBtUaEgd365Km8iSK/xkk28KMmbYmkFN4=
web.lueluesay.top/git/lil/public v0.0.0-20241014113926-be062ca04146/go.mod h1:x/nRP9pMRVToI9Te1TazybP0Qlj3V+/aA2EiPQEvzsI= web.lueluesay.top/git/lil/public v0.0.0-20241014123850-a3280358a869/go.mod h1:x/nRP9pMRVToI9Te1TazybP0Qlj3V+/aA2EiPQEvzsI=
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment