From 1528f0a2b03a770537b7180d01ea48c6d7969402 Mon Sep 17 00:00:00 2001 From: Nathan Rashleigh Date: Tue, 10 Feb 2026 11:36:02 +1100 Subject: [PATCH] mapcycle and all --- .env | 2 +- Justfile | 46 ++-- docker-compose.yaml | 75 ----- etc/mariadb.dockerfile | 41 --- k8s.yaml | 275 +++++++++++++++++++ etc/cssds.dockerfile => src/cssds/Dockerfile | 8 +- {etc => src/cssds}/cfg/mapcycle.txt | 1 + {etc => src/cssds}/cfg/server.cfg | 0 {etc => src/cssds}/run.sh | 16 +- {etc => src/cssds}/update_cssds.txt | 0 {etc => src/cssds}/update_tf2ds.txt | 0 11 files changed, 319 insertions(+), 145 deletions(-) delete mode 100644 docker-compose.yaml delete mode 100755 etc/mariadb.dockerfile create mode 100644 k8s.yaml rename etc/cssds.dockerfile => src/cssds/Dockerfile (87%) rename {etc => src/cssds}/cfg/mapcycle.txt (50%) rename {etc => src/cssds}/cfg/server.cfg (100%) rename {etc => src/cssds}/run.sh (98%) rename {etc => src/cssds}/update_cssds.txt (100%) rename {etc => src/cssds}/update_tf2ds.txt (100%) diff --git a/.env b/.env index cdffbd6..220ff87 100644 --- a/.env +++ b/.env @@ -5,7 +5,7 @@ SRCDS_TOKEN=C02633B3395EA6BEF7D8DFBA440ABB7F SRCDS_RCONPW="reebok" SRCDS_PW="6" -SRCDS_STARTMAP="surf_boreas" +SRCDS_STARTMAP="surf_fornax" SRCDS_HOSTNAME="megastructure surf" SRCDS_MAXPLAYERS=16 diff --git a/Justfile b/Justfile index 6b0a9e6..fb5fc55 100644 --- a/Justfile +++ b/Justfile @@ -1,21 +1,3 @@ -build-css: - docker build -f css/css.dockerfile css/ -t megastructure/css - -up: - docker compose up --remove-orphans - -down: - docker compose down -v --remove-orphans - -build: - docker compose build - -cssds-run: - docker compose run -u root -it cssds bash - -cssds-exec: - docker compose exec -u root -it cssds bash - # Map downloader commands mapsdl-dry: cd src/mapsdl && deno run -A mapsdl.ts --dry-run @@ -28,3 +10,31 @@ mapsdl-all-dry: mapsdl-all: cd src/mapsdl && deno run -A mapsdl-all.ts --dry-run + +# k8s +build: + docker build -t megastructure-surf-cssds:local -t registry.ntwl.xyz/megastructure-surf-cssds src/cssds + docker build -t megastructure-surf-mapsdl:local -t registry.ntwl.xyz/megastructure-surf-mapsdl src/mapsdl + docker build -t megastructure-surf-fastdl:local -t registry.ntwl.xyz/megastructure-surf-fastdl src/fastdl + +push: + docker push registry.ntwl.xyz/megastructure-surf-cssds + docker push registry.ntwl.xyz/megastructure-surf-mapsdl + docker push registry.ntwl.xyz/megastructure-surf-fastdl + +build-cssds: + docker build -t megastructure-surf-cssds:local -t registry.ntwl.xyz/megastructure-surf-cssds src/cssds + +build-mapsdl: + docker build -t megastructure-surf-mapsdl:local -t registry.ntwl.xyz/megastructure-surf-mapsdl src/mapsdl + +build-fastdl: + docker build -t megastructure-surf-fastdl:local -t registry.ntwl.xyz/megastructure-surf-fastdl src/fastdl + +apply: + kubectl delete pod mapsdl -n surf --ignore-not-found + kubectl apply -f k8s.yaml + +env: + kubectl delete secret surf -n surf --ignore-not-found + kubectl create secret generic surf --from-env-file=.env -n surf diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 642c60d..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,75 +0,0 @@ -services: - cssds: - image: registry.ntwl.xyz/megastructure-surf - - build: - dockerfile: cssds.dockerfile - context: ./etc - - user: "1000:1000" - - env_file: - - .env - - # command: sleep 5000000 - - network_mode: host - - ports: - - "27015:27015" - - "27015:27015/udp" - - "27020:27020" - - volumes: - - ./etc:/home/steam/etc - - ./data/cssds:/home/steam/cssds - - tf2ds:/home/steam/tf2ds - - fastdl-maps:/fastdl/maps:ro - - db: - image: mariadb:12 - restart: always - ports: - - "3306:3306" - env_file: - - .env - - volumes: - - ./etc/mariadb/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d - - mapsdl: - image: registry.ntwl.xyz/megastructure-surf-mapsdl - - build: - context: ./src/mapsdl - dockerfile: Dockerfile - - volumes: - # Mount credentials (read-only) - - ./src/mapsdl/credentials:/app/credentials:ro - - # Output bz2 files to shared FastDL volume - - fastdl-maps:/maps - - environment: - - MAPS_DIR=/maps - - TEMP_DIR=/tmp/mapsdl - - GOOGLE_APPLICATION_CREDENTIALS=/app/credentials/service-account.json - - # Don't start automatically with docker-compose up - profiles: - - tools - - # Run once and exit - restart: "no" - - fastdl: - build: ./src/fastdl - ports: - - "8080:80" - volumes: - - fastdl-maps:/srv/maps:ro - -volumes: - tf2ds: - fastdl-maps: diff --git a/etc/mariadb.dockerfile b/etc/mariadb.dockerfile deleted file mode 100755 index 961c177..0000000 --- a/etc/mariadb.dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -FROM cm2network/steamcmd AS build -LABEL maintainer="ntr@megastructure.games" - -EXPOSE 27015/tcp \ - 27015/udp \ - 27020/udp - -USER root -RUN apt-get update -RUN apt-get install -y \ - wget \ - ca-certificates \ - zlib1g \ - lib32gcc-s1 \ - libncurses5 \ - libbz2-1.0 \ - libtinfo5 \ - libcurl3-gnutls \ - unzip \ - rcon - -ENV CSSDS="/home/steam/cssds" -ENV TF2DS="/home/steam/tf2ds" -ENV STEAMCMD="/home/steam/steamcmd" -ENV ETC="/home/steam/etc" -ENV METAMOD_VERSION=1.12 -ENV SOURCEMOD_VERSION=1.12 - -# ensure gamedirs exist and have been chowned to steam -# before they potentially get setup as docker volumes -# which would otherwise cause them to be owned by root -RUN mkdir -p "$CSSDS" "$TF2DS" "$STEAMCMD" "$ETC" -RUN chown -R steam:steam /home/steam - -FROM build AS steam - -USER steam -WORKDIR /home/steam - -COPY . /home/steam/etc -CMD ["bash", "./etc/run.sh"] \ No newline at end of file diff --git a/k8s.yaml b/k8s.yaml new file mode 100644 index 0000000..9e68af8 --- /dev/null +++ b/k8s.yaml @@ -0,0 +1,275 @@ +--- + +apiVersion: v1 +kind: Namespace +metadata: + name: surf + +# ----------------------------------------------------------------------- +# VOLUMES +# ----------------------------------------------------------------------- + +--- + +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: cssds-data + namespace: surf +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + +--- + +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: fastdl-maps + namespace: surf +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 5Gi + +# ----------------------------------------------------------------------- +# ENV (create/update with: just env) +# ----------------------------------------------------------------------- + +# ----------------------------------------------------------------------- +# CSSDS +# ----------------------------------------------------------------------- + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: cfg + namespace: surf +data: + mapcycle.txt: | + surf_anzchamps + surf_boreas + surf_deathstar + surf_ebony + surf_fornax + surf_garden + surf_in_space + surf_kepler + surf_kitsune + surf_kitsune2 + surf_lt_omnific + surf_pantheon + surf_utopia_njv + +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cssds + namespace: surf +spec: + replicas: 1 + selector: + matchLabels: + app: cssds + template: + metadata: + labels: + app: cssds + spec: + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + initContainers: + - name: fix-permissions + image: busybox + securityContext: + runAsUser: 0 + command: ['sh', '-c', 'chown -R 1000:1000 /home/steam/cssds'] + volumeMounts: + - name: cssds-data + mountPath: /home/steam/cssds + containers: + - name: cssds + image: megastructure-surf-cssds:local + imagePullPolicy: Never + ports: + - containerPort: 27015 + protocol: TCP + - containerPort: 27015 + protocol: UDP + - containerPort: 27020 + protocol: UDP + envFrom: + - secretRef: + name: surf + volumeMounts: + - name: src + mountPath: /home/steam/src + - name: cssds-data + mountPath: /home/steam/cssds + - name: fastdl-maps + mountPath: /fastdl/maps + readOnly: true + - name: cfg + mountPath: /home/steam/cfg + readOnly: true + volumes: + - name: src + hostPath: + path: /run/desktop/mnt/host/c/Users/ntr/code/surf_megastructure/src/cssds + - name: cssds-data + persistentVolumeClaim: + claimName: cssds-data + - name: fastdl-maps + persistentVolumeClaim: + claimName: fastdl-maps + - name: cfg + configMap: + name: cfg + +--- + +apiVersion: v1 +kind: Service +metadata: + name: cssds + namespace: surf +spec: + type: LoadBalancer + selector: + app: cssds + ports: + - name: game-tcp + protocol: TCP + port: 27015 + targetPort: 27015 + - name: game-udp + protocol: UDP + port: 27015 + targetPort: 27015 + - name: tv + protocol: UDP + port: 27020 + targetPort: 27020 + +# ----------------------------------------------------------------------- +# FASTDL +# ----------------------------------------------------------------------- + +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fastdl + namespace: surf +spec: + replicas: 1 + selector: + matchLabels: + app: fastdl + template: + metadata: + labels: + app: fastdl + spec: + containers: + - name: fastdl + image: megastructure-surf-fastdl:local + imagePullPolicy: Never + ports: + - containerPort: 80 + volumeMounts: + - name: fastdl-maps + mountPath: /srv/maps + readOnly: true + volumes: + - name: fastdl-maps + persistentVolumeClaim: + claimName: fastdl-maps + +--- + +apiVersion: v1 +kind: Service +metadata: + name: fastdl + namespace: surf +spec: + type: LoadBalancer + selector: + app: fastdl + ports: + - name: http + port: 8080 + targetPort: 80 + +# ----------------------------------------------------------------------- +# MAP DOWNLOADER (run manually: kubectl apply, then delete when done) +# ----------------------------------------------------------------------- + +--- + +apiVersion: v1 +kind: Pod +metadata: + name: mapsdl + namespace: surf +spec: + restartPolicy: Never + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + containers: + - name: mapsdl + image: megastructure-surf-mapsdl:local + imagePullPolicy: Never + command: ["deno", "run", "-A", "mapsdl.ts"] + env: + - name: MAPS_DIR + value: "/maps" + - name: TEMP_DIR + value: "/tmp/mapsdl" + - name: GOOGLE_APPLICATION_CREDENTIALS + value: "/app/credentials/service-account.json" + - name: MAPS_WISHLIST + value: | + surf_anzchamps + surf_boreas + surf_deathstar + surf_ebony + surf_fornax + surf_garden + surf_in_space + surf_kepler + surf_kitsune + surf_kitsune2 + surf_lt_omnific + surf_pantheon + surf_utopia_njv + volumeMounts: + - name: fastdl-maps + mountPath: /maps + - name: credentials + mountPath: /app/credentials + readOnly: true + volumes: + - name: fastdl-maps + persistentVolumeClaim: + claimName: fastdl-maps + - name: credentials + hostPath: + path: /run/desktop/mnt/host/c/Users/ntr/code/surf_megastructure/src/mapsdl/credentials + +--- diff --git a/etc/cssds.dockerfile b/src/cssds/Dockerfile similarity index 87% rename from etc/cssds.dockerfile rename to src/cssds/Dockerfile index 9cde55b..3cf9b8e 100644 --- a/etc/cssds.dockerfile +++ b/src/cssds/Dockerfile @@ -27,14 +27,14 @@ RUN apt-get update && apt-get install -y \ ENV CSSDS="/home/steam/cssds" ENV STEAMCMD="/home/steam/steamcmd" -ENV ETC="/home/steam/etc" +ENV SRC="/home/steam/src" ENV METAMOD_VERSION=1.12 ENV SOURCEMOD_VERSION=1.12 # ensure gamedirs exist and have been chowned to steam # before they potentially get setup as docker volumes # which would otherwise cause them to be owned by root -RUN mkdir -p "$CSSDS" "$STEAMCMD" "$ETC" +RUN mkdir -p "$CSSDS" "$STEAMCMD" "$SRC" RUN chown -R steam:steam /home/steam FROM build AS steam @@ -42,5 +42,5 @@ FROM build AS steam USER steam WORKDIR /home/steam -COPY . /home/steam/etc -CMD ["bash", "./etc/run.sh"] \ No newline at end of file +COPY . /home/steam/src +CMD ["bash", "./src/run.sh"] \ No newline at end of file diff --git a/etc/cfg/mapcycle.txt b/src/cssds/cfg/mapcycle.txt similarity index 50% rename from etc/cfg/mapcycle.txt rename to src/cssds/cfg/mapcycle.txt index 11cdfae..4c0f15f 100644 --- a/etc/cfg/mapcycle.txt +++ b/src/cssds/cfg/mapcycle.txt @@ -1 +1,2 @@ +surf_fornax surf_boreas diff --git a/etc/cfg/server.cfg b/src/cssds/cfg/server.cfg similarity index 100% rename from etc/cfg/server.cfg rename to src/cssds/cfg/server.cfg diff --git a/etc/run.sh b/src/cssds/run.sh similarity index 98% rename from etc/run.sh rename to src/cssds/run.sh index b513279..4eed120 100755 --- a/etc/run.sh +++ b/src/cssds/run.sh @@ -1,6 +1,6 @@ #! /bin/bash -set -uxe +set -ue # Parse command-line flags # By default, skip updates (set to 1) @@ -39,7 +39,7 @@ update_cssds() { fi cd $STEAMCMD - ./steamcmd.sh +runscript "$HOME/etc/update_cssds.txt" + ./steamcmd.sh +runscript "$HOME/src/update_cssds.txt" echo "--------------------------------------------------------------" echo "CSS DS is up to date" @@ -450,8 +450,8 @@ EOF cfg() { cd - cp etc/cfg/server.cfg cssds/cstrike/cfg/ - cp etc/cfg/mapcycle.txt cssds/cstrike/cfg/ + cp src/cfg/server.cfg cssds/cstrike/cfg/ + cp cfg/mapcycle.txt cssds/cstrike/cfg/ sed -i "s|sv_downloadurl .*|sv_downloadurl \"${FASTDL_URL:-}/cstrike/\"|" "$CSTRIKE/cfg/server.cfg" } @@ -504,13 +504,17 @@ populate_maps() { run_cssds() { - echo "ready to run" cd "$CSSDS" + local startmap="${SRCDS_STARTMAP:-}" + if [ -z "$startmap" ]; then + startmap=$(grep -v '^\s*\/\/' "$CSTRIKE/cfg/mapcycle.txt" | grep -m1 '\S') + fi + ./srcds_run -game cstrike \ -port "${SRCDS_PORT}" \ +maxplayers "${SRCDS_MAXPLAYERS}" \ - +map "${SRCDS_STARTMAP}" \ + +map "$startmap" \ -ip "${SRCDS_IP}" } diff --git a/etc/update_cssds.txt b/src/cssds/update_cssds.txt similarity index 100% rename from etc/update_cssds.txt rename to src/cssds/update_cssds.txt diff --git a/etc/update_tf2ds.txt b/src/cssds/update_tf2ds.txt similarity index 100% rename from etc/update_tf2ds.txt rename to src/cssds/update_tf2ds.txt