MCPcopy Index your code
hub / github.com/commitdev/zero / modulesWalkCmd

Function modulesWalkCmd

internal/apply/apply.go:74–135  ·  view source on GitHub ↗
(lifecycleName string, dir string, projectConfig *projectconfig.ZeroProjectConfig, operation string, environments []string, bailOnError bool, shouldPipeStderr bool)

Source from the content-addressed store, hash-verified

72}
73
74func modulesWalkCmd(lifecycleName string, dir string, projectConfig *projectconfig.ZeroProjectConfig, operation string, environments []string, bailOnError bool, shouldPipeStderr bool) []error {
75 var moduleErrors []error
76 graph := projectConfig.GetDAG()
77 root := []dag.Vertex{projectconfig.GraphRootName}
78 environmentArg := fmt.Sprintf("ENVIRONMENT=%s", strings.Join(environments, ","))
79 err := graph.DepthFirstWalk(root, func(v dag.Vertex, depth int) error {
80 // Don't process the root
81 if depth == 0 {
82 return nil
83 }
84
85 name := v.(string)
86 mod := projectConfig.Modules[name]
87 // Add env vars for the makefile
88 envList := []string{
89 environmentArg,
90 fmt.Sprintf("PROJECT_NAME=%s", projectConfig.Name),
91 fmt.Sprintf("PROJECT_DIR=%s", path.Join(dir, mod.Files.Directory)),
92 fmt.Sprintf("REPOSITORY=%s", mod.Files.Repository),
93 }
94
95 modulePath := module.GetSourceDir(mod.Files.Source)
96 // Passed in `dir` will only be used to find the project path, not the module path,
97 // unless the module path is relative
98 if module.IsLocal(mod.Files.Source) && !filepath.IsAbs(modulePath) {
99 modulePath = filepath.Join(dir, modulePath)
100 }
101 flog.Debugf("Loaded module: %s from %s", name, modulePath)
102
103 // TODO: in the case user lost the `/tmp` (module source dir), this will fail
104 // and we should redownload the module for the user
105 modConfig, err := module.ParseModuleConfig(modulePath)
106 if err != nil {
107 exit.Fatal("Failed to load Module: %s", err)
108 }
109
110 envVarTranslationMap := modConfig.GetParamEnvVarTranslationMap()
111 envList = util.AppendProjectEnvToCmdEnv(mod.Parameters, envList, envVarTranslationMap)
112 flog.Debugf("Env injected: %#v", envList)
113
114 // only print msg for apply, or else it gets a little spammy
115 if lifecycleName == "apply" {
116 flog.Infof("Executing %s command for %s...", lifecycleName, modConfig.Name)
117 }
118 operationCommand := getModuleOperationCommand(modConfig, operation)
119 execErr := util.ExecuteCommand(exec.Command(operationCommand[0], operationCommand[1:]...), modulePath, envList, shouldPipeStderr)
120 if execErr != nil {
121 formatedErr := errors.New(fmt.Sprintf("Module (%s) %s", modConfig.Name, execErr.Error()))
122 if bailOnError {
123 return formatedErr
124 } else {
125 moduleErrors = append(moduleErrors, formatedErr)
126 }
127 }
128 return nil
129 })
130 if err != nil {
131 moduleErrors = append(moduleErrors, err)

Callers 1

ApplyFunction · 0.85

Calls 12

GetSourceDirFunction · 0.92
IsLocalFunction · 0.92
DebugfFunction · 0.92
ParseModuleConfigFunction · 0.92
FatalFunction · 0.92
AppendProjectEnvToCmdEnvFunction · 0.92
InfofFunction · 0.92
ExecuteCommandFunction · 0.92
GetDAGMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected