Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify .NET multi-platform Dockerfile #301

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
lbussell marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down