Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Tencent/bk-ci into issue5…
Browse files Browse the repository at this point in the history
…640_github_branch
  • Loading branch information
sawyersong2 committed Dec 1, 2021
2 parents de4617d + 734d015 commit 063d1ef
Show file tree
Hide file tree
Showing 151 changed files with 4,986 additions and 470 deletions.
20 changes: 20 additions & 0 deletions src/agent/build_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,23 @@ go build -o %WORK_DIR%\bin\upgrader.exe %WORK_DIR%\src\cmd\upgrader

go build -o %WORK_DIR%\bin\installer.exe %WORK_DIR%\src\cmd\installer


if not exist %WORK_DIR%\bin\devopsDaemon.exe (
echo "can not find %WORK_DIR%\bin\devopsDaemon.exe"
exit 1
)

if not exist %WORK_DIR%\bin\devopsAgent.exe (
echo "can not find %WORK_DIR%\bin\devopsAgent.exe"
exit 1
)

if not exist %WORK_DIR%\bin\upgrader.exe (
echo "can not find %WORK_DIR%\bin\upgrader.exe"
exit 1
)

if not exist %WORK_DIR%\bin\installer.exe (
echo "can not find %WORK_DIR%\bin\installer.exe"
exit 1
)
5 changes: 5 additions & 0 deletions src/agent/src/cmd/daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ const (
)

