Skip to content

Commit 3ed41df

Browse files
Cross-compile .NET efficiently for multi-arch images
1 parent e0f6366 commit 3ed41df

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ ARG TRUTHGATE_GID=1000
77

88
FROM ipfs/kubo:${KUBO_VERSION} AS kubo
99

10-
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-resolute AS build
10+
# Compile on the builder's native CPU while targeting the requested image
11+
# architecture. This avoids running the full .NET build under QEMU for ARM64.
12+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION}-resolute AS build
13+
ARG TARGETARCH
1114
WORKDIR /src
1215

1316
COPY TruthGate-Web/TruthGate-Web/TruthGate-Web.csproj TruthGate-Web/TruthGate-Web/
1417
COPY TruthGate-Web/TruthGate-Web.Client/TruthGate-Web.Client.csproj TruthGate-Web/TruthGate-Web.Client/
15-
RUN dotnet restore TruthGate-Web/TruthGate-Web/TruthGate-Web.csproj
18+
RUN dotnet restore TruthGate-Web/TruthGate-Web/TruthGate-Web.csproj --arch "${TARGETARCH}"
1619

1720
COPY . .
1821
RUN dotnet publish TruthGate-Web/TruthGate-Web/TruthGate-Web.csproj \
1922
--configuration Release \
23+
--arch "${TARGETARCH}" \
2024
--no-restore \
25+
--no-self-contained \
2126
--output /out \
2227
/p:UseAppHost=false
2328

0 commit comments

Comments
 (0)