From 934edbb2dbee3f21bf6c53d6530b7c6aaa03c8ba Mon Sep 17 00:00:00 2001 From: David Townley Date: Tue, 19 Sep 2023 10:25:10 -0400 Subject: [PATCH 1/5] add app name to front end parse yaml api call --- dashboard/src/lib/hooks/usePorterYaml.ts | 5 ++++- .../home/app-dashboard/app-view/LatestRevisionContext.tsx | 1 + .../src/main/home/app-dashboard/create-app/CreateApp.tsx | 2 +- dashboard/src/shared/api.tsx | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dashboard/src/lib/hooks/usePorterYaml.ts b/dashboard/src/lib/hooks/usePorterYaml.ts index 8550f68f8f..c77fe27f1b 100644 --- a/dashboard/src/lib/hooks/usePorterYaml.ts +++ b/dashboard/src/lib/hooks/usePorterYaml.ts @@ -6,6 +6,7 @@ import { useCallback, useContext, useEffect, useState } from "react"; import { Context } from "shared/Context"; import api from "shared/api"; import { z } from "zod"; +import {useFormContext} from "react-hook-form"; type PorterYamlStatus = | { @@ -30,9 +31,11 @@ type PorterYamlStatus = */ export const usePorterYaml = ({ source, + appName = "", useDefaults = true, }: { source: (SourceOptions & { type: "github" }) | null; + appName?: string; useDefaults?: boolean; }): PorterYamlStatus => { const { currentProject, currentCluster } = useContext(Context); @@ -103,7 +106,7 @@ export const usePorterYaml = ({ try { const res = await api.parsePorterYaml( "", - { b64_yaml: b64Yaml }, + { b64_yaml: b64Yaml, app_name: appName}, { project_id: projectId, cluster_id: clusterId, diff --git a/dashboard/src/main/home/app-dashboard/app-view/LatestRevisionContext.tsx b/dashboard/src/main/home/app-dashboard/app-view/LatestRevisionContext.tsx index 8dacfe1d9e..d2b0bca355 100644 --- a/dashboard/src/main/home/app-dashboard/app-view/LatestRevisionContext.tsx +++ b/dashboard/src/main/home/app-dashboard/app-view/LatestRevisionContext.tsx @@ -145,6 +145,7 @@ export const LatestRevisionProvider = ({ const { loading: porterYamlLoading, detectedServices } = usePorterYaml({ source: latestSource?.type === "github" ? latestSource : null, + appName: appName, useDefaults: false, }); diff --git a/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx b/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx index 8e7f4c0e6d..9e0f66a119 100644 --- a/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx +++ b/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx @@ -147,7 +147,7 @@ const CreateApp: React.FC = ({ history }) => { porterYamlFound, detectedName, loading: isLoadingPorterYaml, - } = usePorterYaml({ source: source?.type === "github" ? source : null }); + } = usePorterYaml({ source: source?.type === "github" ? source : null, appName: name.value }); const deploymentTarget = useDefaultDeploymentTarget(); const { updateAppStep } = useAppAnalytics(name.value); const { validateApp } = useAppValidation({ diff --git a/dashboard/src/shared/api.tsx b/dashboard/src/shared/api.tsx index 5893ce9c54..f5dd526b59 100644 --- a/dashboard/src/shared/api.tsx +++ b/dashboard/src/shared/api.tsx @@ -813,6 +813,7 @@ const getPorterYamlContents = baseApi< const parsePorterYaml = baseApi< { b64_yaml: string; + app_name?: string; }, { project_id: number; From b7abbee31f6071badab53d922f8e1847a5528ac8 Mon Sep 17 00:00:00 2001 From: David Townley Date: Tue, 19 Sep 2023 10:28:16 -0400 Subject: [PATCH 2/5] remove unused import --- dashboard/src/lib/hooks/usePorterYaml.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/dashboard/src/lib/hooks/usePorterYaml.ts b/dashboard/src/lib/hooks/usePorterYaml.ts index c77fe27f1b..197c47d88e 100644 --- a/dashboard/src/lib/hooks/usePorterYaml.ts +++ b/dashboard/src/lib/hooks/usePorterYaml.ts @@ -6,7 +6,6 @@ import { useCallback, useContext, useEffect, useState } from "react"; import { Context } from "shared/Context"; import api from "shared/api"; import { z } from "zod"; -import {useFormContext} from "react-hook-form"; type PorterYamlStatus = | { From 1825f68dcf558605e2ba2023ebc01ae8e84052f9 Mon Sep 17 00:00:00 2001 From: David Townley Date: Tue, 19 Sep 2023 11:07:41 -0400 Subject: [PATCH 3/5] properly pipe app name into hooks --- dashboard/src/lib/hooks/usePorterYaml.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dashboard/src/lib/hooks/usePorterYaml.ts b/dashboard/src/lib/hooks/usePorterYaml.ts index 197c47d88e..d3f83d28c8 100644 --- a/dashboard/src/lib/hooks/usePorterYaml.ts +++ b/dashboard/src/lib/hooks/usePorterYaml.ts @@ -95,10 +95,12 @@ export const usePorterYaml = ({ const detectServices = useCallback( async ({ b64Yaml, + appName, projectId, clusterId, }: { b64Yaml: string; + appName: string; projectId: number; clusterId: number; }) => { @@ -149,6 +151,7 @@ export const usePorterYaml = ({ if (data) { detectServices({ b64Yaml: data, + appName: appName, projectId: currentProject.id, clusterId: currentCluster.id, }); From e497895b5a3b1e66edb5f6da30792f4999ad3d60 Mon Sep 17 00:00:00 2001 From: Feroze Mohideen Date: Tue, 19 Sep 2023 11:25:51 -0400 Subject: [PATCH 4/5] add error handling --- internal/porter_app/v2/yaml.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/porter_app/v2/yaml.go b/internal/porter_app/v2/yaml.go index 23ac6accb9..57d73533fe 100644 --- a/internal/porter_app/v2/yaml.go +++ b/internal/porter_app/v2/yaml.go @@ -31,10 +31,18 @@ func AppProtoFromYaml(ctx context.Context, porterYamlBytes []byte, appName strin 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{ Name: porterYaml.Name, } + if appProto.Name == "" { + return nil, nil, telemetry.Error(ctx, span, nil, "app name is empty") + } + if porterYaml.Build != nil { appProto.Build = &porterv1.Build{ Context: porterYaml.Build.Context, From 1dd945b52322aa442a845b09e538e09c3847f8e8 Mon Sep 17 00:00:00 2001 From: David Townley Date: Tue, 19 Sep 2023 18:05:49 -0400 Subject: [PATCH 5/5] fix test --- internal/porter_app/parse_test.go | 2 +- internal/porter_app/testdata/v2_input_nobuild.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/porter_app/parse_test.go b/internal/porter_app/parse_test.go index f8de16e9c9..9b8a35966a 100644 --- a/internal/porter_app/parse_test.go +++ b/internal/porter_app/parse_test.go @@ -44,7 +44,7 @@ func TestParseYAML(t *testing.T) { } var result_nobuild = &porterv1.PorterApp{ - Name: "js-test-app", + Name: "test-app", Services: map[string]*porterv1.Service{ "example-job": { Run: "echo 'hello world'", diff --git a/internal/porter_app/testdata/v2_input_nobuild.yaml b/internal/porter_app/testdata/v2_input_nobuild.yaml index de014a4fec..63aff6f8eb 100644 --- a/internal/porter_app/testdata/v2_input_nobuild.yaml +++ b/internal/porter_app/testdata/v2_input_nobuild.yaml @@ -1,5 +1,5 @@ version: v2 -name: "js-test-app" +name: "test-app" image: repository: nginx tag: latest