Last active
May 28, 2024 20:50
-
-
Save baronfel/e97f46933d05365ea93d7855af742e58 to your computer and use it in GitHub Desktop.
Azure Functions Isolated dockerfile using SDK Containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
I assume dotnet publish /t:PublishContainer
it sets the images entrypoint to your projects main executable by default - this totally makes sense for api and worker projects.
This does not work for Azure Functions for dotnet-isolated, where the project needs to be started by the Functions host runtime instead. So yep i guess we need a workaround for Functions.
I added your change to the sample so it would be more correct for future readers :)
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
ah, I do see that from the base image. Good catch - though I wonder if this is a gap in the SDK tooling itself (i.e. should we inherit this from the base image?).