From 906d405e435fb1c15eaa11311ecbb68d3b992986 Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Tue, 16 Dec 2025 08:19:41 +0100 Subject: [PATCH] Refactor to LiamAEdwards watchdog approach MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dockerfile: Download server from wylab CDN at build time, build watchdog - start.sh: Simplified to copy defaults and run watchdog - appsettings.yml: Configure for wylab instance with CDN manifest - main.yml: Simplified workflow with auto-tagging via metadata-action - Delete update_build_metadata.py (no longer needed) Based on: https://github.com/LiamAEdwards/SS14-Docker-Linux-Server 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .github/workflows/main.yml | 39 ++++++++++------ Dockerfile | 93 ++++++++++++++++++++------------------ appsettings.yml | 6 +-- start.sh | 10 ++++ 4 files changed, 83 insertions(+), 65 deletions(-) create mode 100644 start.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 40d189f..fa49163 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,7 +1,6 @@ # name: Build SS14 Watchdog Server -# Build on main branch (watchdog) - simpler build, no game source compilation on: push: branches: ['main'] @@ -21,7 +20,7 @@ jobs: packages: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -33,17 +32,24 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME || github.actor }} password: ${{ secrets.REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + flavor: | + suffix=-arm64 + - name: Build and push Docker image (arm64) uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: context: . platforms: linux/arm64 - cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-watchdog-arm64 - cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-watchdog-arm64,mode=max + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-arm64 + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-arm64,mode=max push: true - tags: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:arm64 - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} build-amd64: runs-on: [self-hosted, linux-amd64] @@ -53,7 +59,7 @@ jobs: packages: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -65,16 +71,19 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME || github.actor }} password: ${{ secrets.REGISTRY_PASSWORD || secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image (amd64) uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: context: . platforms: linux/amd64 - cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-watchdog-amd64 - cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-watchdog-amd64,mode=max + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-amd64 + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache-amd64,mode=max push: true - tags: | - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:amd64 - ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}-amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile index b52d8e5..eb277f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,62 +1,65 @@ -# -# SS14 Watchdog Docker Image -# Auto-updates game server from CDN manifest -# # syntax=docker/dockerfile:1.7 +# +# SS14 Watchdog Docker Image (based on LiamAEdwards/SS14-Docker-Linux-Server) +# Downloads game server from CDN and builds SS14.Watchdog +# -# Build stage - compile the watchdog +# Build stage FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build ARG TARGETPLATFORM -RUN apt-get update && \ - apt-get install -y --no-install-recommends git && \ - rm -rf /var/lib/apt/lists/* +# Update and install necessary tools +RUN apt-get -y update && \ + apt-get -y install curl unzip wget git jq -WORKDIR /src - -# Clone and build SS14.Watchdog -RUN git clone --recursive https://github.com/space-wizards/SS14.Watchdog.git watchdog - -WORKDIR /src/watchdog - -# Build for the target platform -RUN --mount=type=cache,target=/root/.nuget/packages \ - if [ "${TARGETPLATFORM:-linux/amd64}" = "linux/arm64" ]; then \ - RUNTIME="linux-arm64"; \ +# Determine platform RID based on Docker TARGETPLATFORM +RUN if [ "${TARGETPLATFORM:-linux/amd64}" = "linux/arm64" ]; then \ + echo "linux-arm64" > /tmp/platform_rid; \ else \ - RUNTIME="linux-x64"; \ + echo "linux-x64" > /tmp/platform_rid; \ fi && \ - dotnet publish SS14.Watchdog -c Release -r "$RUNTIME" --no-self-contained -o /app + echo "Building for platform: $(cat /tmp/platform_rid)" -# Runtime stage -FROM mcr.microsoft.com/dotnet/aspnet:9.0 +# Download and extract SS14 server from WYLAB CDN +RUN PLATFORM_RID=$(cat /tmp/platform_rid) && \ + SERVER_URL=$(curl -sL https://cdn.wylab.me/fork/wylab/manifest | \ + jq -r ".builds | to_entries | sort_by(.value.time) | last | .value.server.\"${PLATFORM_RID}\".url") && \ + echo "Downloading server from: $SERVER_URL" && \ + wget -O SS14.Server.zip "$SERVER_URL" && \ + unzip SS14.Server.zip -d /ss14-default/ -RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates && \ +# Download and build Watchdog +RUN PLATFORM_RID=$(cat /tmp/platform_rid) && \ + wget https://github.com/space-wizards/SS14.Watchdog/archive/refs/heads/master.zip -O Watchdog.zip && \ + unzip Watchdog.zip -d Watchdog && \ + cd Watchdog/SS14.Watchdog-master && \ + dotnet publish SS14.Watchdog -c Release -r "${PLATFORM_RID}" --no-self-contained -o /ss14-default/publish + +# Server stage +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS server + +# Copy from the build stage +COPY --from=build /ss14-default /ss14-default + +# Install necessary tools +RUN apt-get -y update && apt-get -y install unzip && \ rm -rf /var/lib/apt/lists/* -# Copy watchdog from build stage -COPY --from=build /app /app - -WORKDIR /app - -# Create instance directory structure -RUN mkdir -p /app/instances/wylab/data - -# Copy configuration files -COPY appsettings.yml /app/appsettings.yml -COPY server_config.toml /app/instances/wylab/config.toml - -# Expose ports -# 8080 = Watchdog API -# 1212 = Game server (TCP status + UDP game) -EXPOSE 8080/tcp +# Expose necessary ports EXPOSE 1212/tcp EXPOSE 1212/udp +EXPOSE 8080/tcp -# Volume for persistent data (game saves, database, etc.) -VOLUME ["/app/instances"] +# Set volume +VOLUME [ "/ss14" ] -# Run the watchdog -ENTRYPOINT ["./SS14.Watchdog"] +# Add configurations +COPY appsettings.yml /ss14-default/publish/appsettings.yml +COPY server_config.toml /ss14-default/publish/server_config.toml + +COPY start.sh /start.sh +RUN chmod +x /start.sh + +# Set the entry point for the container +ENTRYPOINT ["/start.sh"] diff --git a/appsettings.yml b/appsettings.yml index 27c0ff6..932111e 100644 --- a/appsettings.yml +++ b/appsettings.yml @@ -25,14 +25,10 @@ Serilog: AllowedHosts: "*" # Force Kestrel to bind to 0.0.0.0 (IPv4) instead of [::] (IPv6) -# This fixes the Host header issue with http://[::]:8080 Urls: "http://0.0.0.0:8080" # API URL your watchdog is accessible from. # This NEEDS to be reachable by the game server. -# If you don't want the watchdog to be public, -# do `http://localhost:8080/` here. -#BaseUrl: https://your.domain.com/watchdog/ BaseUrl: http://localhost:8080/ Servers: @@ -43,7 +39,7 @@ Servers: ApiPort: 1212 TimeoutSeconds: 120 - # Override the baseUrl to use localhost instead of [::] + # Override the baseUrl to use localhost EnvironmentVariables: ROBUST_CVAR_watchdog__baseUrl: "http://localhost:8080/" diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..94011f3 --- /dev/null +++ b/start.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Copy default files to volume on first run +if [ ! "$(ls -A /ss14)" ]; then + cp -r /ss14-default/* /ss14/ +fi + +# Run watchdog +cd /ss14/publish/ +exec ./SS14.Watchdog "$@"