func main() {
if len(os.Args) == 2 && os.Args[1] == "version" {
fmt.Println(config.AgentVersion)
systemutil.ExitProcess(0)
}

runtime.GOMAXPROCS(4)

workDir := systemutil.GetExecutableDir()
Expand Down
6 changes: 6 additions & 0 deletions src/agent/src/cmd/daemon/main_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
package main

import (
"fmt"
"encoding/json"
"os"
"os/exec"
"runtime"
"time"

"github.com/Tencent/bk-ci/src/agent/src/pkg/config"
"github.com/Tencent/bk-ci/src/agent/src/pkg/util/fileutil"
"github.com/Tencent/bk-ci/src/agent/src/pkg/util/systemutil"
"github.com/astaxie/beego/logs"
Expand All @@ -44,6 +46,10 @@ import (
const daemonProcess = "daemon"

func main() {
if len(os.Args) == 2 && os.Args[1] == "version" {
fmt.Println(config.AgentVersion)
systemutil.ExitProcess(0)
}
runtime.GOMAXPROCS(4)

workDir := systemutil.GetExecutableDir()
Expand Down
2 changes: 1 addition & 1 deletion src/agent/src/pkg/config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@

package config

const AgentVersion = "v1.7.0"
const AgentVersion = "v1.7.20"
24 changes: 12 additions & 12 deletions src/agent/src/pkg/upgrade/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func UninstallAgent() {
}

func runUpgrader(action string) error {
logs.Info("start upgrader process")
logs.Info("[agentUpgrade]|start upgrader process")

scripPath := systemutil.GetUpgradeDir() + "/" + config.GetClientUpgraderFile()

if !systemutil.IsWindows() {
err := os.Chmod(scripPath, 0777)
if err != nil {
logs.Error("chmod failed: ", err.Error())
logs.Error("[agentUpgrade]|chmod failed: ", err.Error())
return errors.New("chmod failed: ")
}
}
Expand All @@ -70,52 +70,52 @@ func runUpgrader(action string) error {

pid, err := command.StartProcess(scripPath, args, systemutil.GetWorkDir(), nil, "")
if err != nil {
logs.Error("run upgrader failed: ", err.Error())
logs.Error("[agentUpgrade]|run upgrader failed: ", err.Error())
return errors.New("run upgrader failed")
}
logs.Info("start process success, pid: ", pid)
logs.Info("[agentUpgrade]|start process success, pid: ", pid)

logs.Warning("agent process exiting")
logs.Warning("[agentUpgrade]|agent process exiting")
systemutil.ExitProcess(0)
return nil
}

func DoUpgradeOperation(agentChanged bool, workAgentChanged bool) error {
logs.Info("start upgrade, agent changed: ", agentChanged, ", work agent changed: ", workAgentChanged)
logs.Info("[agentUpgrade]|start upgrade, agent changed: ", agentChanged, ", work agent changed: ", workAgentChanged)
config.GIsAgentUpgrading = true
defer func() {
config.GIsAgentUpgrading = false
api.FinishUpgrade(true)
}()

if !agentChanged && !workAgentChanged {
logs.Info("no change to upgrade, skip")
logs.Info("[agentUpgrade]|no change to upgrade, skip")
return nil
}

if workAgentChanged {
logs.Info("work agent changed, replace work agent file")
logs.Info("[agentUpgrade]|work agent changed, replace work agent file")
_, err := fileutil.CopyFile(
systemutil.GetUpgradeDir()+"/"+config.WorkAgentFile,
systemutil.GetWorkDir()+"/"+config.WorkAgentFile,
true)
if err != nil {
logs.Error("replace work agent file failed: ", err.Error())
logs.Error("[agentUpgrade]|replace work agent file failed: ", err.Error())
return errors.New("replace work agent file failed")
}
logs.Info("relace agent file done")
logs.Info("[agentUpgrade]|relace agent file done")

config.GAgentEnv.SlaveVersion = config.DetectWorkerVersion()
}

if agentChanged {
logs.Info("agent changed, start upgrader")
logs.Info("[agentUpgrade]|agent changed, start upgrader")
err := runUpgrader(config.ActionUpgrade)
if err != nil {
return err
}
} else {
logs.Info("agent not changed, skip agent upgrade")
logs.Info("[agentUpgrade]|agent not changed, skip agent upgrade")
}
return nil
}
46 changes: 23 additions & 23 deletions src/agent/src/pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ func DoPollAndUpgradeAgent() {
func agentUpgrade() {
checkResult, err := api.CheckUpgrade()
if err != nil {
logs.Error("check upgrade err: ", err.Error())
logs.Error("[agentUpgrade]|check upgrade err: ", err.Error())
return
}
if !checkResult.IsOk() {
logs.Error("check upgrade failed: ", checkResult.Message)
logs.Error("[agentUpgrade]|check upgrade failed: ", checkResult.Message)
return
}

if checkResult.IsAgentDelete() {
logs.Info("agent is deleted, skip")
logs.Info("[agentUpgrade]|agent is deleted, skip")
return
}

if !(checkResult.Data).(bool) {
logs.Info("no need to upgrade agent, skip")
logs.Info("[agentUpgrade]|no need to upgrade agent, skip")
return
}

logs.Info("download upgrade files start")
logs.Info("[agentUpgrade]|download upgrade files start")
agentChanged, workerChanged, err := downloadUpgradeFiles()
if err != nil {
logs.Error("download upgrade files failed", err.Error())
logs.Error("[agentUpgrade]|download upgrade files failed", err.Error())
return
}
logs.Info("download upgrade files done")
logs.Info("[agentUpgrade]|download upgrade files done")

err = DoUpgradeOperation(agentChanged, workerChanged)
if err != nil {
logs.Error("do upgrade operation failed", err)
logs.Error("[agentUpgrade]|do upgrade operation failed", err)
}
}

Expand All @@ -87,51 +87,51 @@ func downloadUpgradeFiles() (agentChanged bool, workAgentChanged bool, err error
upgradeDir := systemutil.GetUpgradeDir()
os.MkdirAll(upgradeDir, os.ModePerm)

logs.Info("download upgrader start")
logs.Info("[agentUpgrade]|download upgrader start")
_, err = api.DownloadUpgradeFile("upgrade/"+config.GetServerUpgraderFile(), upgradeDir+"/"+config.GetClientUpgraderFile())
if err != nil {
logs.Error("download upgrader failed", err)
logs.Error("[agentUpgrade]|download upgrader failed", err)
return false, false, errors.New("download upgrader failed")
}
logs.Info("download upgrader done")
logs.Info("[agentUpgrade]|download upgrader done")

logs.Info("download daemon start")
logs.Info("[agentUpgrade]|download daemon start")
newDaemonMd5, err := api.DownloadUpgradeFile("upgrade/"+config.GetServerDaemonFile(), upgradeDir+"/"+config.GetClientDaemonFile())
if err != nil {
logs.Error("download daemon failed", err)
logs.Error("[agentUpgrade]|download daemon failed", err)
return false, false, errors.New("download daemon failed")
}
logs.Info("download daemon done")
logs.Info("[agentUpgrade]|download daemon done")

logs.Info("download agent start")
logs.Info("[agentUpgrade]|download agent start")
newAgentMd5, err := api.DownloadUpgradeFile("upgrade/"+config.GetServerAgentFile(), upgradeDir+"/"+config.GetClienAgentFile())
if err != nil {
logs.Error("download agent failed", err)
logs.Error("[agentUpgrade]|download agent failed", err)
return false, false, errors.New("download agent failed")
}
logs.Info("download agent done")
logs.Info("[agentUpgrade]|download agent done")

logs.Info("download worker start")
logs.Info("[agentUpgrade]|download worker start")
newWorkerMd5, err := api.DownloadUpgradeFile("jar/"+config.WorkAgentFile, upgradeDir+"/"+config.WorkAgentFile)
if err != nil {
logs.Error("download worker failed", err)
logs.Error("[agentUpgrade]|download worker failed", err)
return false, false, errors.New("download worker failed")
}
logs.Info("download worker done")
logs.Info("[agentUpgrade]|download worker done")

daemonMd5, err := fileutil.GetFileMd5(workDir + "/" + config.GetClientDaemonFile())
if err != nil {
logs.Error("check daemon md5 failed", err)
logs.Error("[agentUpgrade]|check daemon md5 failed", err)
return false, false, errors.New("check daemon md5 failed")
}
agentMd5, err := fileutil.GetFileMd5(workDir + "/" + config.GetClienAgentFile())
if err != nil {
logs.Error("check agent md5 failed", err)
logs.Error("[agentUpgrade]|check agent md5 failed", err)
return false, false, errors.New("check agent md5 failed")
}
workerMd5, err := fileutil.GetFileMd5(workDir + "/" + config.WorkAgentFile)
if err != nil {
logs.Error("check worker md5 failed", err)
logs.Error("[agentUpgrade]|check worker md5 failed", err)
return false, false, errors.New("check agent md5 failed")
}

Expand Down
Loading

0 comments on commit 063d1ef

Please sign in to comment.