-
Notifications
You must be signed in to change notification settings - Fork 616
/
agent.go
52 lines (48 loc) · 1.46 KB
/
agent.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
package provisionersdk
import (
_ "embed"
"fmt"
"strings"
)
var (
// These used to be hard-coded, but after growing significantly more complex
// it made sense to put them in their own files (e.g. for linting).
//go:embed scripts/bootstrap_windows.ps1
windowsScript string
//go:embed scripts/bootstrap_linux.sh
linuxScript string
//go:embed scripts/bootstrap_darwin.sh
darwinScript string
// A mapping of operating-system ($GOOS) to architecture ($GOARCH)
// to agent install and run script. ${DOWNLOAD_URL} is replaced
// with strings.ReplaceAll() when being consumed. ${ARCH} is replaced
// with the architecture when being provided.
agentScripts = map[string]map[string]string{
"windows": {
"amd64": windowsScript,
"arm64": windowsScript,
},
"linux": {
"amd64": linuxScript,
"arm64": linuxScript,
"armv7": linuxScript,
},
"darwin": {
"amd64": darwinScript,
"arm64": darwinScript,
},
}
)
// AgentScriptEnv returns a key-pair of scripts that are consumed
// by the Coder Terraform Provider. See:
// https://github.com/coder/terraform-provider-coder/blob/main/internal/provider/provider.go#L97
func AgentScriptEnv() map[string]string {
env := map[string]string{}
for operatingSystem, scripts := range agentScripts {
for architecture, script := range scripts {
script := strings.ReplaceAll(script, "${ARCH}", architecture)
env[fmt.Sprintf("CODER_AGENT_SCRIPT_%s_%s", operatingSystem, architecture)] = script
}
}
return env
}