From 2fa95ff347677f9ef1cd2e22ccdd5b135f1983e0 Mon Sep 17 00:00:00 2001 From: Logan Bussell Date: Wed, 18 Oct 2023 12:37:09 -0700 Subject: [PATCH] Simplify .NET multi-platform Dockerfile (#301) * Improve dotnet multiplatform dockerfile * Use implicit TARGETPLATFORM --- worker/Dockerfile | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/worker/Dockerfile b/worker/Dockerfile index fff3913361..cdd31baecb 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -8,27 +8,16 @@ # docker buildx build --platform "linux/arm64/v8" . FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:7.0 as build ARG TARGETPLATFORM +ARG TARGETARCH ARG BUILDPLATFORM RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM" WORKDIR /source COPY *.csproj . -RUN case ${TARGETPLATFORM} in \ - "linux/amd64") ARCH=x64 ;; \ - "linux/arm64") ARCH=arm64 ;; \ - "linux/arm64/v8") ARCH=arm64 ;; \ - "linux/arm/v7") ARCH=arm ;; \ - esac \ - && dotnet restore -r linux-${ARCH} +RUN dotnet restore -a $TARGETARCH COPY . . -RUN case ${TARGETPLATFORM} in \ - "linux/amd64") ARCH=x64 ;; \ - "linux/arm64") ARCH=arm64 ;; \ - "linux/arm64/v8") ARCH=arm64 ;; \ - "linux/arm/v7") ARCH=arm ;; \ - esac \ - && dotnet publish -c release -o /app -r linux-${ARCH} --self-contained false --no-restore +RUN dotnet publish -c release -o /app -a $TARGETARCH --self-contained false --no-restore # app image FROM mcr.microsoft.com/dotnet/runtime:7.0