Merge remote-tracking branch 'potatocider/docker' into general-devel

This commit is contained in:
Lucas Nicodemus 2022-10-28 17:34:06 -07:00
commit e76b393689
No known key found for this signature in database
5 changed files with 108 additions and 0 deletions

15
.dockerignore Normal file
View file

@ -0,0 +1,15 @@
# ignore every file
*
# except for the ones required for building
!i18n/
!prebuilts/
!TerrariaServerAPI/
!TShockAPI/
!TShockLauncher/
!TShockLauncher.Tests/
!TShock.sln
# but exclude build artifacts
*/bin/
*/obj/

45
Dockerfile Normal file
View file

@ -0,0 +1,45 @@
ARG TARGETPLATFORM=linux/amd64
ARG BUILDPLATFORM=${TARGETPLATFORM}
FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:6.0 AS builder
ARG TARGETPLATFORM
# Copy build context
WORKDIR /TShock
COPY . ./
# Build and package release based on target architecture
RUN dotnet build -v m
WORKDIR /TShock/TShockLauncher
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 --platform=${TARGETPLATFORM} mcr.microsoft.com/dotnet/runtime:6.0 AS runner
WORKDIR /server
COPY --from=builder /TShock/TShockLauncher/output ./
VOLUME ["/tshock", "/worlds", "/plugins"]
EXPOSE 7777 7878
ENTRYPOINT [ \
"./TShock.Server", \
"-configpath", "/tshock", \
"-logpath", "/tshock/logs", \
"-crashdir", "/tshock/crashes", \
"-worldselectpath", "/worlds", \
"-additionalplugins", "/plugins" \
]

View file

@ -1,6 +1,7 @@
* [☕️⚡️ TShock documentation home](/) * [☕️⚡️ TShock documentation home](/)
* [Changelog](/changelog.md) * [Changelog](/changelog.md)
* [Command line parameters](/command-line-parameters.md) * [Command line parameters](/command-line-parameters.md)
* [Docker Setup](/docker.md)
* Subsystems * Subsystems
* [Tile providers](/tile-providers.md) * [Tile providers](/tile-providers.md)

View file

@ -70,6 +70,8 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Fix players being kicked after using the Flamethrower to apply the `OnFire3` debuff for `1200` ticks. (@BashGuy10) * Fix players being kicked after using the Flamethrower to apply the `OnFire3` debuff for `1200` ticks. (@BashGuy10)
* Fix being kicked for using the new sponge types on liquid. (@BashGuy10) * Fix being kicked for using the new sponge types on liquid. (@BashGuy10)
* Allow flask buffs to be applied on town npc due to the Flymeal. Add a permission could skip the buff detection. (@KawaiiYuyu) * Allow flask buffs to be applied on town npc due to the Flymeal. Add a permission could skip the buff detection. (@KawaiiYuyu)
* Dockerize TShock (@PotatoCider)
## TShock 4.5.18 ## TShock 4.5.18
* Fixed `TSPlayer.GiveItem` not working if the player is in lava. (@PotatoCider) * Fixed `TSPlayer.GiveItem` not working if the player is in lava. (@PotatoCider)

45
docs/docker.md Normal file
View file

@ -0,0 +1,45 @@
# Docker Setup
In order to run TShock in a docker container, you would need to have mountpoints for
- `/tshock` (TShock config files, logs and crash reports)
- `/worlds`
- `/plugins`
- `/server` (optional, if you want to mount TShock's cwd)
These folders can be mounted using `-v <host_folder>:<container>`
Open ports can also be passed through using `-p <host_port>:<container_port>`.
- `7777` for Terraria
- `7878` for TShock's REST API
For Example:
```bash
# Building the image
docker build -t tshock:linux-x64 --build-arg TARGETPLATFORM=linux-x64 .
# Running the image
docker run -p 7777:7777 -p 7878:7878 \
-v /home/cider/tshock/:/tshock \
-v /home/cider/.local/share/Terraria/Worlds:/worlds \
-v /home/cider/tshock/plugins:/plugins \
--rm -it tshock:linux-x64 \
-world /worlds/backflip.wld -motd "OMFG DOCKER"
```
## Building for Other Platforms
Using `docker buildx`, you could build [multi-platform images](https://docs.docker.com/build/building/multi-platform/) for TShock.
For Example:
```bash
# Building the image using buildx and loading it into docker
sudo docker buildx build -t tshock:linux-arm64 --platform linux/arm64 --load .
# Running the image
docker run -p 7777:7777 -p 7878:7878 \
-v /home/cider/tshock/:/tshock \
-v /home/cider/.local/share/Terraria/Worlds:/worlds \
-v /home/cider/tshock/plugins:/plugins \
--rm -it tshock:linux-arm64 \
-world /worlds/backflip.wld -motd "ARM64 ftw"
```