github.com/jenkins-x/draft-repo@v0.9.0/pkg/draft/manifest/manifest.go (about) 1 package manifest 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/technosophos/moniker" 8 ) 9 10 const ( 11 // DefaultEnvironmentName is the name invoked from draft.toml on `draft up` when 12 // --environment is not supplied. 13 DefaultEnvironmentName = "development" 14 // DefaultNamespace specifies the namespace apps should be deployed to by default. 15 DefaultNamespace = "default" 16 // DefaultWatchDelaySeconds is the time delay between files being changed and when a 17 // new draft up` invocation is called when --watch is supplied. 18 DefaultWatchDelaySeconds = 2 19 ) 20 21 // Manifest represents a draft.toml 22 type Manifest struct { 23 Environments map[string]*Environment `toml:"environments"` 24 } 25 26 // Environment represents the environment for a given app at build time 27 type Environment struct { 28 Name string `toml:"name,omitempty"` 29 BuildTarPath string `toml:"build_tar,omitempty"` 30 ChartTarPath string `toml:"chart_tar,omitempty"` 31 Namespace string `toml:"namespace,omitempty"` 32 Values []string `toml:"set,omitempty"` 33 Wait bool `toml:"wait"` 34 Watch bool `toml:"watch"` 35 WatchDelay int `toml:"watch_delay,omitempty"` 36 } 37 38 // New creates a new manifest with the Environments intialized. 39 func New() *Manifest { 40 m := Manifest{ 41 Environments: make(map[string]*Environment), 42 } 43 m.Environments[DefaultEnvironmentName] = &Environment{ 44 Name: generateName(), 45 Namespace: DefaultNamespace, 46 Watch: false, 47 WatchDelay: DefaultWatchDelaySeconds, 48 } 49 return &m 50 } 51 52 // generateName generates a name based on the current working directory or a random name. 53 func generateName() string { 54 var name string 55 cwd, err := os.Getwd() 56 if err == nil { 57 name = filepath.Base(cwd) 58 } else { 59 namer := moniker.New() 60 name = namer.NameSep("-") 61 } 62 return name 63 }