Azure Functions Host

repository·dev·Indexed 24 days ago

https://github.com/azure/azure-functions-host

The core runtime host for the Azure Functions service, built upon the Azure WebJobs SDK. It provides the underlying infrastructure to execute functions across multiple languages using various triggers and bindings. The repository includes documentation for running WebJobs.Script benchmarks, managing JSON schemas, integrating language worker protobufs via git subtrees, and building/publishing Site Extensions.

Tokens
11.6K
Snippets
30
Records
36
Agent score
83%

What's inside azure-functions-host

  1. Locate and use Azure Functions JSON Schemas

    dev

    The JSON schemas in this repository are copies of the official schemas published to the JSON Schema Store. These schemas are used by Azure Functions tooling, such as Visual Studio, to provide validation and IntelliSense for configuration files.

    Important Maintenance Notes:

    • host.json schema: This schema is no longer maintained in this repository; it is now maintained in the Azure/Azure-Functions repository.
    • Making changes: If you need to update a schema, you must submit a Pull Request to the Schema Store Repository rather than this repository. Changes made here are merely copies.
  2. Generate a Private Site Extension (PSE)

    dev

    Private Site Extensions (PSE) are not generated during the standard build process. To generate one, navigate to the publish output directory ({repo_root}/out/pub/WebJobs.Script.SiteExtension/{config}_win) and run the New-PrivateSiteExtension.ps1 script.

    By default, it generates a zipped x64 PSE.

    # Generates a zipped x64 PSE by default
    ./New-PrivateSiteExtension.ps1
    
    # To generate x86 / 32bit:
    ./New-PrivateSiteExtension.ps1 -Bitness x86
    
    # Can skip zipping the extension:
    ./New-PrivateSiteExtension.ps1 -NoZip
  3. Compress the Site Extension into a .zip package

    dev

    There are two ways to produce a compressed (.zip) site extension:

    1. Via dotnet publish: Add the -p:ZipAfterPublish=true flag to your publish command. The resulting zip will be located at {repo_root}/out/pkg/{config}.
    2. Via PowerShell script: If you have already published the unzipped files to {repo_root}/out/pub/WebJobs.Script.SiteExtension/{config}_win, you can run Compress-SiteExtension.ps1. This method allows you to insert JIT trace files during the compression process.
    # Produces the .zip site extension by default
    ./Compress-SiteExtension.ps1
    
    # Produce the zip, inserting JIT trace files beforehand.
    ./Compress-SiteExtension.ps1 -JitTrace "path/to/file.jittrace", "path/to/file2.jittrace"
  4. Build and publish the Site Extension using dotnet CLI

    dev

    The Site Extension can be built and published using MSBuild commands. You can perform these steps together in a single command or separately for more granular control.

    Note: When building separately, you must set PublishReadyToRun=true (this requirement is fixed in the .NET 9 SDK).

    # Together
    dotnet publish -c {config}
    
    # Separately
    dotnet restore -p:PublishReadyToRun=true
    dotnet build -c {config} --no-restore
    dotnet publish -c {config} --no-build
  5. Update the Language Worker Protobuf subtree

    dev

    If your language worker repository already has the protobuf repository embedded as a subtree, follow these steps to pull updates from a specific release tag:

    1. Add the proto-file remote and fetch it if not already present.
    2. Fetch the specific release tag you want to update to (e.g., v1.1.0-protofile).
    3. Merge the updates using the -X subtree strategy option to handle the subtree path correctly. Use --squash to keep the history clean and --allow-unrelated-histories to permit the merge.
    4. Commit and push the update.
    git remote add proto-file https://github.com/azure/azure-functions-language-worker-protobuf.git
    git fetch proto-file
    git fetch proto-file refs/tags/<tag-name>
    git merge -X subtree=<path in language worker repo> --squash <tag-name> --allow-unrelated-histories --strategy-option theirs
    git commit -m "Updated subtree from https://github.com/azure/azure-functions-language-worker-protobuf. Tag: <tag-name>. Commit: <commit hash>"
    git push
  6. Run WebJobs.Script Benchmarks

    dev

    To execute the performance benchmarks for the WebJobs.Script components, use the dotnet run command from the solution root. You can either use the interactive prompt to select specific benchmarks or pass a filter directly via the command line.

    Interactive Mode

    Running the base command will present a list of discovered benchmarks. You can select them by entering their index number (e.g., 0), their caption (e.g., AuthUtilityBenchmarks), or multiple benchmarks separated by spaces (e.g., 1 2 3).

    Filtered Mode

    To bypass the interactive prompt and run specific benchmarks immediately, use the --filter flag with a glob pattern (e.g., *BenchmarkName*).

  7. Add the Language Worker Protobuf repo as a subtree

    dev

    To use the gRPC service definitions in an Azure Functions language worker repository, add this repository as a git subtree. This ensures the protobuf files are embedded directly in your worker's source tree.

    Follow these steps from within your language worker repository:

    1. Add the protobuf repository as a remote named proto-file.
    2. Fetch the remote.
    3. Use git read-tree to index the contents of a specific version branch into a chosen path in your repository.
    4. Add that path to your .gitignore to prevent accidental commits of the raw subtree files.
    5. Commit and push the changes.
    git remote add proto-file https://github.com/azure/azure-functions-language-worker-protobuf.git
    git fetch proto-file
    git read-tree --prefix=<path in language worker repo> -u proto-file/<version branch>
    # Add <path in language worker repo> to .gitignore
    git commit -m "Added subtree from https://github.com/azure/azure-functions-language-worker-protobuf. Branch: <version branch>. Commit: <latest protobuf commit hash>"
    git push
  8. Generate Java code from FunctionRPC.proto

    dev

    For Java workers, use the protobuf-maven-plugin. Configure the protoSourceRoot in your pom.xml to point to the directory containing the .proto files within the subtree.

    Configuration:

    <protoSourceRoot>${basedir}/<path to this repo>/azure-functions-language-worker-protobuf/src/proto</protoSourceRoot>
    <protoSourceRoot>${basedir}/<path to this repo>/azure-functions-language-worker-protobuf/src/proto</protoSourceRoot>
  9. Generate JavaScript and TypeScript code from FunctionRPC.proto

    dev

    Use the protobufjs npm package to generate runtime code from the protobuf definition. You can generate CommonJS JavaScript modules or static TypeScript definitions.

    Generate JavaScript (CommonJS): Use pbjs with the -t json-module flag.

    Generate TypeScript: Use pbjs with the -t static-module flag to create a static JS file, then use pbts to generate the corresponding .d.ts declaration file.

  10. Generate C# code from FunctionRPC.proto

    dev

    To generate C# classes and gRPC services from the protobuf definition, use protoc.exe with the grpc.tools and google.protobuf.tools NuGet packages.

    Prerequisites:

    • Set NUGET_PATH to your local NuGet packages directory.
    • Set versionNumber to the version of the tools you are using.
    • Ensure GRPC_TOOLS_PATH and PROTOBUF_TOOLS are correctly pointed to the tool binaries within your NuGet cache.
    set NUGET_PATH="%UserProfile%\.nuget\packages"
    set GRPC_TOOLS_PATH=%NUGET_PATH%\grpc.tools\<versionNumber>\tools\windows_x86
    set PROTO_PATH=.\azure-functions-language-worker-protobuf\src\proto
    set PROTO=.\azure-functions-language-worker-protobuf\src\proto\FunctionRpc.proto
    set PROTOBUF_TOOLS=%NUGET_PATH%\google.protobuf.tools\<versionNumber>\tools
    set MSGDIR=.\Messages
    
    if exist %MSGDIR% rmdir /s /q %MSGDIR%
    mkdir %MSGDIR%
    
    set OUTDIR=%MSGDIR%\DotNet
    mkdir %OUTDIR%
    %GRPC_TOOLS_PATH%\protoc.exe %PROTO% --csharp_out %OUTDIR% --grpc_out=%OUTDIR% --plugin=protoc-gen-grpc=%GRPC_TOOLS_PATH%\grpc_csharp_plugin.exe --proto_path=%PROTO_PATH% --proto_path=%PROTOBUF_TOOLS%