-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdefaults.go
61 lines (55 loc) · 1.57 KB
/
defaults.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
package options
import (
"fmt"
"strings"
"github.com/go-git/go-billy/v5/osfs"
giturls "github.com/chainguard-dev/git-urls"
"github.com/coder/envbuilder/constants"
"github.com/coder/envbuilder/internal/chmodfs"
)
// DefaultWorkspaceFolder returns the default workspace folder
// for a given repository URL.
func DefaultWorkspaceFolder(repoURL string) string {
if repoURL == "" {
return constants.EmptyWorkspaceDir
}
parsed, err := giturls.Parse(repoURL)
if err != nil {
return constants.EmptyWorkspaceDir
}
name := strings.Split(parsed.Path, "/")
hasOwnerAndRepo := len(name) >= 2
if !hasOwnerAndRepo {
return constants.EmptyWorkspaceDir
}
repo := strings.TrimSuffix(name[len(name)-1], ".git")
return fmt.Sprintf("/workspaces/%s", repo)
}
func (o *Options) SetDefaults() {
// Temporarily removed these from the default settings to prevent conflicts
// between current and legacy environment variables that add default values.
// Once the legacy environment variables are phased out, this can be
// reinstated to the previous default values.
if len(o.IgnorePaths) == 0 {
o.IgnorePaths = []string{
"/var/run",
// KinD adds these paths to pods, so ignore them by default.
"/product_uuid", "/product_name",
}
}
if o.InitScript == "" {
o.InitScript = "sleep infinity"
}
if o.InitCommand == "" {
o.InitCommand = "/bin/sh"
}
if o.Filesystem == nil {
o.Filesystem = chmodfs.New(osfs.New("/"))
}
if o.WorkspaceFolder == "" {
o.WorkspaceFolder = DefaultWorkspaceFolder(o.GitURL)
}
if o.BinaryPath == "" {
o.BinaryPath = "/.envbuilder/bin/envbuilder"
}
}