Azure / azure-functions-docker

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

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.). #128

Open dewanymca opened 4 years ago

dewanymca commented 4 years ago

Created a Service Topic Trigger function v2 using .net core and test it locally. Everything is working locally. Tried publishing the images locally on docker and run it , getting below error:

Log are attached


Microsoft Windows [Version 10.0.18362.239]
(c) 2019 Microsoft Corporation. All rights reserved.

D:\vsts\Repos\SC-DEL-FnL-ShipmentLite\UtilityFrameworkPackage>docker build -t uss/pocfn .
Sending build context to Docker daemon  37.85MB
Step 1/32 : FROM microsoft/dotnet:2.1-sdk AS installer-env
 ---> d3fad9b1ee71
Step 2/32 : FROM microsoft/dotnet:latest
 ---> 3af77ac73731
Step 3/32 : COPY . /app
 ---> e48f91d9d1bc
Step 4/32 : WORKDIR /app/source/Azure.Storage
 ---> Running in da721e2917a4
Removing intermediate container da721e2917a4
 ---> 1f50bca11c12
Step 5/32 : RUN ["dotnet", "restore"]
 ---> Running in db9e33af72ba
  Restore completed in 6.63 sec for /app/source/Azure.Storage/Azure.Storage.csproj.
Removing intermediate container db9e33af72ba
 ---> a2f54ea4baa9
Step 6/32 : WORKDIR /app/source/Microsoft.SupplyChain.Configuration
 ---> Running in d8df3559468f
Removing intermediate container d8df3559468f
 ---> 41153a43fa8a
Step 7/32 : RUN ["dotnet", "restore"]
 ---> Running in ffdb6b12e453
  Restore completed in 8.67 sec for /app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj.
Removing intermediate container ffdb6b12e453
 ---> 36af7335cda1
Step 8/32 : WORKDIR /app/source/Microsoft.SupplyChain.GDPR
 ---> Running in 0604523bc340
Removing intermediate container 0604523bc340
 ---> 7029cb4bbef1
Step 9/32 : RUN ["dotnet", "restore"]
 ---> Running in 9c1f35a5876c
  Restore completed in 679.89 ms for /app/source/Microsoft.SupplyChain.GDPR/Microsoft.SupplyChain.GDPR.csproj.
Removing intermediate container 9c1f35a5876c
 ---> 40bfba1012a2
Step 10/32 : WORKDIR /app/source/Function.TestHttpCircuitBreaker
 ---> Running in 3b0435e4c9e3
Removing intermediate container 3b0435e4c9e3
 ---> 1c8c1dcc233f
Step 11/32 : RUN dotnet build -c Release
 ---> Running in 6b82ec04fd93
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 116.03 ms for /app/source/Azure.Storage/Azure.Storage.csproj.
  Restore completed in 8.42 ms for /app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj.
  Restore completed in 2.82 ms for /app/source/Microsoft.SupplyChain.GDPR/Microsoft.SupplyChain.GDPR.csproj.
  Restore completed in 7.56 sec for /app/source/Microsoft.SupplyChain.Shipment.Http/Microsoft.SupplyChain.Shipment.Http.csproj.
/app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.Azure.ServiceBus 3.0.2 requires Microsoft.IdentityModel.Clients.ActiveDirectory (>= 3.17.2 && < 4.0.0) but version Microsoft.IdentityModel.Clients.ActiveDirectory 5.1.0 was resolved.
  Restore completed in 13.26 sec for /app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj.
/app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.Azure.ServiceBus 3.0.2 requires Microsoft.IdentityModel.Clients.ActiveDirectory (>= 3.17.2 && < 4.0.0) but version Microsoft.IdentityModel.Clients.ActiveDirectory 5.1.0 was resolved.
  Microsoft.SupplyChain.GDPR -> /app/source/Microsoft.SupplyChain.GDPR/bin/Release/netstandard2.0/Microsoft.SupplyChain.GDPR.dll
  Azure.Storage -> /app/source/Azure.Storage/bin/Release/netstandard2.0/Azure.Storage.dll
ServiceConfiguration.cs(203,21): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj]
ServiceConfiguration.cs(220,53): warning CS0168: The variable 'exp' is declared but never used [/app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj]
  Microsoft.SupplyChain.Configuration -> /app/source/Microsoft.SupplyChain.Configuration/bin/Release/netstandard2.0/Microsoft.SupplyChain.Configuration.dll
HttpClientDependency.cs(20,47): warning CS0649: Field 'HttpClientDependency._logger' is never assigned to, and will always have its default value null [/app/source/Microsoft.SupplyChain.Shipment.Http/Microsoft.SupplyChain.Shipment.Http.csproj]
  Microsoft.SupplyChain.Shipment.Http -> /app/source/Microsoft.SupplyChain.Shipment.Http/bin/Release/netstandard2.0/Microsoft.SupplyChain.Shipment.Http.dll
  Function.TestHttpCircuitBreaker -> /app/source/Function.TestHttpCircuitBreaker/bin/Release/netcoreapp2.1/bin/Function.TestHttpCircuitBreaker.dll

