Skip to content

Commit

Permalink
Cross-compile for arm64
Browse files Browse the repository at this point in the history
The .NET 7.0 SDK image for arm64 is broken.
  • Loading branch information
MarcusWichelmann committed May 7, 2023
1 parent e9890a3 commit 12fa82e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS publish
WORKDIR /src
COPY src/EnergyExporter/EnergyExporter.csproj EnergyExporter/
# The .NET SDK is broken on arm64, so we have to cross-compile instead.
FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim-amd64 AS publish

# Workaround from: https://github.com/dotnet/sdk/issues/28971#issuecomment-1308881150
ARG TARGETARCH
ARG TARGETOS
RUN arch=$TARGETARCH \
&& if [ "$arch" = "amd64" ]; then arch="x64"; fi \
&& echo $TARGETOS-$arch > /tmp/rid \
&& cat /tmp/rid

COPY src/EnergyExporter/EnergyExporter.csproj /src/EnergyExporter/
WORKDIR /src/EnergyExporter
RUN dotnet restore EnergyExporter.csproj
RUN dotnet restore EnergyExporter.csproj -r $(cat /tmp/rid)

COPY src/EnergyExporter/ .
RUN dotnet publish EnergyExporter.csproj -c Release -o /app/publish
RUN dotnet publish EnergyExporter.csproj -r $(cat /tmp/rid) -c Release -o /app/publish --no-self-contained --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
Expand Down

0 comments on commit 12fa82e

Please sign in to comment.