Azure / azure-functions-docker

This repo contains the base Docker images for working with azure functions
MIT License
267 stars 118 forks source link

Question on the AZF image and dependencies being restored #351

Open command0r opened 3 years ago

command0r commented 3 years ago

We're building Azure Durable Function that uses Python as the main language. The Docker image I found here takes .NET Core SDK 3.1 as a base image and restores the 'WebJobs.Script.WebHost' project. The question is, why do we need .NET SDK/Runtime here if the Function is Python-based:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS runtime-image
ARG HOST_VERSION

ENV PublishWithAspNetCoreTargetManifest=false

RUN BUILD_NUMBER=$(echo ${HOST_VERSION} | cut -d'.' -f 3) && \
    git clone --branch v${HOST_VERSION} https://github.com/Azure/azure-functions-host /src/azure-functions-host && \
    cd /src/azure-functions-host && \
    HOST_COMMIT=$(git rev-list -1 HEAD) && \
    dotnet publish -v q /p:BuildNumber=$BUILD_NUMBER /p:CommitHash=$HOST_COMMIT src/WebJobs.Script.WebHost/WebJobs.Script.WebHost.csproj -c Release --output /azure-functions-host --runtime linux-x64 && \
    mv /azure-functions-host/workers /workers && mkdir /azure-functions-host/workers && \
    rm -rf /root/.local /root/.nuget /src

The Docker manifest also takes Python later in the manifest and restores its dependencies as it should be. However, it seems like an enormous overhead which results in the container of almost 2Gb in size.

At the same time, whenever I create a project via the CLI (with the Docker image included) it generates a manifest like this:

FROM mcr.microsoft.com/azure-functions/python:3.0-python3.7

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

COPY requirements.txt /
RUN pip install -r /requirements.txt

COPY . /home/site/wwwroot

Yes, Azure Durable Functions for Python is in preview now. But is this a reason for the huge Docker manifest file with .NET Core and restoring 'WebJobs.Script.WebHost' ? Or my understanding is entirely wrong?

balag0 commented 3 years ago

Azure functions uses a language worker model where there is a separate language worker process for individual langugages apart from a single host process which manages the different triggers and bindings. The host process has a dependency on .Net and the language worker process is implemented in python.

Some more details under the "Optimized for your code section" at https://azure.microsoft.com/hu-hu/blog/introducing-azure-functions-2-0/

Hope this helps.