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

Switch Dockerfile and host.json check when creating function app #4062

Merged
merged 2 commits into from
Mar 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ export async function detectDockerfile(context: ICreateFunctionAppContext): Prom
if (vscode.workspace.workspaceFolders) {
context.workspaceFolder = vscode.workspace.workspaceFolders[0];
const workspacePath = context.workspaceFolder.uri.fsPath;
let hostPath: string = workspacePath
let dockerfilePath: string = workspacePath
context.rootPath = workspacePath;

//check for host.json location
//check for dockerfile location
if (await isFunctionProject(workspacePath)) {
const files = (await findFiles(context.workspaceFolder, `*/${hostFileName}`));
const files = (await findFiles(context.workspaceFolder, `**/${dockerfileGlobPattern}`));
if (files.length === 0) {
throw new Error(localize('noHostJson', 'No host.json file found in the current workspace.'));
return;
}
hostPath = path.dirname(files[0].fsPath);
dockerfilePath = path.dirname(files[0].fsPath);
}

// check if dockerfile exists in the same folder as the host.json
if ((await findFiles(hostPath, dockerfileGlobPattern)).length > 0) {
context.dockerfilePath = (await findFiles(hostPath, dockerfileGlobPattern))[0].fsPath;
// check if host.json is in the same directory as the Dockerfile
if ((await findFiles(dockerfilePath, hostFileName)).length > 0) {
context.dockerfilePath = (await findFiles(dockerfilePath, dockerfileGlobPattern))[0].fsPath;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you just set it as

Suggested change
context.dockerfilePath = (await findFiles(dockerfilePath, dockerfileGlobPattern))[0].fsPath;
context.dockerfilePath = dockerfilePath;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dockerfile path above is set to the directory not the actualy path of the dockerfile. This is because we check the host.json path using the dockerfile directory we found. When we pass this context value to ACA it won't work with just the directory path. I can make two seperate constants and set one as the dockerfile but that seemed a little over kill, but since it seems confusing I can do that if you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the main thing that I wanted to avoid is to have to do another findFiles call in here, but I guess it was always like that so whatever 🤷

} else {
context.dockerfilePath = undefined;
}
Expand Down
Loading