Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
)

var localModulePath string
var registryFilePath string

func init() {
initCmd.PersistentFlags().StringVarP(&localModulePath, "local-module-path", "m", "github.com/commitdev", "local module path - for using local modules instead of downloading from github")
initCmd.PersistentFlags().StringVarP(&registryFilePath, "registry-file-path", "r", "https://raw.githubusercontent.com/commitdev/zero/main/registry.yaml", "registry file path - for using a custom list of stacks")
rootCmd.AddCommand(initCmd)
}

Expand All @@ -22,7 +24,7 @@ var initCmd = &cobra.Command{
Short: "Create new project with provided name and initialize configuration based on user input.",
Run: func(cmd *cobra.Command, args []string) {
flog.Debugf("Root directory is %s", projectconfig.RootDir)
projectContext := initPrompts.Init(projectconfig.RootDir, localModulePath)
projectContext := initPrompts.Init(projectconfig.RootDir, localModulePath, registryFilePath)
projectConfigErr := projectconfig.CreateProjectConfigFile(projectconfig.RootDir, projectContext.Name, projectContext)

if projectConfigErr != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package constants

const (
TmpRegistryYml = "tmp/registry.yaml"
TemplatesDir = "tmp/templates"
ZeroProjectYml = "zero-project.yml"
ZeroModuleYml = "zero-module.yml"
Expand Down
10 changes: 8 additions & 2 deletions internal/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// Create cloud provider context
func Init(outDir string, localModulePath string) *projectconfig.ZeroProjectConfig {
func Init(outDir, localModulePath, registryFilePath string) *projectconfig.ZeroProjectConfig {
projectConfig := defaultProjConfig()

projectRootParams := map[string]string{}
Expand All @@ -36,7 +36,13 @@ func Init(outDir string, localModulePath string) *projectconfig.ZeroProjectConfi
exit.Fatal("Error creating root: %v ", err)
}

moduleSources := chooseStack(registry.GetRegistry(localModulePath))
registry, err := registry.GetRegistry(localModulePath, registryFilePath)

if err != nil {
exit.Fatal("Error getting registry: %v ", err)
}

moduleSources := chooseStack(registry)
moduleConfigs, mappedSources := loadAllModules(moduleSources)

prompts := getProjectPrompts(projectConfig.Name, moduleConfigs)
Expand Down
59 changes: 36 additions & 23 deletions internal/registry/registry.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
package registry

import (
"io/ioutil"

"github.com/commitdev/zero/internal/constants"
"github.com/hashicorp/go-getter"

yaml "gopkg.in/yaml.v2"
)

type Registry []Stack

type Stack struct {
Name string
ModuleSources []string
Name string `yaml:"name"`
ModuleSources []string `yaml:"moduleSources"`
}

func GetRegistry(path string) Registry {
return Registry{
// TODO: better place to store these options as configuration file or any source
{
"EKS + Go + React + Gatsby",
[]string{
path + "/zero-aws-eks-stack",
path + "/zero-static-site-gatsby",
path + "/zero-backend-go",
path + "/zero-frontend-react",
},
},
{
"EKS + NodeJS + React + Gatsby",
[]string{
path + "/zero-aws-eks-stack",
path + "/zero-static-site-gatsby",
path + "/zero-backend-node",
path + "/zero-frontend-react",
},
},
func GetRegistry(localModulePath, registryFilePath string) (Registry, error) {
registry := Registry{}

err := getter.GetFile(constants.TmpRegistryYml, registryFilePath)
if err != nil {
return nil, err
}

data, err := ioutil.ReadFile(constants.TmpRegistryYml)
if err != nil {
return nil, err
}

err = yaml.Unmarshal(data, &registry)
if err != nil {
return nil, err
}

for i := 0; i < len(registry); i++ {
for j := 0; j < len(registry[i].ModuleSources); j++ {
registry[i].ModuleSources[j] = localModulePath + registry[i].ModuleSources[j]
}
}

return registry, nil
}

func GetModulesByName(registry Registry, name string) []string {
Expand Down
13 changes: 13 additions & 0 deletions registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: EKS + Go + React + Gatsby
moduleSources:
- /zero-aws-eks-stack
- /zero-static-site-gatsby
- /zero-backend-go
- /zero-frontend-react

- name: EKS + NodeJS + React + Gatsby
moduleSources:
- /zero-aws-eks-stack
- /zero-static-site-gatsby
- /zero-backend-node
- /zero-frontend-react