Sfoglia il codice sorgente

App requirements yaml (#3968)

ianedwards 2 anni fa
parent
commit
fa049f5b02
1 ha cambiato i file con 30 aggiunte e 7 eliminazioni
  1. 30 7
      internal/porter_app/v2/yaml.go

+ 30 - 7
internal/porter_app/v2/yaml.go

@@ -88,9 +88,10 @@ type PorterApp struct {
 	Build    *Build            `yaml:"build,omitempty"`
 	Env      map[string]string `yaml:"env,omitempty"`
 
-	Predeploy  *Service    `yaml:"predeploy,omitempty"`
-	EnvGroups  []EnvGroup  `yaml:"envGroups,omitempty"`
-	EfsStorage *EfsStorage `yaml:"efsStorage,omitempty"`
+	Predeploy    *Service      `yaml:"predeploy,omitempty"`
+	EnvGroups    []EnvGroup    `yaml:"envGroups,omitempty"`
+	EfsStorage   *EfsStorage   `yaml:"efsStorage,omitempty"`
+	RequiredApps []RequiredApp `yaml:"requiredApps,omitempty"`
 }
 
 // PorterYAML represents all the possible fields in a Porter YAML file
@@ -99,6 +100,12 @@ type PorterYAML struct {
 	Previews  *PorterApp `yaml:"previews,omitempty"`
 }
 
+// RequiredApp specifies another porter app that this app expects to be deployed alongside it
+type RequiredApp struct {
+	Name       string `yaml:"name"`
+	FromTarget string `yaml:"fromTarget"`
+}
+
 // EfsStorage represents the EFS storage settings for a Porter app
 type EfsStorage struct {
 	Enabled bool `yaml:"enabled"`
@@ -189,10 +196,6 @@ func ProtoFromApp(ctx context.Context, porterApp PorterApp) (*porterv1.PorterApp
 		}
 	}
 
-	if porterApp.Services == nil {
-		return appProto, nil, telemetry.Error(ctx, span, nil, "porter yaml is missing services")
-	}
-
 	// service map is only needed for backwards compatibility at this time
 	serviceMap := make(map[string]*porterv1.Service)
 	var services []*porterv1.Service
@@ -238,6 +241,26 @@ func ProtoFromApp(ctx context.Context, porterApp PorterApp) (*porterv1.PorterApp
 			Enabled: porterApp.EfsStorage.Enabled,
 		}
 	}
+
+	for _, requiredApp := range porterApp.RequiredApps {
+		var targetIdentifier *porterv1.DeploymentTargetIdentifier
+
+		if requiredApp.Name == "" {
+			return appProto, nil, telemetry.Error(ctx, span, nil, "required app specified with no name")
+		}
+
+		if requiredApp.FromTarget != "" {
+			targetIdentifier = &porterv1.DeploymentTargetIdentifier{
+				Name: requiredApp.FromTarget,
+			}
+		}
+
+		appProto.RequiredApps = append(appProto.RequiredApps, &porterv1.RequiredApp{
+			Name:       requiredApp.Name,
+			FromTarget: targetIdentifier,
+		})
+	}
+
 	return appProto, porterApp.Env, nil
 }