-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
71 lines (58 loc) · 1.62 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package task
import (
"fmt"
"os"
"path/filepath"
"strings"
"time"
"github.com/circleci/ex/config/secret"
"github.com/goccy/go-json"
)
type Config struct {
Cmd []string `json:"cmd"`
User string `json:"user"`
TaskID string `json:"task_id"`
ReadinessFilePath string `json:"readiness_file_path"`
EnableUnsafeRetries bool `json:"enable_unsafe_retries"`
// Task agent configuration
Token secret.String `json:"token"`
TaskAgentPath string `json:"task_agent_path"`
RunnerAPIBaseURL string `json:"runner_api_base_url"`
Allocation string `json:"allocation"`
SSHAdvertiseAddr string `json:"ssh_advertise_addr"`
MaxRunTime time.Duration `json:"max_run_time"`
}
func (c *Config) UnmarshalJSON(b []byte) error {
type tmpConfig Config
var tc tmpConfig
if err := json.Unmarshal(b, &tc); err != nil {
return fmt.Errorf("failed to unmarshal config: %w", err)
}
*c = Config(tc)
return nil
}
type Agent struct {
Cmd []string
Env []string
}
func (c *Config) Agent() Agent {
args := []string{
"_internal",
"agent-runner",
"--verbose",
"--runnerAPIBaseURL=" + c.RunnerAPIBaseURL,
"--allocation=" + c.Allocation,
"--disableSpinUpStep",
"--disableIsolatedSSHDir",
fmt.Sprintf("--maxRunTime=%v", c.MaxRunTime),
}
if c.SSHAdvertiseAddr != "" {
args = append(args, "--sshAdvertiseAddr="+c.SSHAdvertiseAddr)
}
cmd := append(strings.Split(c.TaskAgentPath, " "), args...)
env := []string{fmt.Sprintf("PATH=%s:%s", os.Getenv("PATH"), filepath.Dir(c.TaskAgentPath))}
return Agent{
Cmd: cmd,
Env: env,
}
}