Hi all,
I'm new to Azure functions and Keda, but I have working experience with k8s - appreciate some assistance in below description.
INFO
me@localhost โค dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: arch
OS Version:
OS Platform: Linux
RID: arch-x64
Base Path: /usr/share/dotnet/sdk/3.1.100/
Host (useful for support):
Version: 3.1.0
Commit: 6e49edcd54
.NET Core SDKs installed:
2.1.803 [/usr/share/dotnet/sdk]
2.2.109 [/usr/share/dotnet/sdk]
3.0.102 [/usr/share/dotnet/sdk]
3.1.100 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.NETCore.App 2.1.15 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
me@localhost โค func --version
2.7.2045
Description:
Trying to deploy my dockerized dotNet function app on k8s, the app uses a custom dockerfile that facilitates the acquisition of credentials to restore NuGet packages hosted on private server feed with the help of Azure Artifacts Credential Provider plugin.
Problem:
Using the command func kubernetes deploy --name some-func-app --registry DOMAIN.azurecr.io --dotnet
Will fail because there is no build args being passed to the consumed docker build command by func kubernetes deploy parent command.
Dockerfile
Here is my docker file
# Downloading the dotnet sdk image. Could be any docker sdk image with sdk > 2.1.500
FROM microsoft/dotnet:2.2-sdk AS dotnet-builder
ARG PROJECT
ARG FEED_URL
ARG PAT
# Download and install latest credential provider. Not required after https://github.com/dotnet/dotnet-docker/issues/878
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
WORKDIR /src
# Optional: Sometimes the http client hangs because of a .NEt issue. Setting this in dockerfile helps
ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER 0
# Environment variable to enable seesion token cache. More on this here: https://github.com/Microsoft/artifacts-credprovider#help
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
# Add "FEED_URL" AND "PAT" using --build-arg in docker build step. "endpointCredentials" field is an array, you can add multiple endpoint configurations.
# Make sure that you *do not* hard code the "PAT" here. That is a sensitive information and must not be checked in.
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{\"endpointCredentials\": [{\"endpoint\":\"${FEED_URL}\", \"username\":\"azure_user\", \"password\":\"${PAT}\"}]}"
# Force NuGet to use basic authentication
ENV NUGET_AUTHENTICATION_TYPES basic
# Copy project files, use this if you have a nuget.config file with all the endpoints.
COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app/"${PROJECT}" \
&& mkdir -p /home/site/wwwroot \
&& dotnet publish *.csproj --output /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/dotnet:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY --from=dotnet-builder ["/home/site/wwwroot", "/home/site/wwwroot"]
Build
As you can see the function apps uses nuget packages that is stored in a private Artifacts server feed - This is how I get a build with docker
docker build . \
--build-arg PROJECT=FUNCTIONS-DIRECTORY-IN-REPO \
--build-arg FEED_URL=https://pkgs.dev.azure.com/DOMAIN/Packages/nuget/v3/index.json \
--build-arg PAT=${PAT} -t DOMAIN.azurecr.io/PROJECT_NAME:${IMAGE_TAG}
Run
And this is how I run it
docker run -it -p 7071:80 \
--env-file=./local.settings.env \
DOMAIN.azurecr.io/PROJECT_NAME:${IMAGE_TAG}
App Directory Strutcture
me@localhost โค tree -d -L 3
โ ~/code/SomeFunctionApp [develop|โฆ 5]
.
โโโ SomeFunctionApp
โย ย โโโ bin
โย ย โย ย โโโ Debug
โย ย โโโ Constants
โย ย โโโ Data
โย ย โย ย โโโ Entities
โย ย โย ย โโโ Exceptions
โย ย โย ย โโโ Incoming
โย ย โย ย โโโ Outgoing
โย ย โย ย โโโ Partials
โย ย โย ย โโโ Validators
โย ย โย ย โโโ ValueObjects
โย ย โโโ Functions
โย ย โโโ Helpers
โย ย โโโ obj
โย ย โย ย โโโ Debug
โย ย โโโ Repositories
โโโ SomeFunctionAppTests
โโโ Util
Instead of specifying --registry, which causes Functions Core Tools to run a docker build and push the resulting image to the registry, you can manually build the image by specifying custom build args and push it to the registry yourself.
Then you should be able to run kubernetes deploy --name some-func-app --image-name DOMAIN.azurecr.io/somefuncapp:latest to deploy it.
If you're having trouble, try dumping out the Kubernetes manifest by supplying the --dry-run flag. You can debug it, edit it to your needs, and run it manually.
Thanks @anthonychu
I was able to deploy the func app providing your answer with the --image-name parameter.
Cheers man
Most helpful comment
Instead of specifying
--registry, which causes Functions Core Tools to run a docker build and push the resulting image to the registry, you can manually build the image by specifying custom build args and push it to the registry yourself.Then you should be able to run
kubernetes deploy --name some-func-app --image-name DOMAIN.azurecr.io/somefuncapp:latestto deploy it.If you're having trouble, try dumping out the Kubernetes manifest by supplying the
--dry-runflag. You can debug it, edit it to your needs, and run it manually.