From 25e99ccfc819a37ecf1589655bdaaa4dc8230c1e Mon Sep 17 00:00:00 2001 From: Pat Hartl Date: Wed, 8 Apr 2026 17:03:51 -0500 Subject: [PATCH] Dockerfile with nightly workflow and sample compose file --- .dockerignore | 23 ++++++++++++++ .github/workflows/nightly-docker.yml | 47 ++++++++++++++++++++++++++++ Dockerfile | 45 ++++++++++++++++++++++++++ docker-compose.yml | 15 +++++++++ 4 files changed, 130 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/nightly-docker.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..153b2466 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +.git +.github +docs +proto +build +*.md +CREDITS +LICENSE + +# Build outputs +src/**/bin/ +src/**/obj/ + +# Test projects — not needed for the server image +src/MHServerEmu.Core.Tests/ +src/MHServerEmu.Games.Tests/ + +# Tools — separate solution, not part of the server +src/Tools/ + +# Debug symbols and XML docs +**/*.pdb +**/*.xml diff --git a/.github/workflows/nightly-docker.yml b/.github/workflows/nightly-docker.yml new file mode 100644 index 00000000..315e13cb --- /dev/null +++ b/.github/workflows/nightly-docker.yml @@ -0,0 +1,47 @@ +name: Nightly Docker Image + +on: + schedule: + - cron: '15 7 * * *' + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=schedule,pattern=nightly-{{date 'YYYYMMDD'}} + type=raw,value=nightly + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0a47c174 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +# Build stage +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /source + +# Copy dep DLLs and project files first to cache the restore layer +COPY dep/ dep/ +COPY src/Gazillion/Gazillion.csproj src/Gazillion/ +COPY src/MHServerEmu/MHServerEmu.csproj src/MHServerEmu/ +COPY src/MHServerEmu.Core/MHServerEmu.Core.csproj src/MHServerEmu.Core/ +COPY src/MHServerEmu.DatabaseAccess/MHServerEmu.DatabaseAccess.csproj src/MHServerEmu.DatabaseAccess/ +COPY src/MHServerEmu.Frontend/MHServerEmu.Frontend.csproj src/MHServerEmu.Frontend/ +COPY src/MHServerEmu.Games/MHServerEmu.Games.csproj src/MHServerEmu.Games/ +COPY src/MHServerEmu.Grouping/MHServerEmu.Grouping.csproj src/MHServerEmu.Grouping/ +COPY src/MHServerEmu.Leaderboards/MHServerEmu.Leaderboards.csproj src/MHServerEmu.Leaderboards/ +COPY src/MHServerEmu.PlayerManagement/MHServerEmu.PlayerManagement.csproj src/MHServerEmu.PlayerManagement/ +COPY src/MHServerEmu.WebFrontend/MHServerEmu.WebFrontend.csproj src/MHServerEmu.WebFrontend/ + +RUN dotnet restore src/MHServerEmu/MHServerEmu.csproj --runtime linux-x64 + +# Copy source and publish as self-contained linux-x64 +COPY src/ src/ + +RUN dotnet publish src/MHServerEmu/MHServerEmu.csproj \ + --no-restore \ + --configuration Release \ + --runtime linux-x64 \ + --self-contained true \ + --output /build/publish + +# Runtime stage — runtime-deps is sufficient for self-contained binaries +FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 +WORKDIR /build + +COPY --from=build /build/publish /server + +# Data directory holds the SQLite database, Config.ini overrides, and game assets. +# Mount a host directory here to persist player data across container restarts. +VOLUME ["/server"] + +# 4306 — game client frontend +# 8080 — web frontend / dashboard +EXPOSE 4306 +EXPOSE 8080 + +ENTRYPOINT ["./MHServerEmu"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..a8efdc30 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +services: + mhservereemu: + image: ghcr.io/crypto137/mhservereemu:nightly + container_name: mhservereemu + restart: unless-stopped + ports: + - "4306:4306" # Game client frontend + - "8080:8080" # Web frontend / dashboard + volumes: + # Persists the SQLite database, backups, and any other runtime data. + # Place your game asset files (CalligraphyData.sip, etc.) here before first run. + - mhservereemu-data:/server + +volumes: + mhservereemu-data: