github.com/pluralsh/plural-cli@v0.9.5/pkg/up/generate.go (about) 1 package up 2 3 import ( 4 "fmt" 5 6 "github.com/pluralsh/plural-cli/pkg/utils" 7 "github.com/pluralsh/plural-cli/pkg/utils/git" 8 ) 9 10 type templatePair struct { 11 from string 12 to string 13 overwrite bool 14 } 15 16 func (ctx *Context) Generate() error { 17 if !utils.Exists("./bootstrap") { 18 if err := git.Submodule("https://github.com/pluralsh/bootstrap.git"); err != nil { 19 return err 20 } 21 } 22 23 prov := ctx.Provider.Name() 24 tpls := []templatePair{ 25 {from: "./bootstrap/charts/runtime/values.yaml.tpl", to: "./helm-values/runtime.yaml", overwrite: true}, 26 {from: "./bootstrap/helm/certmanager.yaml", to: "./helm-values/certmanager.yaml", overwrite: true}, 27 {from: "./bootstrap/helm/flux.yaml", to: "./helm-values/flux.yaml", overwrite: true}, 28 {from: fmt.Sprintf("./bootstrap/templates/providers/bootstrap/%s.tf", prov), to: "clusters/provider.tf"}, 29 {from: fmt.Sprintf("./bootstrap/templates/setup/providers/%s.tf", prov), to: "clusters/mgmt.tf"}, 30 {from: "./bootstrap/templates/setup/console.tf", to: "clusters/console.tf"}, 31 {from: fmt.Sprintf("./bootstrap/templates/providers/apps/%s.tf", prov), to: "apps/terraform/provider.tf"}, 32 {from: "./bootstrap/templates/setup/cd.tf", to: "apps/terraform/cd.tf"}, 33 {from: "./bootstrap/README.md", to: "README.md", overwrite: true}, 34 } 35 36 for _, tpl := range tpls { 37 if utils.Exists(tpl.to) && !tpl.overwrite { 38 fmt.Printf("%s already exists, skipping for now...\n", tpl.to) 39 continue 40 } 41 42 if err := ctx.templateFrom(tpl.from, tpl.to); err != nil { 43 return err 44 } 45 } 46 47 copies := []templatePair{ 48 {from: "./bootstrap/apps/repositories", to: "apps/repositories"}, 49 {from: "./bootstrap/apps/services", to: "apps/services"}, 50 } 51 52 for _, copy := range copies { 53 if utils.Exists(copy.to) && !copy.overwrite { 54 continue 55 } 56 57 if err := utils.CopyDir(copy.from, copy.to); err != nil { 58 return err 59 } 60 } 61 62 return nil 63 }