Преглед изворни кода

POR-1708 route update full to v2 apply (#3563)

ianedwards пре 2 година
родитељ
комит
75185b58f5
4 измењених фајлова са 28 додато и 22 уклоњено
  1. 12 9
      cli/cmd/commands/apply.go
  2. 1 1
      cli/cmd/commands/update.go
  3. 3 10
      cli/cmd/v2/apply.go
  4. 12 2
      cli/cmd/v2/deploy.go

+ 12 - 9
cli/cmd/commands/apply.go

@@ -114,8 +114,15 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 		return fmt.Errorf("could not retrieve project from Porter API. Please contact support@porter.run")
 	}
 
+	var appName string
+	if os.Getenv("PORTER_APP_NAME") != "" {
+		appName = os.Getenv("PORTER_APP_NAME")
+	} else if os.Getenv("PORTER_STACK_NAME") != "" {
+		appName = os.Getenv("PORTER_STACK_NAME")
+	}
+
 	if project.ValidateApplyV2 {
-		err = v2.Apply(ctx, cliConfig, client, porterYAML)
+		err = v2.Apply(ctx, cliConfig, client, porterYAML, appName)
 		if err != nil {
 			return err
 		}
@@ -123,11 +130,8 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 	}
 
 	fileBytes, err := os.ReadFile(porterYAML) //nolint:errcheck,gosec // do not want to change logic of CLI. New linter error
-	if err != nil {
-		stackName := os.Getenv("PORTER_STACK_NAME")
-		if stackName == "" {
-			return fmt.Errorf("a valid porter.yaml file must be specified. Run porter apply --help for more information")
-		}
+	if err != nil && appName == "" {
+		return fmt.Errorf("a valid porter.yaml file must be specified. Run porter apply --help for more information")
 	}
 
 	var previewVersion struct {
@@ -187,8 +191,8 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 		}
 
 		if parsed.Applications != nil {
-			for appName, app := range parsed.Applications {
-				resources, err := porter_app.CreateApplicationDeploy(ctx, client, worker, app, appName, cliConfig)
+			for name, app := range parsed.Applications {
+				resources, err := porter_app.CreateApplicationDeploy(ctx, client, worker, app, name, cliConfig)
 				if err != nil {
 					return fmt.Errorf("error parsing porter.yaml for build resources: %w", err)
 				}
@@ -196,7 +200,6 @@ func apply(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client ap
 				resGroup.Resources = append(resGroup.Resources, resources...)
 			}
 		} else {
-			appName := os.Getenv("PORTER_STACK_NAME")
 			if appName == "" {
 				return fmt.Errorf("environment variable PORTER_STACK_NAME must be set")
 			}

+ 1 - 1
cli/cmd/commands/update.go

@@ -445,7 +445,7 @@ the image that the application uses if no --values file is specified:
 
 func updateFull(ctx context.Context, _ *types.GetAuthenticatedUserResponse, client api.Client, cliConf config.CLIConfig, featureFlags config.FeatureFlags, args []string) error {
 	if featureFlags.ValidateApplyV2Enabled {
-		err := v2.UpdateFull(ctx)
+		err := v2.UpdateFull(ctx, cliConf, client, app)
 		if err != nil {
 			return err
 		}

+ 3 - 10
cli/cmd/v2/apply.go

@@ -23,14 +23,7 @@ import (
 )
 
 // Apply implements the functionality of the `porter apply` command for validate apply v2 projects
-func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, porterYamlPath string) error {
-	var appName string
-	if os.Getenv("PORTER_APP_NAME") != "" {
-		appName = os.Getenv("PORTER_APP_NAME")
-	} else if os.Getenv("PORTER_STACK_NAME") != "" {
-		appName = os.Getenv("PORTER_STACK_NAME")
-	}
-
+func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, porterYamlPath string, appName string) error {
 	var yamlB64 string
 	if len(porterYamlPath) != 0 {
 		porterYaml, err := os.ReadFile(filepath.Clean(porterYamlPath))
@@ -41,7 +34,7 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
 		b64YAML := base64.StdEncoding.EncodeToString(porterYaml)
 
 		// last argument is passed to accommodate users with v1 porter yamls
-		parseResp, err := client.ParseYAML(ctx, cliConf.Project, cliConf.Cluster, b64YAML, os.Getenv("PORTER_STACK_NAME"))
+		parseResp, err := client.ParseYAML(ctx, cliConf.Project, cliConf.Cluster, b64YAML, appName)
 		if err != nil {
 			return fmt.Errorf("error calling parse yaml endpoint: %w", err)
 		}
@@ -162,7 +155,7 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
 		}
 	}
 
-	color.New(color.FgGreen).Printf("Image tag exists in repository") // nolint:errcheck,gosec
+	color.New(color.FgGreen).Printf("Image tag exists in repository\n") // nolint:errcheck,gosec
 
 	if applyResp.CLIAction == porterv1.EnumCLIAction_ENUM_CLI_ACTION_TRACK_PREDEPLOY {
 		color.New(color.FgGreen).Printf("Waiting for predeploy to complete...\n") // nolint:errcheck,gosec

+ 12 - 2
cli/cmd/v2/deploy.go

@@ -3,11 +3,21 @@ package v2
 import (
 	"context"
 	"fmt"
+
+	api "github.com/porter-dev/porter/api/client"
+	"github.com/porter-dev/porter/cli/cmd/config"
 )
 
 // UpdateFull implements the functionality of the `porter build` command for validate apply v2 projects
-func UpdateFull(ctx context.Context) error {
-	fmt.Println("This command is not supported for your project. Contact support@porter.run for more information.")
+func UpdateFull(ctx context.Context, cliConf config.CLIConfig, client api.Client, appName string) error {
+	// use empty string for porterYamlPath,legacy projects wont't have a v2 porter.yaml
+	var porterYamlPath string
+
+	err := Apply(ctx, cliConf, client, porterYamlPath, appName)
+	if err != nil {
+		return err
+	}
+
 	return nil
 }