From 7a12b929dd387a9c223c9c4130d2458e4991f6ab Mon Sep 17 00:00:00 2001 From: nanxun Date: Fri, 3 Jul 2026 17:17:38 +0800 Subject: [PATCH] fix: use docker TARGETARCH for runtime-specific dotnet publish Removing RuntimeIdentifier from the csproj caused dotnet publish to produce ALL platform runtimes (20+) in the output, making runtime loading ambiguous and causing FileLoadException at startup. Instead of hardcoding the RID in the csproj, use Docker's built-in TARGETARCH ARG (injected automatically by buildx for multi-platform builds): amd64 -> -r linux-x64 arm64 -> -r linux-arm64 This ensures native deps (SQLitePCLRaw, EF Core) resolve to exactly one architecture per image, while keeping the csproj clean for local dev. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/LiveRecorder.WebApi/Dockerfile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/LiveRecorder.WebApi/Dockerfile b/src/LiveRecorder.WebApi/Dockerfile index 09c6c62..c355119 100644 --- a/src/LiveRecorder.WebApi/Dockerfile +++ b/src/LiveRecorder.WebApi/Dockerfile @@ -20,6 +20,13 @@ ENV HTTP_PROXY=${HTTP_PROXY} \ https_proxy=${https_proxy} \ no_proxy=${no_proxy} +# Map Docker TARGETARCH to .NET RID so native dependencies (SQLite, EF Core) +# resolve to the correct platform. Framework-dependent output — apphost stays +# at /p:UseAppHost=false. +ARG TARGETARCH +RUN DOTNET_RID=$(case "$TARGETARCH" in amd64) echo linux-x64 ;; arm64) echo linux-arm64 ;; *) echo "unknown: $TARGETARCH" >&2; exit 1 ;; esac) ; \ + echo "Building for TARGETARCH=$TARGETARCH -> RID=$DOTNET_RID" + COPY . . # Workaround for QEMU ARM64 emulation @@ -30,7 +37,7 @@ ENV DOTNET_GCConserveMemory=9 RUN dotnet restore "src/LiveRecorder.WebApi/LiveRecorder.WebApi.csproj" -p:RestoreUseStaticGraphEvaluation=true --disable-parallel || \ dotnet restore "src/LiveRecorder.WebApi/LiveRecorder.WebApi.csproj" -p:RestoreUseStaticGraphEvaluation=true --disable-parallel || \ dotnet restore "src/LiveRecorder.WebApi/LiveRecorder.WebApi.csproj" -p:RestoreUseStaticGraphEvaluation=true --disable-parallel -RUN dotnet publish "src/LiveRecorder.WebApi/LiveRecorder.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false /p:DebugType=None /p:DebugSymbols=false /maxcpucount:1 +RUN dotnet publish "src/LiveRecorder.WebApi/LiveRecorder.WebApi.csproj" -c Release -o /app/publish -r $DOTNET_RID /p:UseAppHost=false /p:DebugType=None /p:DebugSymbols=false /maxcpucount:1 FROM ${DOTNET_RUNTIME_IMAGE} AS runtime