implement system mode agent

This commit is contained in:
yusing
2025-02-23 11:26:38 +08:00
parent 5e8e4fa4a1
commit 2c21387ad9
7 changed files with 254 additions and 11 deletions

View File

@@ -0,0 +1,24 @@
package agent
import (
"bytes"
"strings"
"text/template"
)
var (
installScript = `AGENT_NAME={{.Name}} \
AGENT_PORT={{.Port}} \
AGENT_CA_CERT={{.CACert}} \
AGENT_SSL_CERT={{.SSLCert}} \
bash -c "$(curl -fsSL https://raw.githubusercontent.com/yusing/go-proxy/main/scripts/install-agent.sh)"`
installScriptTemplate = template.Must(template.New("install.sh").Parse(installScript))
)
func (c *AgentEnvConfig) Generate() (string, error) {
buf := bytes.NewBuffer(make([]byte, 0, 4096))
if err := installScriptTemplate.Execute(buf, c); err != nil {
return "", err
}
return strings.ReplaceAll(buf.String(), ";", "\\;"), nil
}

View File

@@ -7,9 +7,11 @@ import (
_ "embed"
)
//go:embed agent.compose.yml
var agentComposeYAML string
var agentComposeYAMLTemplate = template.Must(template.New("agent.compose.yml").Parse(agentComposeYAML))
var (
//go:embed templates/agent.compose.yml
agentComposeYAML string
agentComposeYAMLTemplate = template.Must(template.New("agent.compose.yml").Parse(agentComposeYAML))
)
const (
DockerImageProduction = "ghcr.io/yusing/godoxy-agent:latest"

17
agent/pkg/agent/env.go Normal file
View File

@@ -0,0 +1,17 @@
package agent
type (
AgentEnvConfig struct {
Name string
Port int
CACert string
SSLCert string
}
AgentComposeConfig struct {
Image string
*AgentEnvConfig
}
Generator interface {
Generate() (string, error)
}
)