Add support for multi-platform builds with docker buildx

- also added docs
This commit is contained in:
Joseph Goh 2022-10-23 06:10:36 +08:00
parent d85efbad60
commit 108b19970b
No known key found for this signature in database
GPG key ID: 0C83392A0999DD5A
4 changed files with 33 additions and 20 deletions

View file

@ -1,32 +1,32 @@
FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:6.0 AS builder
# Docker Instructions
# Build Image:
# docker build -t tshock .
# and run:
# docker run -p 7777:7777 -p 7878:7878 \
# -v <save path>:/tshock \
# -v <world path>:/worlds \
# -v <plugin path>:/plugins \
# --rm -it tshock -world /worlds/<world file> <flags>
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS builder
ARG ARCH=linux-x64
ARG TARGETPLATFORM
# Copy build context
WORKDIR /TShock
COPY . ./
# Build and package release
RUN dotnet build
# Build and package release based on target architecture
RUN dotnet build -v m
WORKDIR /TShock/TShockLauncher
RUN dotnet publish -o output/ -r ${ARCH} -f net6.0 -c Release -p:PublishSingleFile=true --self-contained false
RUN case "${TARGETPLATFORM}" in \
"linux/amd64") export ARCH="linux-x64" \
;; \
"linux/arm64") export ARCH="linux-arm64" \
;; \
"linux/arm/v7") export ARCH="linux-arm" \
;; \
"windows/amd64") export ARCH="win-x64" \
;; \
*) echo "Error: Unsupported platform ${TARGETPLATFORM}" && exit 1 \
;; \
esac && \
dotnet publish -o output/ -r "${ARCH}" -v m -f net6.0 -c Release -p:PublishSingleFile=true --self-contained false
# Runtime image
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS runner
FROM --platform=${TARGETPLATFORM} mcr.microsoft.com/dotnet/runtime:6.0 AS runner
WORKDIR /server
COPY --from=builder /TShock/TShockLauncher/output ./
RUN mkdir -p /tshock /worlds /plugins
VOLUME ["/tshock", "/worlds", "/plugins"]
EXPOSE 7777 7878
@ -38,4 +38,4 @@ ENTRYPOINT [ \
"-crashdir", "/tshock/crashes", \
"-worldselectpath", "/worlds", \
"-additionalplugins", "/plugins" \
]
]