Skip to content

Commit

Permalink
Multiarch dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonLucid committed Sep 30, 2020
1 parent c00ca2a commit d7da885
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ jobs:
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
platforms: linux/amd64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
29 changes: 23 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build

# See for all possible platforms
# https://github.com/containerd/containerd/blob/master/platforms/platforms.go#L17
ARG TARGETARCH

WORKDIR /source

# Copy csproj and restore.
COPY src/Impostor.Server/Impostor.Server.csproj ./src/Impostor.Server/Impostor.Server.csproj
COPY src/Impostor.Shared/Impostor.Shared.csproj ./src/Impostor.Shared/Impostor.Shared.csproj
COPY submodules/Hazel-Networking/Hazel/Hazel.csproj ./submodules/Hazel-Networking/Hazel/Hazel.csproj

RUN dotnet restore -r linux-musl-x64 ./src/Impostor.Server/Impostor.Server.csproj && \
dotnet restore -r linux-musl-x64 ./src/Impostor.Shared/Impostor.Shared.csproj && \
dotnet restore -r linux-musl-x64 ./submodules/Hazel-Networking/Hazel/Hazel.csproj
RUN case "$TARGETARCH" in \
amd64) NETCORE_PLATFORM='linux-x64';; \
arm64) NETCORE_PLATFORM='linux-arm64';; \
arm) NETCORE_PLATFORM='linux-arm';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac && \
dotnet restore -r "$NETCORE_PLATFORM" ./src/Impostor.Server/Impostor.Server.csproj && \
dotnet restore -r "$NETCORE_PLATFORM" ./src/Impostor.Shared/Impostor.Shared.csproj && \
dotnet restore -r "$NETCORE_PLATFORM" ./submodules/Hazel-Networking/Hazel/Hazel.csproj

# Copy everything else.
COPY submodules/. ./submodules/
COPY src/. ./src/
RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore ./src/Impostor.Server/Impostor.Server.csproj
RUN case "$TARGETARCH" in \
amd64) NETCORE_PLATFORM='linux-x64';; \
arm64) NETCORE_PLATFORM='linux-arm64';; \
arm) NETCORE_PLATFORM='linux-arm';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac && \
dotnet publish -c release -o /app -r "$NETCORE_PLATFORM" --no-restore ./src/Impostor.Server/Impostor.Server.csproj

# Final image.
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1-alpine
FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.1
WORKDIR /app
COPY --from=build /app ./
EXPOSE 22023/udp
Expand Down
1 change: 0 additions & 1 deletion src/Impostor.Server/Impostor.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win-x64;linux-x64;linux-musl-x64</RuntimeIdentifiers>
<PublishTrimmed>true</PublishTrimmed>
<AssemblyTitle>Impostor.Server</AssemblyTitle>
<Product>Impostor.Server</Product>
Expand Down

0 comments on commit d7da885

Please sign in to comment.