|
|
@@ -24,33 +24,41 @@ 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 {
|
|
|
- if len(porterYamlPath) == 0 {
|
|
|
- return fmt.Errorf("porter yaml is empty")
|
|
|
+ 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")
|
|
|
}
|
|
|
|
|
|
- porterYaml, err := os.ReadFile(filepath.Clean(porterYamlPath))
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("could not read porter yaml file: %w", err)
|
|
|
- }
|
|
|
+ var yamlB64 string
|
|
|
+ if len(porterYamlPath) != 0 {
|
|
|
+ porterYaml, err := os.ReadFile(filepath.Clean(porterYamlPath))
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("could not read porter yaml file: %w", err)
|
|
|
+ }
|
|
|
|
|
|
- b64YAML := base64.StdEncoding.EncodeToString(porterYaml)
|
|
|
+ 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"))
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("error calling parse yaml endpoint: %w", err)
|
|
|
- }
|
|
|
+ // 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"))
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("error calling parse yaml endpoint: %w", err)
|
|
|
+ }
|
|
|
|
|
|
- if parseResp.B64AppProto == "" {
|
|
|
- return errors.New("b64 app proto is empty")
|
|
|
- }
|
|
|
+ if parseResp.B64AppProto == "" {
|
|
|
+ return errors.New("b64 app proto is empty")
|
|
|
+ }
|
|
|
+ yamlB64 = parseResp.B64AppProto
|
|
|
|
|
|
- appName, err := appNameFromB64AppProto(parseResp.B64AppProto)
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("error getting app name from b64 app proto: %w", err)
|
|
|
- }
|
|
|
+ // override app name if provided
|
|
|
+ appName, err = appNameFromB64AppProto(parseResp.B64AppProto)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("error getting app name from b64 app proto: %w", err)
|
|
|
+ }
|
|
|
|
|
|
- color.New(color.FgGreen).Printf("Successfully parsed Porter YAML: applying app \"%s\"\n", appName) // nolint:errcheck,gosec
|
|
|
+ color.New(color.FgGreen).Printf("Successfully parsed Porter YAML: applying app \"%s\"\n", appName) // nolint:errcheck,gosec
|
|
|
+ }
|
|
|
|
|
|
targetResp, err := client.DefaultDeploymentTarget(ctx, cliConf.Project, cliConf.Cluster)
|
|
|
if err != nil {
|
|
|
@@ -70,7 +78,7 @@ func Apply(ctx context.Context, cliConf config.CLIConfig, client api.Client, por
|
|
|
commitSHA = commit.Sha
|
|
|
}
|
|
|
|
|
|
- validateResp, err := client.ValidatePorterApp(ctx, cliConf.Project, cliConf.Cluster, parseResp.B64AppProto, targetResp.DeploymentTargetID, commitSHA)
|
|
|
+ validateResp, err := client.ValidatePorterApp(ctx, cliConf.Project, cliConf.Cluster, appName, yamlB64, targetResp.DeploymentTargetID, commitSHA)
|
|
|
if err != nil {
|
|
|
return fmt.Errorf("error calling validate endpoint: %w", err)
|
|
|
}
|
|
|
@@ -154,6 +162,8 @@ 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
|
|
|
+
|
|
|
if applyResp.CLIAction == porterv1.EnumCLIAction_ENUM_CLI_ACTION_TRACK_PREDEPLOY {
|
|
|
color.New(color.FgGreen).Printf("Waiting for predeploy to complete...\n") // nolint:errcheck,gosec
|
|
|
|