agent

package
v0.13.0-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AgentCmd = &cobra.Command{
	Use:   "agent",
	Short: "Start the agent process",
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		if log.GetLevel() < log.InfoLevel {
			log.SetLevel(log.InfoLevel)
		}

		agentMode := config.ModeProject

		if hostModeFlag {
			agentMode = config.ModeHost
		}

		config, err := config.GetConfig(agentMode)
		if err != nil {
			log.Fatal(err)
		}

		gitLogWriter := io.MultiWriter(os.Stdout)
		var agentLogWriter io.Writer
		if config.LogFilePath != nil {
			logFile, err := os.OpenFile(*config.LogFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
			if err != nil {
				log.Fatal(err)
			}
			defer logFile.Close()
			gitLogWriter = io.MultiWriter(os.Stdout, logFile)
			agentLogWriter = logFile
		}

		git := &git.Service{
			ProjectDir:        config.ProjectDir,
			GitConfigFileName: path.Join(os.Getenv("HOME"), ".gitconfig"),
			LogWriter:         gitLogWriter,
		}

		sshServer := &ssh.Server{
			ProjectDir:        config.ProjectDir,
			DefaultProjectDir: os.Getenv("HOME"),
		}

		tailscaleHostname := workspace.GetProjectHostname(config.WorkspaceId, config.ProjectName)
		if hostModeFlag {
			tailscaleHostname = config.WorkspaceId
		}

		tailscaleServer := &tailscale.Server{
			Hostname:  tailscaleHostname,
			ServerUrl: config.Server.Url,
		}

		agent := agent.Agent{
			Config:    config,
			Git:       git,
			Ssh:       sshServer,
			Tailscale: tailscaleServer,
			LogWriter: agentLogWriter,
		}

		err = agent.Start()
		if err != nil {
			log.Fatal(err)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL