From be978927f6c10f9cd959061360b336c8edba84fe Mon Sep 17 00:00:00 2001 From: William Lewis Date: Mon, 23 Mar 2026 13:05:47 -0500 Subject: [PATCH] Added initial project --- Dockerfile | 39 ++++++++++++++++++ build_steps.md | 36 +++++++++++++++++ docker-compose.yml | 42 +++++++++++++++++++ docker-entrypoint.sh | 96 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+) create mode 100644 Dockerfile create mode 100644 build_steps.md create mode 100644 docker-compose.yml create mode 100644 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f948ff9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,39 @@ +FROM debian:bookworm-slim + +ENV DEBIAN_FRONTEND=noninteractive + +RUN dpkg --add-architecture i386 \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + socat \ + tini \ + winbind \ + xvfb \ + xauth \ + cabextract \ + unzip \ + wine \ + wine64 \ + wine32 \ + && rm -rf /var/lib/apt/lists/* + +ENV WINEPREFIX=/wineprefix +ENV WINEARCH=win64 +ENV WINEDEBUG=-all + +WORKDIR /opt/ns2 +COPY . /opt/ns2 + +RUN chmod +x /opt/ns2/docker-entrypoint.sh + +RUN mkdir -p /data/config /data/mods /data/logs \ + && mkdir -p "${WINEPREFIX}" \ + && xvfb-run -a wineboot -u + +EXPOSE 27015/udp 27016/udp 8080/tcp + +VOLUME ["/data"] + +ENTRYPOINT ["/usr/bin/tini","--","/opt/ns2/docker-entrypoint.sh"] diff --git a/build_steps.md b/build_steps.md new file mode 100644 index 0000000..b2bb53f --- /dev/null +++ b/build_steps.md @@ -0,0 +1,36 @@ +## Basic Build steps for local image + +```bash +docker system prune -a -f + +docker compose up --build +``` + + +## Tagging and pushing an image for VeritableValor/ns2-server-docker + +Assuming you built an image locally (example image name: ns2-server) and you want to push to Docker Hub under the repo VeritableValor/ns2-server-docker: + +### Log in (if not already): + +```bash +docker login gitea.veritablevalor.com +``` + +### Tag the image for Docker Hub (replace IMAGE_ID or local-name and VERSION as needed): + +```bash +docker tag local-image:tag gitea.veritablevalor.com/VeritableValor/ns2-server-docker:version +``` + +Or using image ID: + +```bash +docker tag gitea.veritablevalor.com/VeritableValor/ns2-server-docker:version +``` + +### Push: + +```bash +docker push gitea.veritablevalor.com/VeritableValor/ns2-server-docker:version +``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..929ad1d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,42 @@ +services: + ns2-dedicated: + # image: naturalselection2-ns2-dedicated + build: . + container_name: ns2-dedicated + restart: unless-stopped + environment: + NS2_IP: 0.0.0.0 + NS2_GAME_PORT: 27015 + NS2_INSECURE: "1" + NS2_WEBADMIN: "1" + NS2_WEB_PORT: 8080 + NS2_NAME: "NS2 Docker Server" + NS2_MAP: "ns2_summit" + NS2_LIMIT: 24 + NS2_CONFIG_PATH: "/data/config" + NS2_MODSTORAGE: "/data/mods" + NS2_LOGDIR: "/data/logs" + NS2_WEBUSER: "admin" + NS2_WEBPASSWORD: "admin" + # NS2_WEBUSERS_FILE: "/data/config/users.htpasswd" + ports: + - "27015:27015/udp" + - "27016:27016/udp" + - "8080:8080" + volumes: + - ./docker-data:/data + + # If you prefer passing command-line args directly instead of env vars: + # command: + # - -ip + # - 0.0.0.0 + # - -port + # - "27015" + # - -insecure + # - -webadmin + # - -webport + # - "80" + # - -name + # - "NS2 Docker Server" + # - -map + # - "ns2_summit" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..4771cb3 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +set -euo pipefail + +: "${NS2_GAME_PORT:=27015}" +: "${NS2_WEB_PORT:=8080}" +: "${NS2_WEB_INTERNAL_PORT:=8081}" +: "${NS2_IP:=0.0.0.0}" + +if [[ "${NS2_DEBUG:-0}" == "1" ]]; then + set -x +fi + +ARGS=() +ARGS+=("-ip" "${NS2_IP}") +ARGS+=("-port" "${NS2_GAME_PORT}") + +if [[ "${NS2_INSECURE:-0}" == "1" ]]; then + ARGS+=("-insecure") +fi + +if [[ "${NS2_WEBADMIN:-0}" == "1" ]]; then + ARGS+=("-webadmin" "-webport" "${NS2_WEB_INTERNAL_PORT}") +fi + +if [[ -n "${NS2_NAME:-}" ]]; then + ARGS+=("-name" "${NS2_NAME}") +fi + +if [[ -n "${NS2_MAP:-}" ]]; then + ARGS+=("-map" "${NS2_MAP}") +fi + +if [[ -n "${NS2_LIMIT:-}" ]]; then + ARGS+=("-limit" "${NS2_LIMIT}") +fi + +if [[ -n "${NS2_PASSWORD:-}" ]]; then + ARGS+=("-password" "${NS2_PASSWORD}") +fi + +if [[ -n "${NS2_WEBUSER:-}" ]]; then + ARGS+=("-webuser" "${NS2_WEBUSER}") +fi + +if [[ -n "${NS2_WEBPASSWORD:-}" ]]; then + ARGS+=("-webpassword" "${NS2_WEBPASSWORD}") +fi + +if [[ -n "${NS2_WEBDOMAIN:-}" ]]; then + ARGS+=("-webdomain" "${NS2_WEBDOMAIN}") +fi + +if [[ -n "${NS2_WEBUSERS_FILE:-}" ]]; then + ARGS+=("-webusers" "${NS2_WEBUSERS_FILE}") +fi + +if [[ -n "${NS2_MODSTORAGE:-}" ]]; then + ARGS+=("-modstorage" "${NS2_MODSTORAGE}") +fi + +if [[ -n "${NS2_CONFIG_PATH:-}" ]]; then + ARGS+=("-config_path" "${NS2_CONFIG_PATH}") +fi + +if [[ -n "${NS2_LOGDIR:-}" ]]; then + ARGS+=("-logdir" "${NS2_LOGDIR}") +fi + +cd /opt/ns2 + +if [[ "${NS2_WEBADMIN:-0}" == "1" ]] && [[ "${NS2_WEB_PROXY:-1}" == "1" ]]; then + if command -v socat >/dev/null 2>&1; then + echo "[ns2] starting web proxy: 0.0.0.0:${NS2_WEB_PORT} -> 127.0.0.1:${NS2_WEB_INTERNAL_PORT}" >&2 + socat TCP-LISTEN:"${NS2_WEB_PORT}",fork,reuseaddr,bind=0.0.0.0 TCP:127.0.0.1:"${NS2_WEB_INTERNAL_PORT}" & + else + echo "[ns2] warning: socat not installed; cannot start web proxy" >&2 + fi +fi + +WINE_BIN="" +if command -v wine64 >/dev/null 2>&1; then + WINE_BIN="wine64" +elif command -v wine >/dev/null 2>&1; then + WINE_BIN="wine" +else + echo "[ns2] error: wine executable not found in PATH" >&2 + exit 127 +fi + +if [[ $# -gt 0 ]]; then + echo "[ns2] launching: ${WINE_BIN} x64/Server.exe $*" >&2 + exec "${WINE_BIN}" x64/Server.exe "$@" +fi + +echo "[ns2] launching: ${WINE_BIN} x64/Server.exe ${ARGS[*]}" >&2 +exec "${WINE_BIN}" x64/Server.exe "${ARGS[@]}"