content: FROM nvidia/cuda:11.1-devel-ubuntu18.04 AS runtime-image
  
  ENV \
      # Enable detection of running in a container
      DOTNET_RUNNING_IN_CONTAINER=true \
      # Enable correct mode for dotnet watch (only mode supported in a container)
      DOTNET_USE_POLLING_FILE_WATCHER=true \
      # Skip extraction of XML docs - generally not useful within an image/container - helps performance
      NUGET_XMLDOC_MODE=skip \
      # PowerShell telemetry for docker image usage
      POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetCoreSDK-Ubuntu-18.04
  
  # Install .NET CLI dependencies
  RUN apt-get update \
      && apt-get install -y --no-install-recommends \
          libc6 \
          libgcc1 \
          libgssapi-krb5-2 \
          libicu60 \
          libssl1.1 \
          libstdc++6 \
          zlib1g \
          curl \
          git \
      && rm -rf /var/lib/apt/lists/*
  
  # Install .NET Core SDK
  RUN dotnet_sdk_version=3.1.404 \
      && curl -SL --output dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$dotnet_sdk_version/dotnet-sdk-$dotnet_sdk_version-linux-x64.tar.gz \
      && dotnet_sha512='94d8eca3b4e2e6c36135794330ab196c621aee8392c2545a19a991222e804027f300d8efd152e9e4893c4c610d6be8eef195e30e6f6675285755df1ea49d3605' \
      && echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \
      && mkdir -p /usr/share/dotnet \
      && tar -ozxf dotnet.tar.gz -C /usr/share/dotnet \
      && rm dotnet.tar.gz \
      && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
      # Trigger first run experience by running arbitrary cmd
      && dotnet help
  
  # Install PowerShell global tool
  RUN powershell_version=7.0.3 \
      && curl -SL --output PowerShell.Linux.x64.$powershell_version.nupkg https://pwshtool.blob.core.windows.net/tool/$powershell_version/PowerShell.Linux.x64.$powershell_version.nupkg \
      && powershell_sha512='580f405d26df40378f3abff3ec7e4ecaa46bb0e46bcb2b3c16eff2ead28fde5aaa55c19501f73315b454e68d98c9ef49f8887c36e7c733d7c8ea3dd70977da2f' \
      && echo "$powershell_sha512  PowerShell.Linux.x64.$powershell_version.nupkg" | sha512sum -c - \
      && mkdir -p /usr/share/powershell \
      && dotnet tool install --add-source / --tool-path /usr/share/powershell --version $powershell_version PowerShell.Linux.x64 \
      && dotnet nuget locals all --clear \
      && rm PowerShell.Linux.x64.$powershell_version.nupkg \
      && ln -s /usr/share/powershell/pwsh /usr/bin/pwsh \
      && chmod 755 /usr/share/powershell/pwsh \
      # To reduce image size, remove the copy nupkg that nuget keeps.
      && find /usr/share/powershell -print | grep -i '.*[.]nupkg$' | xargs rm
  
  # Build the Azure Function Runtime from source
  ARG HOST_VERSION=3.0.15149
  
  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
  
  RUN EXTENSION_BUNDLE_VERSION=1.5.0 && \
      EXTENSION_BUNDLE_FILENAME=Microsoft.Azure.Functions.ExtensionBundle.1.5.0_linux-x64.zip && \
      apt-get update && \
      apt-get install -y gnupg wget unzip && \
      wget https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/$EXTENSION_BUNDLE_VERSION/$EXTENSION_BUNDLE_FILENAME && \
      mkdir -p /FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/$EXTENSION_BUNDLE_VERSION && \
      unzip /$EXTENSION_BUNDLE_FILENAME -d /FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/$EXTENSION_BUNDLE_VERSION && \
      rm -f /$EXTENSION_BUNDLE_FILENAME && \
      EXTENSION_BUNDLE_VERSION_V2=2.4.0 && \
      EXTENSION_BUNDLE_FILENAME_V2=Microsoft.Azure.Functions.ExtensionBundle.${EXTENSION_BUNDLE_VERSION_V2}_linux-x64.zip && \
      wget https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/$EXTENSION_BUNDLE_VERSION_V2/$EXTENSION_BUNDLE_FILENAME_V2 && \
      mkdir -p /FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/$EXTENSION_BUNDLE_VERSION_V2 && \
      unzip /$EXTENSION_BUNDLE_FILENAME_V2 -d /FuncExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/$EXTENSION_BUNDLE_VERSION_V2 && \
      rm -f /$EXTENSION_BUNDLE_FILENAME_V2 &&\
      find /FuncExtensionBundles/ -type f -exec chmod 644 {} \;
  
  # Python 3.7 Installation with dependencies
  
  RUN apt-get update \
      && apt-get install -y --no-install-recommends software-properties-common \
      && add-apt-repository ppa:deadsnakes/ppa \
      && apt-get install -y python3.7 \
      && apt-get install -y libpython3.7-dev \
      && apt-get install -y python3-pip \
      && apt-get install -y python3-dev \
      && apt-get install -y cmake \
      && apt-get install -y pkg-config \
      && rm -rf /var/lib/apt/lists/*
  
  ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
  ENV PYTHON_VERSION 3.7.9
  
  # make some useful symlinks that are expected to exist
  RUN cd /usr/bin \
  	&& ln -s pydoc3.7 pydoc3 -f \
  	&& ln -s pygettext3.7 pygettext3 -f \
  	&& ln -s pip3 pip -f \
  	&& ln -s python3.7 python3 -f \
  	&& ln -s python3.7 python -f
  
  ENV LANG=C.UTF-8 \
      ACCEPT_EULA=Y \
      AzureWebJobsScriptRoot=/home/site/wwwroot \
      HOME=/home \
      FUNCTIONS_WORKER_RUNTIME=python \
      ASPNETCORE_URLS=http://+:80 \
      DOTNET_RUNNING_IN_CONTAINER=true \
      DOTNET_USE_POLLING_FILE_WATCHER=true \
      HOST_VERSION=${HOST_VERSION}
  
  # Install Python dependencies
  RUN apt-get update && \
      apt-get install -y wget && \
      apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9D6D8F6BC857C906 && \
      apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 && \
      echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \
      apt-get update && \
      apt-get install -y apt-transport-https curl gnupg && \
      curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
      curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
      # Needed for libss1.0.0 and in turn MS SQL
      echo 'deb http://security.debian.org/debian-security jessie/updates main' >> /etc/apt/sources.list && \
      # install necessary locales for MS SQL
      apt-get update && apt-get install -y locales && \
      echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen && \
      locale-gen && \
      # install MS SQL related packages
      apt-get update && \
      apt-get install -y unixodbc msodbcsql17 mssql-tools && \
      # .NET Core dependencies
      apt-get install -y --no-install-recommends ca-certificates \
      libc6 libgcc1 libgssapi-krb5-2 libicu60 libssl1.1 libstdc++6 zlib1g && \
      rm -rf /var/lib/apt/lists/* && \
      # Custom dependencies:
      #  OpenCV dependencies:
      apt-get update && \
      apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender-dev && \
      #  binutils
      apt-get install -y binutils && \
      #  OpenMP dependencies
      apt-get install -y libgomp1 && \
      # mysql dependencies
      apt-get install -y default-libmysqlclient-dev
  
  RUN mv /workers /azure-functions-host
  
  ENV FUNCTIONS_WORKER_RUNTIME_VERSION=3.7
  
  CMD [ "/azure-functions-host/Microsoft.Azure.WebJobs.Script.WebHost" ]
  
  