Browse Source

Add more locations to find func (#682)

pull/685/head
Justin Kotalik 6 years ago
committed by GitHub
parent
commit
b31204486c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      docs/recipes/azure_functions.md
  2. 2
      docs/reference/schema.md
  3. 40
      src/Microsoft.Tye.Hosting/FuncFinder.cs

6
docs/recipes/azure_functions.md

@ -11,11 +11,7 @@ To start, create an Azure Function project in a folder called `backend-function`
- [Visual Studio](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-your-first-function-visual-studio)
- [Commandline](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-azure-function-azure-cli?tabs=bash%2Cbrowser&pivots=programming-language-csharp)
Next, you must have the [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash) through npm. By default, if you created an azure function through VSCode or Commandline, you will already have installed it. Otherwise, you can install the core tools by running:
```bash
npm install -g azure-functions-core-tools@3
```
Next, you must have the [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash). You can install the core tools by installing the [standalone installer](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#v2) or through [npm](https://www.npmjs.com/package/azure-functions-core-tools).
You can also specify a path to func by specifying `pathToFunc` for the azure function service.

2
docs/reference/schema.md

@ -226,7 +226,7 @@ A path to a folder which contains an azure function project.
#### `pathToFunc` (string)
An optional path to the Azure Functions host to be used instead of the default one installed by npm.
An optional path to the Azure Functions host to be used.
## Environment Variables

40
src/Microsoft.Tye.Hosting/FuncFinder.cs

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -49,25 +50,50 @@ namespace Microsoft.Tye.Hosting
private string? FindFuncForVersion(AzureFunctionRunInfo func)
{
var npmFuncDllPath = GetFuncNpmPath();
if (!File.Exists(npmFuncDllPath))
var funcDllPath = FuncDllPath();
if (!File.Exists(funcDllPath))
{
throw new FileNotFoundException("Could not find func installation. Please install the azure function core tools via: `npm install -g azure-functions-core-tools@3`");
throw new FileNotFoundException("Could not find func installation. Please install the azure function core tools with the installer: " +
"https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local or `npm install -g azure-functions-core-tools@3`");
}
_logger.LogDebug("Using func for running azure functions located at {Func}.", npmFuncDllPath);
return npmFuncDllPath;
_logger.LogDebug("Using func for running azure functions located at {Func}.", funcDllPath);
return funcDllPath;
}
private string GetFuncNpmPath()
private string FuncDllPath()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var funcPathStandalone = Environment.ExpandEnvironmentVariables("%PROGRAMFILES%/Microsoft/Azure Functions Core Tools/func.dll");
if (File.Exists(funcPathStandalone))
{
return funcPathStandalone;
}
return Environment.ExpandEnvironmentVariables("%APPDATA%/npm/node_modules/azure-functions-core-tools/bin/func.dll");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var funcPathStandalone = "/usr/lib/azure-functions-core-tools-3/func.dll";
if (File.Exists(funcPathStandalone))
{
return funcPathStandalone;
}
return "/usr/local/lib/node_modules/azure-functions-core-tools/bin/func.dll";
}
else
{
return Environment.ExpandEnvironmentVariables("/usr/local/lib/node_modules/azure-functions-core-tools/bin/func.dll");
// For brew path, just find a folder that supports functions v3.
var funcDirectories = Directory.GetDirectories("/usr/local/Cellar/azure-functions-core-tools@3/");
var funcPathStandalone = Path.Combine(funcDirectories.LastOrDefault() ?? "", "func.dll");
if (File.Exists(funcPathStandalone))
{
return funcPathStandalone;
}
return "/usr/local/lib/node_modules/azure-functions-core-tools/bin/func.dll";
}
}

Loading…
Cancel
Save