Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send app name to parse request for v1 yaml #3595

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions dashboard/src/lib/hooks/usePorterYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ type PorterYamlStatus =
* usePorterYaml is a hook that will fetch the porter.yaml file from the
* specified source and parse it to determine the services that should be
* added to an app by default with read-only values.
*
*
* `appName` is required to be passed in to accommodate v1 porter.yaml, since v1 porter.yaml does not explicitly specify the app name.
* if the porter.yaml is v2, and the file contains an app name, then the appName parameter here will be ignored.
*/
export const usePorterYaml = ({
source,
appName = "",
useDefaults = true,
}: {
source: (SourceOptions & { type: "github" }) | null;
appName?: string;
useDefaults?: boolean;
}): PorterYamlStatus => {
const { currentProject, currentCluster } = useContext(Context);
Expand Down Expand Up @@ -95,15 +99,17 @@ export const usePorterYaml = ({
b64Yaml,
projectId,
clusterId,
appName,
}: {
b64Yaml: string;
projectId: number;
clusterId: number;
appName: string;
}) => {
try {
const res = await api.parsePorterYaml(
"<token>",
{ b64_yaml: b64Yaml },
{ b64_yaml: b64Yaml, app_name: appName },
{
project_id: projectId,
cluster_id: clusterId,
Expand Down Expand Up @@ -149,6 +155,7 @@ export const usePorterYaml = ({
b64Yaml: data,
projectId: currentProject.id,
clusterId: currentCluster.id,
appName,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const LatestRevisionProvider = ({

const { loading: porterYamlLoading, detectedServices } = usePorterYaml({
source: latestSource?.type === "github" ? latestSource : null,
appName: porterApp?.name,
useDefaults: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const CreateApp: React.FC<CreateAppProps> = ({ 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({
Expand Down Expand Up @@ -585,9 +585,8 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
}
>
{detectedServices.count > 0
? `Detected ${detectedServices.count} service${
detectedServices.count > 1 ? "s" : ""
} from porter.yaml.`
? `Detected ${detectedServices.count} service${detectedServices.count > 1 ? "s" : ""
} from porter.yaml.`
: `Could not detect any services from porter.yaml. Make sure it exists in the root of your repo.`}
</Text>
</AppearingDiv>
Expand Down
84 changes: 36 additions & 48 deletions dashboard/src/shared/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ const getFeedEvents = baseApi<
}
>("GET", (pathParams) => {
let { project_id, cluster_id, stack_name, page } = pathParams;
return `/api/projects/${project_id}/clusters/${cluster_id}/applications/${stack_name}/events?page=${
page || 1
}`;
return `/api/projects/${project_id}/clusters/${cluster_id}/applications/${stack_name}/events?page=${page || 1
}`;
});

const createEnvironment = baseApi<
Expand Down Expand Up @@ -747,11 +746,9 @@ const detectBuildpack = baseApi<
branch: string;
}
>("GET", (pathParams) => {
return `/api/projects/${pathParams.project_id}/gitrepos/${
pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${
pathParams.name
}/${encodeURIComponent(pathParams.branch)}/buildpack/detect`;
return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
}/${encodeURIComponent(pathParams.branch)}/buildpack/detect`;
});

const detectGitlabBuildpack = baseApi<
Expand Down Expand Up @@ -782,11 +779,9 @@ const getBranchContents = baseApi<
branch: string;
}
>("GET", (pathParams) => {
return `/api/projects/${pathParams.project_id}/gitrepos/${
pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${
pathParams.name
}/${encodeURIComponent(pathParams.branch)}/contents`;
return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
}/${encodeURIComponent(pathParams.branch)}/contents`;
});

const getProcfileContents = baseApi<
Expand All @@ -802,11 +797,9 @@ const getProcfileContents = baseApi<
branch: string;
}
>("GET", (pathParams) => {
return `/api/projects/${pathParams.project_id}/gitrepos/${
pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${
pathParams.name
}/${encodeURIComponent(pathParams.branch)}/procfile`;
return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
}/${encodeURIComponent(pathParams.branch)}/procfile`;
});

const getPorterYamlContents = baseApi<
Expand All @@ -822,16 +815,15 @@ const getPorterYamlContents = baseApi<
branch: string;
}
>("GET", (pathParams) => {
return `/api/projects/${pathParams.project_id}/gitrepos/${
pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${
pathParams.name
}/${encodeURIComponent(pathParams.branch)}/porteryaml`;
return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
}/${encodeURIComponent(pathParams.branch)}/porteryaml`;
});

const parsePorterYaml = baseApi<
{
b64_yaml: string;
app_name: string;
},
{
project_id: number;
Expand Down Expand Up @@ -862,11 +854,9 @@ const getBranchHead = baseApi<
branch: string;
}
>("GET", (pathParams) => {
return `/api/projects/${pathParams.project_id}/gitrepos/${
pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${
pathParams.name
}/${encodeURIComponent(pathParams.branch)}/head`;
return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
}/${encodeURIComponent(pathParams.branch)}/head`;
});

const validatePorterApp = baseApi<
Expand All @@ -890,21 +880,21 @@ const validatePorterApp = baseApi<

const createApp = baseApi<
| {
name: string;
type: "github";
git_repo_id: number;
git_branch: string;
git_repo_name: string;
porter_yaml_path: string;
}
name: string;
type: "github";
git_repo_id: number;
git_branch: string;
git_repo_name: string;
porter_yaml_path: string;
}
| {
name: string;
type: "docker-registry";
image: {
repository: string;
tag: string;
};
},
name: string;
type: "docker-registry";
image: {
repository: string;
tag: string;
};
},
{
project_id: number;
cluster_id: number;
Expand Down Expand Up @@ -1894,11 +1884,9 @@ const getEnvGroup = baseApi<
version?: number;
}
>("GET", (pathParams) => {
return `/api/projects/${pathParams.id}/clusters/${
pathParams.cluster_id
}/namespaces/${pathParams.namespace}/envgroup?name=${pathParams.name}${
pathParams.version ? "&version=" + pathParams.version : ""
}`;
return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id
}/namespaces/${pathParams.namespace}/envgroup?name=${pathParams.name}${pathParams.version ? "&version=" + pathParams.version : ""
}`;
});

const getConfigMap = baseApi<
Expand Down Expand Up @@ -2955,7 +2943,7 @@ const removeStackEnvGroup = baseApi<
`/api/v1/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/stacks/${stack_id}/remove_env_group/${env_group_name}`
);

const getGithubStatus = baseApi<{}, {}>("GET", ({}) => `/api/status/github`);
const getGithubStatus = baseApi<{}, {}>("GET", ({ }) => `/api/status/github`);

const createSecretAndOpenGitHubPullRequest = baseApi<
{
Expand Down
8 changes: 8 additions & 0 deletions internal/porter_app/v2/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading