Skip to content

Commit a800f69

Browse files
committed
Add agent command for root menu
1 parent c35b0dc commit a800f69

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

cmd/cmd_agent.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ func init() {
4141
}
4242

4343
func cmdAgentRun(cmd *cobra.Command, args []string) {
44-
log := logrus.WithField("component", "agent")
44+
runAgentLoop(flagAgentServer, flagAgentToken, agent.DockerConfig{
45+
Disabled: flagAgentDockerDisabled,
46+
DefaultImage: flagAgentDockerDefaultImage,
47+
}, vcs.Options{
48+
P4Client: flagAgentP4Client,
49+
})
50+
}
4551

46-
serverURL := flagAgentServer
47-
agentToken := flagAgentToken
52+
func runAgentLoop(serverURL, agentToken string, dockerCfg agent.DockerConfig, vcsOpts vcs.Options) {
53+
log := logrus.WithField("component", "agent")
4854

4955
ctx, cancel := context.WithCancel(context.Background())
5056
defer cancel()
@@ -63,12 +69,7 @@ func cmdAgentRun(cmd *cobra.Command, args []string) {
6369

6470
for {
6571
client := agent.NewClient(serverURL, agentToken)
66-
w := agent.NewWorker(client, agent.DockerConfig{
67-
Disabled: flagAgentDockerDisabled,
68-
DefaultImage: flagAgentDockerDefaultImage,
69-
}, vcs.Options{
70-
P4Client: flagAgentP4Client,
71-
})
72+
w := agent.NewWorker(client, dockerCfg, vcsOpts)
7273

7374
log.WithField("server", serverURL).Info("connecting")
7475
err := w.Run(ctx)

cmd/cmd_root.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/actionforge/actrun-cli/agent"
13+
"github.com/actionforge/actrun-cli/agent/vcs"
1314
"github.com/actionforge/actrun-cli/build"
1415
"github.com/actionforge/actrun-cli/core"
1516
"github.com/actionforge/actrun-cli/sessions"
@@ -231,7 +232,23 @@ func cmdRootRun(cmd *cobra.Command, args []string) {
231232
return
232233

233234
case 3: // Connect as agent
234-
fmt.Println("Agent mode is not yet implemented.")
235+
serverURL := envOr("ACT_AGENT_SERVER", "https://orch.actionforge.dev")
236+
token := envOr("ACT_AGENT_TOKEN", "")
237+
if token == "" {
238+
token = sessions.PromptAgentToken()
239+
}
240+
if token == "" {
241+
fmt.Println("No agent token provided.")
242+
trapfn()
243+
return
244+
}
245+
runAgentLoop(serverURL, token, agent.DockerConfig{
246+
Disabled: envOrBool("ACT_AGENT_DOCKER_DISABLED", false),
247+
DefaultImage: envOr("ACT_AGENT_DOCKER_DEFAULT_IMAGE", ""),
248+
}, vcs.Options{
249+
P4Client: envOr("ACT_AGENT_P4CLIENT", ""),
250+
})
251+
trapfn()
235252
return
236253

237254
default:

0 commit comments

Comments
 (0)