From 93749be8bf57520d764264dbef007252883fe9a6 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 29 Sep 2023 17:36:58 +0200 Subject: [PATCH 1/3] Clear default Dockerfile assignments for `*PLATFORM` These kept Docker buildx from automatically building for multiple platforms. --- Dockerfile | 10 ++++++---- docs/docker.md | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 186bee70..87024fb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,8 @@ -ARG TARGETPLATFORM=linux/amd64 -ARG BUILDPLATFORM=${TARGETPLATFORM} +# TARGETPLATFORM and BUILDPLATFORM are automatically filled in by Docker buildx. +# They should not be set in the global scope manually. FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:6.0 AS builder -ARG TARGETPLATFORM - # Copy build context WORKDIR /TShock COPY . ./ @@ -12,6 +10,10 @@ COPY . ./ # Build and package release based on target architecture RUN dotnet build -v m WORKDIR /TShock/TShockLauncher + +# Make TARGETPLATFORM available to the container. +ARG TARGETPLATFORM + RUN \ case "${TARGETPLATFORM}" in \ "linux/amd64") export ARCH="linux-x64" \ diff --git a/docs/docker.md b/docs/docker.md index 0b89681b..ca018510 100644 --- a/docs/docker.md +++ b/docs/docker.md @@ -14,15 +14,15 @@ Open ports can also be passed through using `-p :`. For Example: ```bash -# Building the image -docker build -t tshock:linux-amd64 --build-arg TARGETPLATFORM=linux/amd64 . +# Building the image using buildx and loading it into docker +docker buildx build -t tshock:latest --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-amd64 \ + --rm -it tshock:latest \ -world /worlds/backflip.wld -motd "OMFG DOCKER" ``` @@ -33,7 +33,7 @@ Using `docker buildx`, you could build [multi-platform images](https://docs.dock 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 . +docker buildx build -t tshock:linux-arm64 --platform linux/arm64 --load . # Running the image docker run -p 7777:7777 -p 7878:7878 \ From 3ffe8e1274597151dee42a42f8df64a2f7b9a076 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 29 Sep 2023 17:13:00 +0200 Subject: [PATCH 2/3] Add CI for Docker images --- .github/workflows/ci-docker.yml | 25 +++++++++++++++++++++++++ docs/changelog.md | 1 + 2 files changed, 26 insertions(+) create mode 100644 .github/workflows/ci-docker.yml diff --git a/.github/workflows/ci-docker.yml b/.github/workflows/ci-docker.yml new file mode 100644 index 00000000..deb811a2 --- /dev/null +++ b/.github/workflows/ci-docker.yml @@ -0,0 +1,25 @@ +name: CI (Docker image) + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: 'recursive' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up buildx + uses: docker/setup-buildx-action@v3 + - name: Build image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/arm/v7,windows/amd64 + push: false + pull: true + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} diff --git a/docs/changelog.md b/docs/changelog.md index 035df8ad..3cb52f80 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -90,6 +90,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace) * Fixed typo in `/gbuff`. (@sgkoishi, #2955) * Rewrote the `.dockerignore` file into a denylist. (@timschumi) +* Added CI for Docker images. (@timschumi) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK) From a19ac72e0db7f37728f1ebaa1c4aaa4713642357 Mon Sep 17 00:00:00 2001 From: ZakFahey Date: Sun, 18 Feb 2024 11:36:26 -0800 Subject: [PATCH 3/3] Lazy initialize TextLog._logWriter There is an instance of this in SqlLog that's used as a backup, but since the StreamWriter is created in the constructor, the file is created too. This means that you'll get an empty text log created, every time a server starts up, even if you have text logs disabled. This is especially problematic when you have a multi-server setup with file write conflicts. --- TShockAPI/TextLog.cs | 14 +++++++++++--- docs/changelog.md | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/TShockAPI/TextLog.cs b/TShockAPI/TextLog.cs index 070c6c88..ae3bb29e 100644 --- a/TShockAPI/TextLog.cs +++ b/TShockAPI/TextLog.cs @@ -29,7 +29,8 @@ namespace TShockAPI /// public class TextLog : ILog, IDisposable { - private readonly StreamWriter _logWriter; + private readonly bool ClearFile; + private StreamWriter _logWriter; /// /// File name of the Text log @@ -44,7 +45,7 @@ namespace TShockAPI public TextLog(string filename, bool clear) { FileName = filename; - _logWriter = new StreamWriter(filename, !clear); + ClearFile = clear; } public bool MayWriteType(TraceLevel type) @@ -247,6 +248,10 @@ namespace TShockAPI { if (!MayWriteType(level)) return; + if (_logWriter is null) + { + _logWriter = new StreamWriter(FileName, !ClearFile); + } var caller = "TShock"; @@ -278,7 +283,10 @@ namespace TShockAPI public void Dispose() { - _logWriter.Dispose(); + if (_logWriter != null) + { + _logWriter.Dispose(); + } } } } diff --git a/docs/changelog.md b/docs/changelog.md index 035df8ad..ebb335cc 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -88,6 +88,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace) * Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace) * Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace) +* Fixed bug where when the `UseSqlLogs` config property is true, an empty log file would still get created. (@ZakFahey) * Fixed typo in `/gbuff`. (@sgkoishi, #2955) * Rewrote the `.dockerignore` file into a denylist. (@timschumi)