Skip to content

Instantly share code, notes, and snippets.

@baronfel
Last active May 28, 2024 20:50
Show Gist options
  • Save baronfel/e97f46933d05365ea93d7855af742e58 to your computer and use it in GitHub Desktop.
Save baronfel/e97f46933d05365ea93d7855af742e58 to your computer and use it in GitHub Desktop.
Azure Functions Isolated dockerfile using SDK Containers
<Project>
<!-- Targets that replicate the behavior of the azure functions isolated dockerfile using the
SDK container tech -->
<Target Name="EnsureValidFunctionsTFM">
<PropertyGroup>
<_MinimumSupportedFunctionsTFM>6.0</_MinimumSupportedFunctionsTFM>
<_MaximumSupportedFunctionsTFM>8.0</_MaximumSupportedFunctionsTFM>
</PropertyGroup>
<Error Condition="[MSBuild]::VersionLessThan($(_MinimumSupportedFunctionsTFM), $(TargetFrameworkVersion)) or [MSBuild]::VersionGreaterThan($(_MaximumSupportedFunctionsTFM), $(TargetFrameworkVersion))"
Text="The Azure Functions isolated worker supports between net$(_MinimumSupportedFunctionsTFM) and net$(_MaximumSupportedFunctionsTFM) as the target framework." />
</Target>
<Target
Name="AssignFunctionsBaseImage"
BeforeTargets="ComputeContainerBaseImage"
DependsOnTargets="EnsureValidFunctionsTFM">
<!-- We're replicating the data in this dockerfile: https://github.com/Azure/azure-functions-core-tools/blob/8878ab9455b83142f614e27557cf1ee7f1b414a1/src/Azure.Functions.Cli/StaticResources/Dockerfile.dotnetIsolated -->
<PropertyGroup>
<FunctionsRuntimeVersion Condition="'$(FunctionsRuntimeVersion)' == ''">4</FunctionsRuntimeVersion>
<ContainerBaseImage>
mcr.microsoft.com/azure-functions/dotnet-isolated:$(FunctionsRuntimeVersion)-dotnet-isolated$(_TargetFrameworkVersionWithoutV)</ContainerBaseImage>
<ContainerWorkingDirectory>/home/site/wwwroot</ContainerWorkingDirectory>
<!-- Functions only support amd64 runtimes -->
<ContainerRuntimeIdentifier>linux-x64</ContainerRuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<ContainerEnvironmentVariable
Include="AzureWebJobsScriptRoot"
Value="$(ContainerWorkingDirectory)" />
<ContainerEnvironmentVariable
Include="AzureFunctionsJobHost__Logging__Console__IsEnabled"
Value="true" />
</ItemGroup>
<ItemGroup>
<ContainerAppCommand Include="/opt/startup/start_nonappservice.sh" />
</ItemGroup>
</Target>
</Project>
@baronfel
Copy link
Author

And to be clear, this kind of extensibility is exactly what I was hoping for when we made these extensibility points in the SDK - sorta like dotnet run, the SDK bakes in some defaults but allows specific use cases to override that behavior!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment