lzbj commented on a change in pull request #310: Support both manifest.yaml and 
manifest.yml
URL: 
https://github.com/apache/incubator-openwhisk-wskdeploy/pull/310#discussion_r133344309
 
 

 ##########
 File path: cmd/root.go
 ##########
 @@ -144,3 +138,134 @@ func initConfig() {
                fmt.Println("Using config file:", viper.ConfigFileUsed())
        }
 }
+
+
+func Deploy() error {
+
+       whisk.SetVerbose(utils.Flags.Verbose)
+
+       projectPath, err := filepath.Abs(utils.Flags.ProjectPath)
+       utils.Check(err)
+
+       if utils.Flags.ManifestPath == "" {
+               if _, err := os.Stat(path.Join(projectPath, "manifest.yaml")); 
err == nil {
+                       utils.Flags.ManifestPath = path.Join(projectPath, 
deployers.ManifestFileNameYaml)
+               } else if _, err := os.Stat(path.Join(projectPath, 
"manifest.yml")); err == nil {
+                       utils.Flags.ManifestPath = path.Join(projectPath, 
deployers.ManifestFileNameYml)
+               }
+       }
+
+       if utils.Flags.DeploymentPath == "" {
+               if _, err := os.Stat(path.Join(projectPath, 
"deployment.yaml")); err == nil {
+                       utils.Flags.DeploymentPath = path.Join(projectPath, 
deployers.DeploymentFileNameYaml)
+               } else if _, err := os.Stat(path.Join(projectPath, 
"deployment.yml")); err == nil {
+                       utils.Flags.DeploymentPath = path.Join(projectPath, 
deployers.DeploymentFileNameYml)
+               }
+       }
+
+       if utils.MayExists(utils.Flags.ManifestPath) {
+
+               var deployer = deployers.NewServiceDeployer()
+               deployer.ProjectPath = projectPath
+               deployer.ManifestPath = utils.Flags.ManifestPath
+               deployer.DeploymentPath = utils.Flags.DeploymentPath
+               // perform some quick check here.
+               go func() {
+                       deployer.Check()
+               }()
+               deployer.IsDefault = utils.Flags.UseDefaults
+
+               deployer.IsInteractive = utils.Flags.UseInteractive
+
+               // master record of any dependency that has been downloaded
+               deployer.DependencyMaster = 
make(map[string]utils.DependencyRecord)
+
+               propPath := ""
+               if !utils.Flags.WithinOpenWhisk {
+                       userHome := utils.GetHomeDirectory()
+                       propPath = path.Join(userHome, ".wskprops")
+               }
+               whiskClient, clientConfig := deployers.NewWhiskClient(propPath, 
utils.Flags.DeploymentPath, deployer.IsInteractive)
+               deployer.Client = whiskClient
+               deployer.ClientConfig = clientConfig
+
+               err := deployer.ConstructDeploymentPlan()
+
+               if err != nil {
+                       utils.Check(err)
+                       return err
+               }
+
+               err = deployer.Deploy()
+               if err != nil {
+                       utils.Check(err)
+                       return err
+               } else {
+                       return nil
+               }
+
+       } else {
+               if utils.Flags.WithinOpenWhisk {
+                       utils.PrintOpenWhiskError(wski18n.T("missing 
manifest.yaml file"))
+                       return errors.New("missing manifest.yaml file")
+               } else {
+                       log.Println("missing manifest.yaml file")
+                       return errors.New("missing manifest.yaml file")
+               }
+       }
+
+}
+
+func Undeploy() error {
+       // TODO: Work your own magic here
+       whisk.SetVerbose(utils.Flags.Verbose)
+
+       if utils.Flags.ManifestPath == "" {
+               if ok, _ := regexp.Match(deployers.ManifestFileNameYml, 
[]byte(utils.Flags.ManifestPath)); ok {
+                       utils.Flags.ManifestPath = 
path.Join(utils.Flags.ProjectPath, deployers.ManifestFileNameYml)
+               } else {
+                       utils.Flags.ManifestPath = 
path.Join(utils.Flags.ProjectPath, deployers.ManifestFileNameYaml)
+               }
+
+       }
+
+       if utils.Flags.DeploymentPath == "" {
+               if ok, _ := regexp.Match(deployers.DeploymentFileNameYml, 
[]byte(utils.Flags.ManifestPath)); ok {
+                       utils.Flags.DeploymentPath = 
path.Join(utils.Flags.ProjectPath, deployers.DeploymentFileNameYml)
+               } else {
+                       utils.Flags.DeploymentPath = 
path.Join(utils.Flags.ProjectPath, deployers.DeploymentFileNameYaml)
+               }
+
+       }
+
+       if utils.FileExists(utils.Flags.ManifestPath) {
+
+               var deployer = deployers.NewServiceDeployer()
+               deployer.ProjectPath = utils.Flags.ProjectPath
+               deployer.ManifestPath = utils.Flags.ManifestPath
+               deployer.DeploymentPath = utils.Flags.DeploymentPath
+
+               deployer.IsInteractive = utils.Flags.UseInteractive
+               deployer.IsDefault = utils.Flags.UseDefaults
+
+               userHome := utils.GetHomeDirectory()
+               propPath := path.Join(userHome, ".wskprops")
+
+               whiskClient, clientConfig := deployers.NewWhiskClient(propPath, 
utils.Flags.DeploymentPath, deployer.IsInteractive)
+               deployer.Client = whiskClient
+               deployer.ClientConfig = clientConfig
+
+               verifiedPlan, err := deployer.ConstructUnDeploymentPlan()
 
 Review comment:
   Ok, agree.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to