Ver código fonte

add app name to front end parse yaml api call (#3593)

Co-authored-by: David Townley <davidtownley@Davids-MacBook-Air.local>
Co-authored-by: Feroze Mohideen <feroze@porter.run>
d-g-town 2 anos atrás
pai
commit
e101a54d8a

+ 6 - 1
dashboard/src/lib/hooks/usePorterYaml.ts

@@ -30,9 +30,11 @@ type PorterYamlStatus =
  */
  */
 export const usePorterYaml = ({
 export const usePorterYaml = ({
   source,
   source,
+  appName = "",
   useDefaults = true,
   useDefaults = true,
 }: {
 }: {
   source: (SourceOptions & { type: "github" }) | null;
   source: (SourceOptions & { type: "github" }) | null;
+  appName?: string;
   useDefaults?: boolean;
   useDefaults?: boolean;
 }): PorterYamlStatus => {
 }): PorterYamlStatus => {
   const { currentProject, currentCluster } = useContext(Context);
   const { currentProject, currentCluster } = useContext(Context);
@@ -93,17 +95,19 @@ export const usePorterYaml = ({
   const detectServices = useCallback(
   const detectServices = useCallback(
     async ({
     async ({
       b64Yaml,
       b64Yaml,
+      appName,
       projectId,
       projectId,
       clusterId,
       clusterId,
     }: {
     }: {
       b64Yaml: string;
       b64Yaml: string;
+      appName: string;
       projectId: number;
       projectId: number;
       clusterId: number;
       clusterId: number;
     }) => {
     }) => {
       try {
       try {
         const res = await api.parsePorterYaml(
         const res = await api.parsePorterYaml(
           "<token>",
           "<token>",
-          { b64_yaml: b64Yaml },
+          { b64_yaml: b64Yaml, app_name: appName},
           {
           {
             project_id: projectId,
             project_id: projectId,
             cluster_id: clusterId,
             cluster_id: clusterId,
@@ -147,6 +151,7 @@ export const usePorterYaml = ({
     if (data) {
     if (data) {
       detectServices({
       detectServices({
         b64Yaml: data,
         b64Yaml: data,
+        appName: appName,
         projectId: currentProject.id,
         projectId: currentProject.id,
         clusterId: currentCluster.id,
         clusterId: currentCluster.id,
       });
       });

+ 1 - 0
dashboard/src/main/home/app-dashboard/app-view/LatestRevisionContext.tsx

@@ -145,6 +145,7 @@ export const LatestRevisionProvider = ({
 
 
   const { loading: porterYamlLoading, detectedServices } = usePorterYaml({
   const { loading: porterYamlLoading, detectedServices } = usePorterYaml({
     source: latestSource?.type === "github" ? latestSource : null,
     source: latestSource?.type === "github" ? latestSource : null,
+    appName: appName,
     useDefaults: false,
     useDefaults: false,
   });
   });
 
 

+ 1 - 1
dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx

@@ -183,7 +183,7 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
     porterYamlFound,
     porterYamlFound,
     detectedName,
     detectedName,
     loading: isLoadingPorterYaml,
     loading: isLoadingPorterYaml,
-  } = usePorterYaml({ source: source?.type === "github" ? source : null });
+  } = usePorterYaml({ source: source?.type === "github" ? source : null, appName: name.value });
   const deploymentTarget = useDefaultDeploymentTarget();
   const deploymentTarget = useDefaultDeploymentTarget();
   const { updateAppStep } = useAppAnalytics(name.value);
   const { updateAppStep } = useAppAnalytics(name.value);
   const { validateApp } = useAppValidation({
   const { validateApp } = useAppValidation({

+ 1 - 0
dashboard/src/shared/api.tsx

@@ -832,6 +832,7 @@ const getPorterYamlContents = baseApi<
 const parsePorterYaml = baseApi<
 const parsePorterYaml = baseApi<
   {
   {
     b64_yaml: string;
     b64_yaml: string;
+    app_name?: string;
   },
   },
   {
   {
     project_id: number;
     project_id: number;

+ 1 - 1
internal/porter_app/parse_test.go

@@ -44,7 +44,7 @@ func TestParseYAML(t *testing.T) {
 }
 }
 
 
 var result_nobuild = &porterv1.PorterApp{
 var result_nobuild = &porterv1.PorterApp{
-	Name: "js-test-app",
+	Name: "test-app",
 	Services: map[string]*porterv1.Service{
 	Services: map[string]*porterv1.Service{
 		"example-job": {
 		"example-job": {
 			Run:          "echo 'hello world'",
 			Run:          "echo 'hello world'",

+ 1 - 1
internal/porter_app/testdata/v2_input_nobuild.yaml

@@ -1,5 +1,5 @@
 version: v2
 version: v2
-name: "js-test-app"
+name: "test-app"
 image:
 image:
   repository: nginx
   repository: nginx
   tag: latest
   tag: latest

+ 8 - 0
internal/porter_app/v2/yaml.go

@@ -31,10 +31,18 @@ func AppProtoFromYaml(ctx context.Context, porterYamlBytes []byte, appName strin
 		porterYaml.Name = appName
 		porterYaml.Name = appName
 	}
 	}
 
 
+	if porterYaml.Name != "" && appName != "" && porterYaml.Name != appName {
+		return nil, nil, telemetry.Error(ctx, span, nil, "name specified in porter.yaml does not match app name")
+	}
+
 	appProto := &porterv1.PorterApp{
 	appProto := &porterv1.PorterApp{
 		Name: porterYaml.Name,
 		Name: porterYaml.Name,
 	}
 	}
 
 
+	if appProto.Name == "" {
+		return nil, nil, telemetry.Error(ctx, span, nil, "app name is empty")
+	}
+
 	if porterYaml.Build != nil {
 	if porterYaml.Build != nil {
 		appProto.Build = &porterv1.Build{
 		appProto.Build = &porterv1.Build{
 			Context:    porterYaml.Build.Context,
 			Context:    porterYaml.Build.Context,