Skip to content

Commit 4cfa80c

Browse files
Copilotjongalloway
andcommitted
Simplify Dockerfile to fix 30+ minute build timeout issue
Co-authored-by: jongalloway <[email protected]>
1 parent eca3c6f commit 4cfa80c

File tree

2 files changed

+16
-60
lines changed

2 files changed

+16
-60
lines changed

deployment/docker/Dockerfile

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,35 @@
11
# Multi-stage Dockerfile for NLWebNet Demo Application
22
# Based on .NET 9 runtime and optimized for production deployment
33

4-
# Multi-stage Dockerfile for NLWebNet Demo Application
5-
# Optimized for production deployment with SSL workarounds
6-
74
# Build stage
85
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
96
WORKDIR /src
107

11-
# Install necessary certificates and tools
12-
RUN apt-get update && \
13-
apt-get install -y ca-certificates curl && \
14-
update-ca-certificates && \
15-
rm -rf /var/lib/apt/lists/*
16-
17-
# Set environment variables for .NET in containerized environments
18-
ENV DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0
19-
ENV NUGET_XMLDOC_MODE=skip
20-
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
21-
ENV DOTNET_EnableWriteXorExecute=0
8+
# Set essential environment variables for .NET in containerized environments
229
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
2310
ENV DOTNET_CLI_TELEMETRY_OPTOUT=true
11+
ENV NUGET_XMLDOC_MODE=skip
2412

25-
# Copy project files first
13+
# Copy solution file and project files for dependency resolution
2614
COPY ["NLWebNet.sln", "./"]
2715
COPY ["src/NLWebNet/NLWebNet.csproj", "src/NLWebNet/"]
2816
COPY ["samples/Demo/NLWebNet.Demo.csproj", "samples/Demo/"]
2917
COPY ["samples/AspireHost/NLWebNet.AspireHost.csproj", "samples/AspireHost/"]
3018
COPY ["tests/NLWebNet.Tests/NLWebNet.Tests.csproj", "tests/NLWebNet.Tests/"]
31-
COPY ["NuGet.Config", "./"]
32-
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 with timeout" && \
37-
(timeout 45 dotnet restore "samples/Demo/NLWebNet.Demo.csproj" --verbosity minimal) || \
38-
(echo "Strategy 2: Restore with --disable-parallel" && \
39-
timeout 45 dotnet restore "samples/Demo/NLWebNet.Demo.csproj" --verbosity minimal --disable-parallel) || \
40-
(echo "Strategy 3: Clear cache and retry with ignore-failed-sources" && \
41-
dotnet nuget locals all --clear && \
42-
timeout 45 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
19+
20+
# Restore dependencies
21+
RUN dotnet restore "samples/Demo/NLWebNet.Demo.csproj"
22+
23+
# Copy source code
4624
COPY . .
4725

48-
# Build and publish with fallback strategies
49-
# If restore failed, the build will automatically restore what it can
50-
RUN cd samples/Demo && \
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 short timeout..." && \
55-
timeout 60 dotnet build "NLWebNet.Demo.csproj" -c Release --verbosity minimal) || \
56-
(echo "Standard build failed, trying with ignore-failed-sources..." && \
57-
timeout 60 dotnet build "NLWebNet.Demo.csproj" -c Release --verbosity minimal -p:RestoreIgnoreFailedSources=true) && \
58-
echo "=== Publishing application ===" && \
59-
dotnet publish "NLWebNet.Demo.csproj" -c Release --no-build -o /app/publish /p:UseAppHost=false
26+
# Build the demo application
27+
WORKDIR "/src/samples/Demo"
28+
RUN dotnet build "NLWebNet.Demo.csproj" -c Release -o /app/build
29+
30+
# Publish stage
31+
FROM build AS publish
32+
RUN dotnet publish "NLWebNet.Demo.csproj" -c Release -o /app/publish /p:UseAppHost=false
6033

6134
# Runtime stage
6235
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
@@ -69,7 +42,7 @@ RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* \
6942
WORKDIR /app
7043

7144
# Copy published application
72-
COPY --from=build /app/publish .
45+
COPY --from=publish /app/publish .
7346

7447
# Create directory for logs and ensure proper permissions
7548
RUN mkdir -p /app/logs && chown -R nlwebnet:nlwebnet /app

deployment/docker/NuGet.Docker.Config

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)