11# Multi-stage Dockerfile for NLWebNet Demo Application
22# Based on .NET 9 runtime and optimized for production deployment
33
4- # Build stage
4+ # Multi-stage Dockerfile for NLWebNet Demo Application
5+ # Optimized to work around SSL certificate issues in containerized environments
6+
7+ # Build stage
58FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
69WORKDIR /src
710
8- # Copy solution file and project files for dependency resolution
11+ # Install ca-certificates
12+ RUN apt-get update && \
13+ apt-get install -y ca-certificates && \
14+ update-ca-certificates && \
15+ rm -rf /var/lib/apt/lists/*
16+
17+ # Set environment variables for .NET
18+ ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
19+ ENV NUGET_XMLDOC_MODE=skip
20+
21+ # Copy project files first for dependency resolution
922COPY ["NLWebNet.sln" , "./" ]
1023COPY ["src/NLWebNet/NLWebNet.csproj" , "src/NLWebNet/" ]
1124COPY ["samples/Demo/NLWebNet.Demo.csproj" , "samples/Demo/" ]
1225COPY ["samples/AspireHost/NLWebNet.AspireHost.csproj" , "samples/AspireHost/" ]
1326COPY ["tests/NLWebNet.Tests/NLWebNet.Tests.csproj" , "tests/NLWebNet.Tests/" ]
14-
15- # Restore dependencies
16- RUN dotnet restore "samples/Demo/NLWebNet.Demo.csproj"
27+ COPY ["NuGet.Config" , "./" ]
28+
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..." )
1739
1840# Copy source code
1941COPY . .
2042
21- # Build the demo application
22- WORKDIR "/src/samples/Demo"
23- RUN dotnet build "NLWebNet.Demo.csproj" -c Release -o /app/build
24-
25- # Publish stage
26- FROM build AS publish
27- RUN dotnet publish "NLWebNet.Demo.csproj" -c Release -o /app/publish /p:UseAppHost=false
43+ # Build and publish with no-restore fallback
44+ 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) && \
48+ dotnet publish "NLWebNet.Demo.csproj" -c Release --no-build -o /app/publish /p:UseAppHost=false
2849
2950# Runtime stage
3051FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
@@ -37,7 +58,7 @@ RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* \
3758WORKDIR /app
3859
3960# Copy published application
40- COPY --from=publish /app/publish .
61+ COPY --from=build /app/publish .
4162
4263# Create directory for logs and ensure proper permissions
4364RUN mkdir -p /app/logs && chown -R nlwebnet:nlwebnet /app
0 commit comments