[agent] - bastion mode init
This commit is contained in:
@@ -1,15 +1,34 @@
|
|||||||
package a_init
|
package a_init
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
"wdd.io/agent-go/a_agent"
|
"wdd.io/agent-go/a_agent"
|
||||||
"wdd.io/agent-go/a_executor"
|
|
||||||
"wdd.io/agent-go/a_status"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
完全离线模式
|
||||||
|
交互模式 手动运行 接受输入并且执行指令 类似于cli
|
||||||
|
|
||||||
|
1. 环境信息检测打印输出
|
||||||
|
|
||||||
|
2. 接受用户输入 执行指令
|
||||||
|
|
||||||
|
3. 功能
|
||||||
|
3.1 安装docker
|
||||||
|
3.2 安装docker-compose
|
||||||
|
3.3 安装minio
|
||||||
|
3.4 安装rabbitmq
|
||||||
|
3.5 安装kubernetes
|
||||||
|
*/
|
||||||
|
|
||||||
|
// BastionModeInit 堡垒机模式 完全离线模式
|
||||||
func BastionModeInit() {
|
func BastionModeInit() {
|
||||||
|
|
||||||
// Build For Operator
|
// Build For Operator
|
||||||
agentServerInfo := &a_agent.AgentServerInfo{
|
_ = &a_agent.AgentServerInfo{
|
||||||
ServerName: "BastionSingle",
|
ServerName: "BastionSingle",
|
||||||
ServerIPPbV4: "127.0.0.1",
|
ServerIPPbV4: "127.0.0.1",
|
||||||
ServerIPInV4: "127.0.0.1",
|
ServerIPInV4: "127.0.0.1",
|
||||||
@@ -40,16 +59,36 @@ func BastionModeInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// re-get agentInfo from status module
|
// re-get agentInfo from status module
|
||||||
agentInfo := a_status.ReportAgentInfo()
|
//agentInfo := a_status.ReportAgentInfo()
|
||||||
refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo)
|
//refreshAgentInfoByStatusInfo(agentInfo, agentServerInfo)
|
||||||
buildAgentOsOperator(agentInfo, agentServerInfo)
|
//buildAgentOsOperator(agentInfo, agentServerInfo)
|
||||||
|
|
||||||
// install docker
|
// install docker
|
||||||
agentOsOperator := a_executor.AgentOsOperatorCache
|
//agentOsOperator := a_executor.AgentOsOperatorCache
|
||||||
// boot up minio & rabbitmq
|
// boot up minio & rabbitmq
|
||||||
agentOsOperator.InstallDockerFromLocalExec(nil)
|
//agentOsOperator.InstallDockerFromLocalExec(nil)
|
||||||
agentOsOperator.InstallDockerComposeFromLocalExec()
|
//agentOsOperator.InstallDockerComposeFromLocalExec()
|
||||||
|
|
||||||
// build for socks server
|
// build for socks server
|
||||||
|
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
for {
|
||||||
|
fmt.Print("> ")
|
||||||
|
text, _ := reader.ReadString('\n')
|
||||||
|
text = strings.TrimSpace(text)
|
||||||
|
|
||||||
|
if text == "quit" {
|
||||||
|
break
|
||||||
|
} else if text == "help" {
|
||||||
|
fmt.Println("Available commands:")
|
||||||
|
fmt.Println("- help: show this help message")
|
||||||
|
fmt.Println("- quit: exit the program")
|
||||||
|
fmt.Println("- [command name]: execute a command")
|
||||||
|
} else {
|
||||||
|
// Execute the command
|
||||||
|
fmt.Println("Executing command:", text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if mode == "bastion" {
|
if mode == "bastion" {
|
||||||
|
// 堡垒机模式
|
||||||
|
// 初始化堡垒机模式
|
||||||
a_init.BastionModeInit()
|
a_init.BastionModeInit()
|
||||||
|
flag.StringVar(&agentServerInfoConfFile, "agentServerInfoConfFile", "", "agent server info conf file")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,75 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BasicDownloadFileHTTP(downloadUrl string, proxyUrl string, proxyUser string, proxyPass string, desFile string) (downloadOk bool, resultLog []string) {
|
|
||||||
// 解析下载URL
|
|
||||||
_, err := url.Parse(downloadUrl)
|
|
||||||
if err != nil {
|
|
||||||
resultLog = append(resultLog, "Error parsing download URL: "+err.Error())
|
|
||||||
return false, resultLog
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建文件
|
|
||||||
out, err := os.Create(desFile)
|
|
||||||
if err != nil {
|
|
||||||
resultLog = append(resultLog, "Error creating file: "+err.Error())
|
|
||||||
return false, resultLog
|
|
||||||
}
|
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
// 创建HTTP客户端
|
|
||||||
client := &http.Client{}
|
|
||||||
|
|
||||||
// 如果提供了代理URL
|
|
||||||
if proxyUrl != "" {
|
|
||||||
// 解析代理URL
|
|
||||||
proxyURL, err := url.Parse(proxyUrl)
|
|
||||||
if err != nil {
|
|
||||||
resultLog = append(resultLog, "Error parsing proxy URL: "+err.Error())
|
|
||||||
return false, resultLog
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置HTTP代理
|
|
||||||
transport := &http.Transport{
|
|
||||||
Proxy: func(req *http.Request) (*url.URL, error) {
|
|
||||||
req.SetBasicAuth(proxyUser, proxyPass)
|
|
||||||
return proxyURL, nil
|
|
||||||
},
|
|
||||||
}
|
|
||||||
client.Transport = transport
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发送HTTP GET请求
|
|
||||||
resp, err := client.Get(downloadUrl)
|
|
||||||
if err != nil {
|
|
||||||
resultLog = append(resultLog, "Error making GET request: "+err.Error())
|
|
||||||
return false, resultLog
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
// 检查HTTP响应状态码
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
resultLog = append(resultLog, "Server returned HTTP status "+resp.Status)
|
|
||||||
return false, resultLog
|
|
||||||
}
|
|
||||||
|
|
||||||
// 将HTTP响应内容写入文件
|
|
||||||
_, err = io.Copy(out, resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
resultLog = append(resultLog, "Error writing to file: "+err.Error())
|
|
||||||
return false, resultLog
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, resultLog
|
|
||||||
}
|
|
||||||
|
|
||||||
func splitTest() {
|
func splitTest() {
|
||||||
|
|
||||||
bucketName := "123"
|
bucketName := "123"
|
||||||
@@ -93,20 +27,4 @@ func main() {
|
|||||||
|
|
||||||
splitTest()
|
splitTest()
|
||||||
|
|
||||||
//socksProxyUrl := "socks5://192.168.35.71:22888"
|
|
||||||
//httpProxyUrl := "http://192.168.35.71:22808"
|
|
||||||
//downloadOk, resultLog := BasicDownloadFileHTTP(
|
|
||||||
// "https://happybirthday.107421.xyz/octopus-agent/octopus-agent_linux_amd64_2024-03-29-17-47-14",
|
|
||||||
// httpProxyUrl,
|
|
||||||
// "zeaslity",
|
|
||||||
// "password",
|
|
||||||
// "octopus-agent_linux_1232",
|
|
||||||
//)
|
|
||||||
//if downloadOk {
|
|
||||||
// println("File downloaded successfully")
|
|
||||||
//} else {
|
|
||||||
// for _, log := range resultLog {
|
|
||||||
// println(log)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,22 +38,21 @@ public class TestImageSyncScheduler {
|
|||||||
public void runImageSync() {
|
public void runImageSync() {
|
||||||
|
|
||||||
ArrayList<String> CmiiAppNameList = new ArrayList<>(List.of(
|
ArrayList<String> CmiiAppNameList = new ArrayList<>(List.of(
|
||||||
"cmii-uav-platform-armypeople:5.4.0-041201"
|
// "cmii-uav-platform-armypeople:5.4.0-041201"
|
||||||
));
|
));
|
||||||
|
|
||||||
ArrayList<String> ImageFullNameList = new ArrayList<>(List.of(
|
ArrayList<String> ImageFullNameList = new ArrayList<>(List.of(
|
||||||
// "harbor.cdcyy.com.cn/cmii/cmii-live-operator:5.2.0",
|
// "harbor.cdcyy.com.cn/cmii/cmii-live-operator:5.2.0",
|
||||||
// "harbor.cdcyy.com.cn/cmii/cmii/srs:v5.0.195"
|
// "harbor.cdcyy.com.cn/cmii/cmii/srs:v5.0.195"
|
||||||
// "harbor.cdcyy.com.cn/cmii/cmii-uav-industrial-portfolio:5.4.9-cqly-040901",
|
"harbor.cdcyy.com.cn/cmii/cmii-uav-industrial-portfolio:5.54.0-cqly-041601"
|
||||||
// "harbor.cdcyy.com.cn/cmii/cmii-uav-platform:5.3.0-cqly-040902"
|
|
||||||
));
|
));
|
||||||
|
|
||||||
Boolean downloadAndCompressOnly = false;
|
Boolean downloadAndCompressOnly = false;
|
||||||
|
|
||||||
// String projectNamespace = "wdd"; // wdd
|
// String projectNamespace = "wdd"; // wdd
|
||||||
// String projectNamespace = "cqlyj"; // 重庆林业局
|
String projectNamespace = "cqlyj"; // 重庆林业局
|
||||||
// String projectNamespace = "jlyd"; // 吉林移动
|
// String projectNamespace = "jlyd"; // 吉林移动
|
||||||
String projectNamespace = "xmyd"; // 厦门移动
|
// String projectNamespace = "xmyd"; // 厦门移动
|
||||||
|
|
||||||
// String innerWorkerAgentName = "Chengdu-amd64-65-lapwdd"; //wdd
|
// String innerWorkerAgentName = "Chengdu-amd64-65-lapwdd"; //wdd
|
||||||
String innerWorkerAgentName = "Chengdu-amd64-71-3571gd"; //prod
|
String innerWorkerAgentName = "Chengdu-amd64-71-3571gd"; //prod
|
||||||
|
|||||||
Reference in New Issue
Block a user