diff --git a/dashboard/src/lib/hooks/usePorterYaml.ts b/dashboard/src/lib/hooks/usePorterYaml.ts index 8550f68f8f..d3f83d28c8 100644 --- a/dashboard/src/lib/hooks/usePorterYaml.ts +++ b/dashboard/src/lib/hooks/usePorterYaml.ts @@ -30,9 +30,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); @@ -93,17 +95,19 @@ export const usePorterYaml = ({ const detectServices = useCallback( async ({ b64Yaml, + appName, projectId, clusterId, }: { b64Yaml: string; + appName: string; projectId: number; clusterId: number; }) => { try { const res = await api.parsePorterYaml( "", - { b64_yaml: b64Yaml }, + { b64_yaml: b64Yaml, app_name: appName}, { project_id: projectId, cluster_id: clusterId, @@ -147,6 +151,7 @@ export const usePorterYaml = ({ if (data) { detectServices({ b64Yaml: data, + appName: appName, projectId: currentProject.id, clusterId: currentCluster.id, }); 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 cb20efedbb..370d535333 100644 --- a/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx +++ b/dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx @@ -183,7 +183,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 0f2c83b960..0b45043389 100644 --- a/dashboard/src/shared/api.tsx +++ b/dashboard/src/shared/api.tsx @@ -832,6 +832,7 @@ const getPorterYamlContents = baseApi< const parsePorterYaml = baseApi< { b64_yaml: string; + app_name?: string; }, { project_id: number; 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 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,