|
2 | 2 | # Based on .NET 9 runtime and optimized for production deployment |
3 | 3 |
|
4 | 4 | # Multi-stage Dockerfile for NLWebNet Demo Application |
5 | | -# Optimized to work around SSL certificate issues in containerized environments |
| 5 | +# Optimized for production deployment with SSL workarounds |
6 | 6 |
|
7 | | -# Build stage |
| 7 | +# Build stage |
8 | 8 | FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build |
9 | 9 | WORKDIR /src |
10 | 10 |
|
11 | | -# Install ca-certificates |
| 11 | +# Install necessary certificates and tools |
12 | 12 | RUN apt-get update && \ |
13 | | - apt-get install -y ca-certificates && \ |
| 13 | + apt-get install -y ca-certificates curl && \ |
14 | 14 | update-ca-certificates && \ |
15 | 15 | rm -rf /var/lib/apt/lists/* |
16 | 16 |
|
17 | | -# Set environment variables for .NET |
| 17 | +# Set environment variables for .NET in containerized environments |
18 | 18 | ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 |
19 | 19 | ENV NUGET_XMLDOC_MODE=skip |
| 20 | +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 |
| 21 | +ENV DOTNET_EnableWriteXorExecute=0 |
| 22 | +ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true |
| 23 | +ENV DOTNET_CLI_TELEMETRY_OPTOUT=true |
20 | 24 |
|
21 | | -# Copy project files first for dependency resolution |
| 25 | +# Copy project files first |
22 | 26 | COPY ["NLWebNet.sln", "./"] |
23 | 27 | COPY ["src/NLWebNet/NLWebNet.csproj", "src/NLWebNet/"] |
24 | 28 | COPY ["samples/Demo/NLWebNet.Demo.csproj", "samples/Demo/"] |
25 | 29 | COPY ["samples/AspireHost/NLWebNet.AspireHost.csproj", "samples/AspireHost/"] |
26 | 30 | COPY ["tests/NLWebNet.Tests/NLWebNet.Tests.csproj", "tests/NLWebNet.Tests/"] |
27 | 31 | COPY ["NuGet.Config", "./"] |
28 | 32 |
|
29 | | -# Try restore with fallback - if it fails, continue anyway |
30 | | -RUN echo "Attempting package restore..." && \ |
31 | | - export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 && \ |
32 | | - export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 && \ |
33 | | - export COMPlus_DisableEncryptedStateCache=1 && \ |
34 | | - (dotnet restore "samples/Demo/NLWebNet.Demo.csproj" --verbosity minimal || \ |
35 | | - (echo "Restore failed with SSL errors, attempting workaround..." && \ |
36 | | - dotnet nuget locals all --clear && \ |
37 | | - dotnet restore "samples/Demo/NLWebNet.Demo.csproj" --verbosity minimal --ignore-failed-sources) || \ |
38 | | - echo "All restore attempts failed, continuing with no-restore build...") |
39 | | - |
40 | | -# Copy source code |
| 33 | +# Attempt package restore with multiple fallback strategies |
| 34 | +# This addresses the SSL certificate validation issues common in Docker environments |
| 35 | +RUN echo "=== Attempting NuGet package restore ===" && \ |
| 36 | + echo "Strategy 1: Standard restore" && \ |
| 37 | + (timeout 60 dotnet restore "samples/Demo/NLWebNet.Demo.csproj" --verbosity minimal) || \ |
| 38 | + (echo "Strategy 2: Restore with --disable-parallel" && \ |
| 39 | + timeout 60 dotnet restore "samples/Demo/NLWebNet.Demo.csproj" --verbosity minimal --disable-parallel) || \ |
| 40 | + (echo "Strategy 3: Clear cache and retry" && \ |
| 41 | + dotnet nuget locals all --clear && \ |
| 42 | + timeout 60 dotnet restore "samples/Demo/NLWebNet.Demo.csproj" --verbosity minimal --ignore-failed-sources) || \ |
| 43 | + echo "All restore strategies failed due to SSL issues - will attempt build anyway" |
| 44 | + |
| 45 | +# Copy all source code |
41 | 46 | COPY . . |
42 | 47 |
|
43 | | -# Build and publish with no-restore fallback |
| 48 | +# Build and publish with fallback strategies |
| 49 | +# If restore failed, the build will automatically restore what it can |
44 | 50 | RUN cd samples/Demo && \ |
45 | | - echo "Building NLWebNet Demo application..." && \ |
46 | | - (dotnet build "NLWebNet.Demo.csproj" -c Release --no-restore --verbosity minimal || \ |
47 | | - dotnet build "NLWebNet.Demo.csproj" -c Release --verbosity minimal) && \ |
| 51 | + echo "=== Building NLWebNet Demo Application ===" && \ |
| 52 | + (echo "Attempting build with --no-restore..." && \ |
| 53 | + dotnet build "NLWebNet.Demo.csproj" -c Release --no-restore --verbosity minimal) || \ |
| 54 | + (echo "Build without restore failed, attempting with restore and shorter timeout..." && \ |
| 55 | + timeout 90 dotnet build "NLWebNet.Demo.csproj" -c Release --verbosity minimal) || \ |
| 56 | + (echo "Standard build failed, trying with ignore-failed-sources..." && \ |
| 57 | + timeout 90 dotnet build "NLWebNet.Demo.csproj" -c Release --verbosity minimal -p:RestoreIgnoreFailedSources=true) && \ |
| 58 | + echo "=== Publishing application ===" && \ |
48 | 59 | dotnet publish "NLWebNet.Demo.csproj" -c Release --no-build -o /app/publish /p:UseAppHost=false |
49 | 60 |
|
50 | 61 | # Runtime stage |
|
0 commit comments