Skip to content

Commit c799af7

Browse files
Copilotjongalloway
andcommitted
Optimize Docker build with improved SSL handling and timeouts
Co-authored-by: jongalloway <[email protected]>
1 parent 7d3dd39 commit c799af7

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

deployment/docker/Dockerfile

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,60 @@
22
# Based on .NET 9 runtime and optimized for production deployment
33

44
# 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
66

7-
# Build stage
7+
# Build stage
88
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
99
WORKDIR /src
1010

11-
# Install ca-certificates
11+
# Install necessary certificates and tools
1212
RUN apt-get update && \
13-
apt-get install -y ca-certificates && \
13+
apt-get install -y ca-certificates curl && \
1414
update-ca-certificates && \
1515
rm -rf /var/lib/apt/lists/*
1616

17-
# Set environment variables for .NET
17+
# Set environment variables for .NET in containerized environments
1818
ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
1919
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
2024

21-
# Copy project files first for dependency resolution
25+
# Copy project files first
2226
COPY ["NLWebNet.sln", "./"]
2327
COPY ["src/NLWebNet/NLWebNet.csproj", "src/NLWebNet/"]
2428
COPY ["samples/Demo/NLWebNet.Demo.csproj", "samples/Demo/"]
2529
COPY ["samples/AspireHost/NLWebNet.AspireHost.csproj", "samples/AspireHost/"]
2630
COPY ["tests/NLWebNet.Tests/NLWebNet.Tests.csproj", "tests/NLWebNet.Tests/"]
2731
COPY ["NuGet.Config", "./"]
2832

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
4146
COPY . .
4247

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
4450
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 ===" && \
4859
dotnet publish "NLWebNet.Demo.csproj" -c Release --no-build -o /app/publish /p:UseAppHost=false
4960

5061
# Runtime stage

0 commit comments

Comments
 (0)