Build succeeded.

/app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.Azure.ServiceBus 3.0.2 requires Microsoft.IdentityModel.Clients.ActiveDirectory (>= 3.17.2 && < 4.0.0) but version Microsoft.IdentityModel.Clients.ActiveDirectory 5.1.0 was resolved.
/app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.Azure.ServiceBus 3.0.2 requires Microsoft.IdentityModel.Clients.ActiveDirectory (>= 3.17.2 && < 4.0.0) but version Microsoft.IdentityModel.Clients.ActiveDirectory 5.1.0 was resolved.
ServiceConfiguration.cs(203,21): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj]
ServiceConfiguration.cs(220,53): warning CS0168: The variable 'exp' is declared but never used [/app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj]
HttpClientDependency.cs(20,47): warning CS0649: Field 'HttpClientDependency._logger' is never assigned to, and will always have its default value null [/app/source/Microsoft.SupplyChain.Shipment.Http/Microsoft.SupplyChain.Shipment.Http.csproj]
    5 Warning(s)
    0 Error(s)

Time Elapsed 00:00:25.73
Removing intermediate container 6b82ec04fd93
 ---> 8b61b8b75f53
Step 12/32 : COPY . /src/dotnet-function-app
 ---> df377f85c364
Step 13/32 : RUN cd /src/dotnet-function-app &&     mkdir -p /home/site/wwwroot &&     dotnet publish /app/source/Function.TestHttpCircuitBreaker/*.csproj --output /home/site/wwwroot
 ---> Running in 71b498e83999
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

/app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.Azure.ServiceBus 3.0.2 requires Microsoft.IdentityModel.Clients.ActiveDirectory (>= 3.17.2 && < 4.0.0) but version Microsoft.IdentityModel.Clients.ActiveDirectory 5.1.0 was resolved.
  Restore completed in 127.52 ms for /app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj.
  Restore completed in 125.74 ms for /app/source/Azure.Storage/Azure.Storage.csproj.
  Restore completed in 24.28 ms for /app/source/Microsoft.SupplyChain.GDPR/Microsoft.SupplyChain.GDPR.csproj.
  Restore completed in 3.75 ms for /app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj.
  Restore completed in 9.36 ms for /app/source/Microsoft.SupplyChain.Shipment.Http/Microsoft.SupplyChain.Shipment.Http.csproj.
/app/source/Function.TestHttpCircuitBreaker/Function.TestHttpCircuitBreaker.csproj : warning NU1608: Detected package version outside of dependency constraint: Microsoft.Azure.ServiceBus 3.0.2 requires Microsoft.IdentityModel.Clients.ActiveDirectory (>= 3.17.2 && < 4.0.0) but version Microsoft.IdentityModel.Clients.ActiveDirectory 5.1.0 was resolved.
  Microsoft.SupplyChain.GDPR -> /app/source/Microsoft.SupplyChain.GDPR/bin/Debug/netstandard2.0/Microsoft.SupplyChain.GDPR.dll
  Azure.Storage -> /app/source/Azure.Storage/bin/Debug/netstandard2.0/Azure.Storage.dll
ServiceConfiguration.cs(203,21): warning CS4014: Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call. [/app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj]
ServiceConfiguration.cs(220,53): warning CS0168: The variable 'exp' is declared but never used [/app/source/Microsoft.SupplyChain.Configuration/Microsoft.SupplyChain.Configuration.csproj]
  Microsoft.SupplyChain.Configuration -> /app/source/Microsoft.SupplyChain.Configuration/bin/Debug/netstandard2.0/Microsoft.SupplyChain.Configuration.dll
HttpClientDependency.cs(20,47): warning CS0649: Field 'HttpClientDependency._logger' is never assigned to, and will always have its default value null [/app/source/Microsoft.SupplyChain.Shipment.Http/Microsoft.SupplyChain.Shipment.Http.csproj]
  Microsoft.SupplyChain.Shipment.Http -> /app/source/Microsoft.SupplyChain.Shipment.Http/bin/Debug/netstandard2.0/Microsoft.SupplyChain.Shipment.Http.dll
  Function.TestHttpCircuitBreaker -> /app/source/Function.TestHttpCircuitBreaker/bin/Debug/netcoreapp2.1/bin/Function.TestHttpCircuitBreaker.dll
  Function.TestHttpCircuitBreaker -> /home/site/wwwroot/
Removing intermediate container 71b498e83999
 ---> dcc6b563cfff
Step 14/32 : FROM mcr.microsoft.com/azure-functions/dotnet:2.0
 ---> e31042cea794
Step 15/32 : ENV AzureWebJobsScriptRoot = /home/site/wwwroot
 ---> Using cache
 ---> 522fccd2251a
Step 16/32 : ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true
 ---> Using cache
 ---> c499fd1b50b2
 ---> Using cache

 ---> Using cache
 ---> cae8e30c0260
Step 30/32 : RUN echo "$PWD"
 ---> Using cache
 ---> 464312a1a2cf
Step 31/32 : WORKDIR /home/site/wwwroot
 ---> Using cache
 ---> 6b851f3d770a
Step 32/32 : COPY . .
 ---> 0680b346e353
Successfully built 0680b346e353
Successfully tagged uss/pocfn:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

D:\vsts\Repos\SC-DEL-FnL-ShipmentLite\UtilityFrameworkPackage>docker run --rm -it uss/pocfn
info: Host.Startup[503]
      Initializing Host.
info: Host.Startup[504]
      Host initialization: ConsecutiveErrors=0, StartupCount=1
info: Host.General[513]
      Building host: startup suppressed:False, configuration suppressed: False
info: Host.Startup[204]
      No host configuration file found. Creating a default host.json file.
info: Host.Startup[205]
      Failed to create host.json file. Host execution will continue.
info: Host.Startup[201]
      Reading host configuration file '= /home/site/wwwroot/host.json'
info: Host.Startup[202]
      Host configuration file read:
      {
        "version": "2.0"
      }
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
      ApplicationInsightsLoggerOptions
      {
        "SamplingSettings": {
          "EvaluationInterval": "00:00:15",
          "InitialSamplingPercentage": 100.0,
          "MaxSamplingPercentage": 100.0,
          "MaxTelemetryItemsPerSecond": 20.0,
          "MinSamplingPercentage": 0.1,
          "MovingAverageRatio": 0.25,
          "SamplingPercentageDecreaseTimeout": "00:02:00",
          "SamplingPercentageIncreaseTimeout": "00:15:00"
        },
        "SnapshotConfiguration": null,
        "EnablePerformanceCountersCollection": true,
        "HttpAutoCollectionOptions": {
          "EnableHttpTriggerExtendedInfoCollection": true,
          "EnableW3CDistributedTracing": true,
          "EnableResponseHeaderInjection": true
        }
      }
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
      LoggerFilterOptions
      {
        "MinLevel": "None",
        "Rules": [
          {
            "ProviderName": null,
            "CategoryName": null,
            "LogLevel": null,
            "Filter": "<AddFilter>b__0"
          },
          {
            "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
            "CategoryName": null,
            "LogLevel": "None",
            "Filter": null
          },
          {
            "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
            "CategoryName": null,
            "LogLevel": null,
            "Filter": "<AddFilter>b__0"
          },
          {
            "ProviderName": "Microsoft.Azure.WebJobs.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider",
            "CategoryName": null,
            "LogLevel": "Trace",
            "Filter": null
          }
        ]
      }
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
      LoggerFilterOptions
      {
        "MinLevel": "None",
        "Rules": [
          {
            "ProviderName": null,
            "CategoryName": null,
            "LogLevel": null,
            "Filter": "<AddFilter>b__0"
          },
          {
            "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
            "CategoryName": null,
            "LogLevel": "None",
            "Filter": null
          },
          {
            "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
            "CategoryName": null,
            "LogLevel": null,
            "Filter": "<AddFilter>b__0"
          },
          {
            "ProviderName": "Microsoft.Azure.WebJobs.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider",
            "CategoryName": null,
            "LogLevel": "Trace",
            "Filter": null
          }
        ]
      }
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
      FunctionResultAggregatorOptions
      {
        "BatchSize": 1000,
        "FlushTimeout": "00:00:30",
        "IsEnabled": true
      }
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
      SingletonOptions
      {
        "LockPeriod": "00:00:15",
        "ListenerLockPeriod": "00:01:00",
        "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
        "LockAcquisitionPollingInterval": "00:00:05",
        "ListenerLockRecoveryPollingInterval": "00:01:00"
      }
info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0]
      HttpOptions
      {
        "DynamicThrottlesEnabled": false,
        "MaxConcurrentRequests": -1,
        "MaxOutstandingRequests": -1,
        "RoutePrefix": "api"
      }
info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0]
      Starting JobHost
info: Host.Startup[401]
      Starting Host (HostId=fc7efc7f502f-229690988, InstanceId=38d27b6d-f5d5-4d8c-b1ed-95998e561be7, Version=2.0.12612.0, ProcessId=1, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=)
info: Host.Startup[314]
      Loading functions metadata
info: Host.Startup[315]
      0 functions loaded
info: Host.Startup[0]
      Generating 0 job function(s)
warn: Host.Startup[0]
      No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
info: Host.Startup[412]
      Host initialized (209ms)
info: Host.Startup[413]
      Host started (261ms)
info: Host.Startup[0]
      Job host started
Hosting environment: Production
Content root path: /home/site/wwwroot
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
dewanymca commented 4 years ago

Can somebody help me?

rhwilburn commented 4 years ago

I have same issue with Node version of the docker container.

I have the following files in the /home/site/wwwroot:

host.json lendingApplication/function.json lendingApplication/lendingApplication.js

As with original post doing func start, works a charm (ie testing locally). The docker container shows the proper default webpage on localhost but the api url doesn't show response or webpage etc. I turned on logging in the container which showed the function isn't being discovered

Dockerfile:

FROM microsoft/azure-functions-node8:2.0
ENV AzureWebJobsScriptRoot=/home/site/wwwroot
ENV AzureFunctionsJobHost__Logging__Console__IsEnabled=true

EXPOSE 80

WORKDIR /usr/src/app

ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app/

WORKDIR /opt/app
ADD . /opt/app
RUN npm run build

WORKDIR /opt/app/dist
COPY . /home/site/wwwroot

RUN echo "Deployed site file are:"
RUN echo $PWD
RUN ls

Output from docker image logs

PS C:\Users\aksljdf\Documents\GitHub\asdfasdf\api\lendingApplication> docker run -p 4001:80 lendingapplication info: Host.Startup[503] Initializing Host. info: Host.Startup[504] Host initialization: ConsecutiveErrors=0, StartupCount=1 info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0] LoggerFilterOptions { "MinLevel": "None", "Rules": [ { "ProviderName": null, "CategoryName": null, "LogLevel": null, "Filter": "<AddFilter>b__0" }, { "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider", "CategoryName": null, "LogLevel": "None", "Filter": null }, { "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider", "CategoryName": null, "LogLevel": null, "Filter": "<AddFilter>b__0" } ] } info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0] FunctionResultAggregatorOptions { "BatchSize": 1000, "FlushTimeout": "00:00:30", "IsEnabled": true } info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0] SingletonOptions { "LockPeriod": "00:00:15", "ListenerLockPeriod": "00:01:00", "LockAcquisitionTimeout": "10675199.02:48:05.4775807", "LockAcquisitionPollingInterval": "00:00:05", "ListenerLockRecoveryPollingInterval": "00:01:00" } info: Microsoft.Azure.WebJobs.Hosting.OptionsLoggingService[0] HttpOptions { "DynamicThrottlesEnabled": false, "MaxConcurrentRequests": -1, "MaxOutstandingRequests": -1, "RoutePrefix": "api" } info: Microsoft.Azure.WebJobs.Hosting.JobHostService[0] Starting JobHost info: Host.Startup[401] Starting Host (HostId=ee9904c54a56-2137340777, InstanceId=834d4cba-9b2e-45e0-a3ca-fb1b9f972122, Version=2.0.12733.0, ProcessId=1, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=) info: Host.Startup[314] Loading functions metadata info: Host.Startup[315] 0 functions loaded info: Host.Startup[0] Generating 0 job function(s) warn: Host.Startup[0] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.). info: Host.Startup[412] Host initialized (53ms) info: Host.Startup[413] Host started (65ms) info: Host.Startup[0] Job host started Hosting environment: Production Content root path: /opt/app/dist Now listening on: http://[::]:80 Application started. Press Ctrl+C to shut down. info: Host.General[316] Host lock lease acquired by instance ID '000000000000000000000000555F7E28'.

rhwilburn commented 4 years ago

I fixed my issue, my DockerFile ended up as:


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

EXPOSE 80

# Create app directory
#WORKDIR /usr/src/app

# use changes to package.json to force Docker not to use the cache
# when we change our application's nodejs dependencies:
ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app/

# From here we load our application's code in, therefore the previous docker
# "layer" thats been cached will be used if possible
WORKDIR /opt/app
ADD . /opt/app
RUN npm run build

# Bundle app source
RUN mkdir -p /home/site/wwwroot/ && cp -a /opt/app/dist/. /home/site/wwwroot/

WORKDIR /home/site/wwwroot
RUN echo "Deployed site file are:"
RUN echo $PWD
RUN ls```

I took the following steps to debug:

1.I took my dist folder and used `func start` (Success)
2. I took my dist folder (ie bin equivilent), and wrapped that folder in a docker image (It reproduced issue)
3. I fixed that minimum container, then used that. It worked. (My issue was my folder structure was stuffed up in container due to being new with Docker).
4. Applied my fix to my full project

Its also super key to note the difference of 401 vs 404 exceptions, as functions by default are not anonymously viewable and return 401s which in Chrome can look fairly similar to 404s