Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
933 stars 194 forks source link

[Bug]: Docker build fails, requested .net version does not match the build container #2383

Open regtm opened 2 months ago

regtm commented 2 months ago

What happened?

When trying to build the Dockerfile the build process fails. The global.json does indeed require version 8.0.100:

docker build -f "Dockerfile" -t dataapibuilder:latest "."
[+] Building 0.3s (10/12)                                                                                                                             docker:default
 => [internal] load build definition from Dockerfile                                                                                                            0.0s
 => => transferring dockerfile: 578B                                                                                                                            0.0s
 => [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0-cbl-mariner2.0                                                                             0.1s
 => [internal] load metadata for mcr.microsoft.com/dotnet/sdk:6.0-cbl-mariner2.0.                                                                               0.1s
 => [internal] load .dockerignore                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                 0.0s
 => [build 1/4] FROM mcr.microsoft.com/dotnet/sdk:6.0-cbl-mariner2.0.@sha256:c3e1b51ec0d87798c598cef029aa3070bcfca299f419c09e3565a5cfdfb52c77                   0.0s
 => CACHED [runtime 1/3] FROM mcr.microsoft.com/dotnet/aspnet:6.0-cbl-mariner2.0@sha256:0281acf4da2032e112615ee4083b52bf7f103c4ddcb2878e14c313839d015930        0.0s
 => [internal] load build context                                                                                                                               0.0s
 => => transferring context: 208.38kB                                                                                                                           0.0s
 => CACHED [build 2/4] WORKDIR /src                                                                                                                             0.0s
 => CACHED [build 3/4] COPY [., ./]                                                                                                                             0.0s
 => ERROR [build 4/4] RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-x64                                       0.2s
------                                                                                                                                                               
 > [build 4/4] RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-x64:                                                  
0.105 The command could not be loaded, possibly because:                                                                                                             
0.105   * You intended to execute a .NET application:                                                                                                                
0.105       The application 'build' does not exist.                                                                                                                  
0.105   * You intended to execute a .NET SDK command:                                                                                                                
0.105       A compatible .NET SDK was not found.
0.105 
0.105 Requested SDK version: 8.0.100
0.105 global.json file: /src/global.json
0.105 
0.105 Installed SDKs:
0.105 
0.105 Install the [8.0.100] .NET SDK or update [/src/global.json] to match an installed SDK.
0.105 
0.105 Learn about SDK resolution:
0.105 https://aka.ms/dotnet/sdk-not-found
0.105 6.0.425 [/usr/share/dotnet/sdk]
------
Dockerfile:8
--------------------
   6 |     WORKDIR /src
   7 |     COPY [".", "./"]
   8 | >>> RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-x64
   9 |     
  10 |     FROM mcr.microsoft.com/dotnet/aspnet:6.0-cbl-mariner2.0 AS runtime
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet build \"./src/Service/Azure.DataApiBuilder.Service.csproj\" -c Docker -o /out -r linux-x64" did not complete successfully: exit code: 145
regtm commented 2 months ago

Bumping to mcr.microsoft.com/dotnet/sdk:8.0-cbl-mariner2.0 leads to what I assume to be dependency issues:

[build 4/4] RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-x64:                                                                                                       
0.476   Determining projects to restore...                                                                   
30.90   Restored /src/src/Product/Azure.DataApiBuilder.Product.csproj (in 29.74 sec).                        
63.26   Restored /src/src/Config/Azure.DataApiBuilder.Config.csproj (in 1.04 min).                           
63.26   Restored /src/src/Auth/Azure.DataApiBuilder.Auth.csproj (in 1.04 min).
63.27   Restored /src/src/Service.GraphQLBuilder/Azure.DataApiBuilder.Service.GraphQLBuilder.csproj (in 1.04 min).
100.3   Restored /src/src/Core/Azure.DataApiBuilder.Core.csproj (in 1.65 min).
185.5   Restored /src/src/Service/Azure.DataApiBuilder.Service.csproj (in 3.07 min).
185.6 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(251,5): warning NETSDK1201: For projects targeting .NET 8.0 and higher, specifying a RuntimeIdentifier will no longer produce a self contained app by default. To continue building self-contained apps, set the SelfContained property to true or use the --self-contained argument. [/src/src/Service/Azure.DataApiBuilder.Service.csproj::TargetFramework=net6.0]
186.7   Azure.DataApiBuilder.Product -> /out/Azure.DataApiBuilder.Product.dll
186.8   Azure.DataApiBuilder.Product -> /out/Azure.DataApiBuilder.Product.dll
187.3   Azure.DataApiBuilder.Config -> /out/Azure.DataApiBuilder.Config.dll
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018: System.IO.IOException: The process cannot access the file '/out/Azure.DataApiBuilder.Config.deps.json' because it is being used by another process. [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Init(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Int64& fileLength, UnixFileMode& filePermissions) [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException) [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at System.IO.File.Create(String path) [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath) [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.3 /usr/share/dotnet/sdk/8.0.401/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(284,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/src/src/Config/Azure.DataApiBuilder.Config.csproj::TargetFramework=net6.0]
187.5   Azure.DataApiBuilder.Auth -> /out/Azure.DataApiBuilder.Auth.dll
188.1   Azure.DataApiBuilder.Service.GraphQLBuilder -> /out/Azure.DataApiBuilder.Service.GraphQLBuilder.dll
189.1   Azure.DataApiBuilder.Core -> /out/Azure.DataApiBuilder.Core.dll
189.7   Azure.DataApiBuilder.Service -> /out/Azure.DataApiBuilder.Service.dll
189.7 
189.7 Build FAILED.
--------------------
   6 |     WORKDIR /src
   7 |     COPY [".", "./"]
   8 | >>> RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -c Docker -o /out -r linux-x64
   9 |     
  10 |     FROM mcr.microsoft.com/dotnet/aspnet:8.0-cbl-mariner2.0 AS runtime
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet build \"./src/Service/Azure.DataApiBuilder.Service.csproj\" -c Docker -o /out -r linux-x64" did not complete successfully: exit code: 1

Changing the build command to 'RUN dotnet build "./src/Service/Azure.DataApiBuilder.Service.csproj" -f net6.0 -c Docker -o /out -r linux-x64` does allow the build to succeed, but I run into trouble during execution, when accessing the api with token authentication:

Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[3]
      Exception occurred while processing message.
      System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://login.microsoftonline.com/{tenant-id}/v2.0/.well-known/openid-configuration'. Will retry at '09/13/2024 14:26:07 +00:00'. Exception: 'System.TypeLoadException: Could not load type 'Microsoft.IdentityModel.Json.JsonConvert' from assembly 'Microsoft.IdentityModel.Tokens, Version=7.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.Microsoft.IdentityModel.Protocols.IConfigurationRetriever<Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration>.GetConfigurationAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)'.
       ---> System.TypeLoadException: Could not load type 'Microsoft.IdentityModel.Json.JsonConvert' from assembly 'Microsoft.IdentityModel.Tokens, Version=7.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.Microsoft.IdentityModel.Protocols.IConfigurationRetriever<Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration>.GetConfigurationAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
         --- End of inner exception stack trace ---
         at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
         at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN6K000O3ICI", Request id "0HN6K000O3ICI:00000002": An unhandled exception was thrown by the application.
      System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://login.microsoftonline.com/{tenant-id}/v2.0/.well-known/openid-configuration'. Will retry at '09/13/2024 14:26:07 +00:00'. Exception: 'System.TypeLoadException: Could not load type 'Microsoft.IdentityModel.Json.JsonConvert' from assembly 'Microsoft.IdentityModel.Tokens, Version=7.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.Microsoft.IdentityModel.Protocols.IConfigurationRetriever<Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration>.GetConfigurationAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)'.
       ---> System.TypeLoadException: Could not load type 'Microsoft.IdentityModel.Json.JsonConvert' from assembly 'Microsoft.IdentityModel.Tokens, Version=7.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.Microsoft.IdentityModel.Protocols.IConfigurationRetriever<Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfiguration>.GetConfigurationAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
         at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
         --- End of inner exception stack trace ---
         at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
         at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
         at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
         at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.AuthenticateAsync()
         at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Azure.DataApiBuilder.Service.Startup.<>c__DisplayClass15_0.<<Configure>b__3>d.MoveNext() in /src/src/Service/Startup.cs:line 355
      --- End of stack trace from previous location ---
         at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
         at Azure.DataApiBuilder.Core.Services.PathRewriteMiddleware.InvokeAsync(HttpContext httpContext) in /src/src/Core/Services/PathRewriteMiddleware.cs:line 89
         at Azure.DataApiBuilder.Core.Services.CorrelationIdMiddleware.Invoke(HttpContext httpContext) in /src/src/Core/Services/CorrelationIdMiddleware.cs:line 53
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
regtm commented 2 months ago

After making the project single framework and setting the new images I can build the image as expected.

https://github.com/regtm/data-api-builder/commit/b9443e6ab23183939fdc3db525d64f969dd0b5e1