diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf38ceb..a87ad0b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,10 +3,12 @@ name: Build on: push: branches: - - "*" + - "**" + tags: + - '[0-9]+.[0-9]+.[0-9]+' pull_request: branches: - - "*" + - "**" types: [opened, synchronize, reopened] concurrency: @@ -168,10 +170,9 @@ jobs: name: Deploy artifacts needs: [build-win, build-linux, build-macos] runs-on: ubuntu-latest - if: github.event_name == 'push' && github.ref == 'refs/heads/master' + if: github.ref_type == 'tag' steps: - name: Setup main environment - if: github.ref == 'refs/heads/master' run: echo "ALTERWARE_MASTER_SERVER_PATH=${{ secrets.ALTERWARE_MASTER_SERVER_SSH_PATH }}" >> $GITHUB_ENV - name: Download Release binaries @@ -193,3 +194,61 @@ jobs: - name: Publish changes run: ssh ${{ secrets.ALTERWARE_MASTER_SERVER_SSH_USER }}@${{ secrets.ALTERWARE_MASTER_SERVER_SSH_ADDRESS }} ${{ secrets.ALTERWARE_SSH_SERVER_PUBLISH_COMMAND }} + + docker: + name: Create Docker Image + needs: [build-win, build-linux, build-macos] + runs-on: ubuntu-latest + if: github.ref_type == 'tag' + steps: + - name: Check out files + uses: actions/checkout@main + with: + sparse-checkout: | + Dockerfile + README.md + sparse-checkout-cone-mode: false + + - name: Download Release binaries + uses: actions/download-artifact@main + + - name: Compress Binaries + run: | + for dir in */; do + if [[ $dir == *"windows"* ]]; then + cd "$dir" && zip -r "../${dir%/}.zip" . && cd .. + else + tar -czvf "${dir%/}.tar.gz" -C "$dir" . + fi + done + shell: bash + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + + - name: Login to DockerHub + uses: docker/login-action@v3.1.0 + with: + username: ${{ secrets.DOCKERHUB_USER }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: | + alterware/master-server + tags: | + ${{ github.ref_name }} + latest + + - name: Build and Push Docker Image + id: build-and-push + uses: docker/build-push-action@v5.1.0 + with: + context: . + platforms: linux/amd64 + 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 0000000..571d90b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM ubuntu:latest + +RUN apt-get update +RUN apt-get install -y libc++-dev libcurl4-gnutls-dev + +COPY --chmod=755 ./linux-x64-release/alterware-master /usr/local/bin/ + +RUN groupadd alterware-master && useradd -r -g alterware-master alterware-master +USER alterware-master + +EXPOSE 20810/udp + +ENTRYPOINT ["/usr/local/bin/alterware-master"] diff --git a/README.md b/README.md index 89f918a..109cfbe 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,13 @@ # AlterWare: Master Server This is the master server our clients use. It is based on the DP Master Server (ID Tech) protocol +## Usage +Run using [Docker][docker-link] + +```bash +docker run -p 20810:20810/udp alterware/master-server:latest +``` + ## Build - Install [Premake5][premake5-link] and add it to your system PATH - Clone this repository using [Git][git-link] @@ -18,6 +25,7 @@ Requirements for Unix systems: - Customization: Modifications to the Premake5.lua script may be required - Platform support: Details regarding supported platforms are available in [build.yml][build-link] +[docker-link]: https://www.docker.com [premake5-link]: https://premake.github.io [git-link]: https://git-scm.com [mold-link]: https://github.com/rui314/mold diff --git a/src/crypto_key.cpp b/src/crypto_key.cpp index d2fe2b1..ed6bff9 100644 --- a/src/crypto_key.cpp +++ b/src/crypto_key.cpp @@ -36,7 +36,7 @@ namespace crypto_key if (!utils::io::write_file("./private.key", key.serialize())) { - throw std::runtime_error("Failed to write server key!"); + console::error("Failed to write server key!"); } console::info("Generated cryptographic key: %llX", key.get_hash()); diff --git a/src/services/kill_list.cpp b/src/services/kill_list.cpp index a349d95..bc6627a 100644 --- a/src/services/kill_list.cpp +++ b/src/services/kill_list.cpp @@ -142,8 +142,14 @@ void kill_list::write_to_disk() stream << entry.ip_address_ << " " << entry.reason_ << "\n"; } - utils::io::write_file(kill_file, stream.str(), false); - console::info("Wrote %s to disk (%zu entries)", kill_file, entries.size()); + if (utils::io::write_file(kill_file, stream.str(), false)) + { + console::info("Wrote %s to disk (%zu entries)", kill_file, entries.size()); + } + else + { + console::error("Failed to write %s!", kill_file); + } }); }