| 22 | ) |
| 23 | |
| 24 | func Apply(rootDir string, configPath string, environments []string) error { |
| 25 | var errs []error |
| 26 | if strings.Trim(configPath, " ") == "" { |
| 27 | exit.Fatal("config path cannot be empty!") |
| 28 | } |
| 29 | configFilePath := path.Join(rootDir, configPath) |
| 30 | projectConfig := projectconfig.LoadConfig(configFilePath) |
| 31 | |
| 32 | if len(environments) == 0 { |
| 33 | fmt.Println(`Choose the environments to apply. This will create infrastructure, CI pipelines, etc. |
| 34 | At this point, real things will be generated that may cost money! |
| 35 | Only a single environment may be suitable for an initial test, but for a real system we suggest setting up both staging and production environments.`) |
| 36 | environments = promptEnvironments() |
| 37 | } |
| 38 | |
| 39 | flog.Infof(":mag: checking project %s's module requirements.", projectConfig.Name) |
| 40 | |
| 41 | errs = modulesWalkCmd("check", rootDir, projectConfig, "check", environments, false, false) |
| 42 | // Check operation walks through all modules and can return multiple errors |
| 43 | if len(errs) > 0 { |
| 44 | msg := "" |
| 45 | for i := 0; i < len(errs); i++ { |
| 46 | msg += "- " + errs[i].Error() |
| 47 | } |
| 48 | return errors.New(fmt.Sprintf("The following Module check(s) failed: \n%s", msg)) |
| 49 | } |
| 50 | |
| 51 | flog.Infof(":tada: Bootstrapping project %s. Please use the zero-project.yml file to modify the project as needed.", projectConfig.Name) |
| 52 | |
| 53 | flog.Infof("Cloud provider: %s", "AWS") // will this come from the config? |
| 54 | |
| 55 | flog.Infof("Runtime platform: %s", "Kubernetes") |
| 56 | |
| 57 | flog.Infof("Infrastructure executor: %s", "Terraform") |
| 58 | |
| 59 | errs = modulesWalkCmd("apply", rootDir, projectConfig, "apply", environments, true, true) |
| 60 | if len(errs) > 0 { |
| 61 | return errors.New(fmt.Sprintf("Module Apply failed: %s", errs[0])) |
| 62 | } |
| 63 | |
| 64 | flog.Infof(":check_mark_button: Done.") |
| 65 | |
| 66 | flog.Infof("Your projects and infrastructure have been successfully created. Here are some useful links and commands to get you started:") |
| 67 | errs = modulesWalkCmd("summary", rootDir, projectConfig, "summary", environments, true, true) |
| 68 | if len(errs) > 0 { |
| 69 | return errors.New(fmt.Sprintf("Module summary failed: %s", errs[0])) |
| 70 | } |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | func modulesWalkCmd(lifecycleName string, dir string, projectConfig *projectconfig.ZeroProjectConfig, operation string, environments []string, bailOnError bool, shouldPipeStderr bool) []error { |
| 75 | var moduleErrors []error |