commit 60b57a07202b72fa8620ad17eb42dc1633486ae0 Author: Jerry Aldrich Date: Thu Jun 3 22:14:21 2021 -0700 Initial commit diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 0000000..738392e --- /dev/null +++ b/client/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:latest as build + +RUN apk add --no-cache git + +WORKDIR /src + +RUN git clone --depth=1 --recurse-submodules https://github.com/glennhartmann/quakejs + +FROM alpine:latest + +RUN apk add --no-cache lighttpd + +RUN chown -R lighttpd /var/log/lighttpd +COPY lighttpd.conf /etc/lighttpd/lighttpd.conf + +COPY --from=build /src/quakejs/html/ /srv/http/ +RUN chown -R lighttpd /srv + +COPY index.html.template /bootstrap/index.html.template +RUN chown -R lighttpd /bootstrap + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +USER lighttpd + +EXPOSE 8080 +ENTRYPOINT ["/entrypoint.sh"] +CMD ["lighttpd", "-D", "-f", "/etc/lighttpd/lighttpd.conf"] diff --git a/client/entrypoint.sh b/client/entrypoint.sh new file mode 100644 index 0000000..b29afd0 --- /dev/null +++ b/client/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# Exit on error +set -e + +sed -i "s/QUAKEJS_TAB_TITLE/${QUAKEJS_TAB_TITLE:=Quake JS}/" /bootstrap/index.html.template +sed -i "s/QUAKEJS_CONTENT_URL/${QUAKEJS_CONTENT_URL:=content.quakejs.com}/" /bootstrap/index.html.template +sed -i "s/QUAKEJS_SERVER_URL/$QUAKEJS_SERVER_URL/" /bootstrap/index.html.template + +if [ -n "$QUAKEJS_USE_SSL" ]; then + sed -i "s/'http:\/\/'/\'https:\/\/'/g" /srv/http/ioquake3.js + sed -i "s/'ws:\/\/'/\'wss:\/\/'/g" /srv/http/ioquake3.js +fi + +cp /bootstrap/index.html.template /srv/http/index.html + +lighttpd -D -f /etc/lighttpd/lighttpd.conf diff --git a/client/index.html.template b/client/index.html.template new file mode 100644 index 0000000..b58faee --- /dev/null +++ b/client/index.html.template @@ -0,0 +1,155 @@ + + + + QUAKEJS_TAB_TITLE + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + +
+ + diff --git a/client/lighttpd.conf b/client/lighttpd.conf new file mode 100644 index 0000000..fb02a50 --- /dev/null +++ b/client/lighttpd.conf @@ -0,0 +1,23 @@ +var.logdir = "/var/log/lighttpd" +var.statedir = "/var/lib/lighttpd" + +server.modules = ( + "mod_access", + "mod_accesslog", +) + +include "mime-types.conf" + +server.document-root = "/srv/http/" +server.pid-file = "/tmp/lighttpd.pid" + +server.errorlog-use-syslog = "enable" +accesslog.use-syslog = "enable" + +server.indexfiles = ("index.php", "index.html", "index.htm", "default.htm") + +server.port = 8080 + +url.access-deny = ("~", ".inc") + +server.network-backend = "writev" diff --git a/content/Dockerfile b/content/Dockerfile new file mode 100644 index 0000000..d959686 --- /dev/null +++ b/content/Dockerfile @@ -0,0 +1,24 @@ +FROM alpine:latest as build + +RUN apk add --no-cache bash wget jq + +WORKDIR /src + +RUN wget https://steamforge.net/files/quakejs/get_assets.sh + +RUN bash get_assets.sh + +FROM alpine:latest + +RUN apk add --no-cache lighttpd + +RUN chown -R lighttpd /var/log/lighttpd + +USER lighttpd + +COPY lighttpd.conf /etc/lighttpd/lighttpd.conf +COPY --from=build /src/assets /srv/http/assets + +EXPOSE 8080 + +CMD ["lighttpd", "-D", "-f", "/etc/lighttpd/lighttpd.conf"] diff --git a/content/lighttpd.conf b/content/lighttpd.conf new file mode 100644 index 0000000..fbec07f --- /dev/null +++ b/content/lighttpd.conf @@ -0,0 +1,28 @@ +var.logdir = "/var/log/lighttpd" +var.statedir = "/var/lib/lighttpd" + +server.modules = ( + "mod_access", + "mod_accesslog", + "mod_setenv", +) + +setenv.add-response-header = ( + "Access-Control-Allow-Origin" => "*", +) + +include "mime-types.conf" + +server.document-root = "/srv/http/" +server.pid-file = "/tmp/lighttpd.pid" + +server.errorlog-use-syslog = "enable" +accesslog.use-syslog = "enable" + +server.indexfiles = ("index.php", "index.html", "index.htm", "default.htm") + +server.port = 8080 + +url.access-deny = ("~", ".inc") + +server.network-backend = "writev" diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..a4381e4 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,30 @@ +version: "3.3" + +services: + content: + build: content/ + ports: + - "8080:8080" + server: + build: server/ + ports: + - "8888:27960" + client: + depends_on: + - content + - server + build: client/ + ports: + - "9999:8080" + environment: + - "QUAKEJS_CONTENT_URL=172.69.0.1:8080" + - "QUAKEJS_SERVER_URL=172.69.0.1:8888" + +# Prevent subnet conflict with OpenVPN +# Can connect to services via 172.69.0.1:PORT +networks: + default: + ipam: + driver: default + config: + - subnet: 172.69.0.0/16 diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 0000000..2d6edea --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,3 @@ +quakejs/ +server.cfg.override +rcon.cfg.override diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..5fc6a36 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,20 @@ +FROM node:16-alpine + +# Read the README...it's important (TL;DR: quakejs is .gitignore'd) +COPY quakejs /srv/quakejs + +COPY server.cfg.template /srv/server.cfg.template +COPY rcon.cfg.template /srv/rcon.cfg.template + +COPY entrypoint.sh /srv +RUN chmod +x /srv/entrypoint.sh + +RUN chown -R node /srv + +RUN mkdir /bootstrap +RUN chown -R node /bootstrap + +EXPOSE 27960 + +USER node +ENTRYPOINT ["/srv/entrypoint.sh"] diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..b93b312 --- /dev/null +++ b/server/README.md @@ -0,0 +1,19 @@ +# QuakeJS + +## Building quakejs and assets + +``` +git clone --recurse-submodules https://github.com/glennhartmann/quakejs.git + +cd quakejs +npm install +node build/ioq3ded.js +set fs_game baseq3 +set dedicated 1 +# Hold down/press enter until you see `Agreee? (y/n)` +# You read the EULA right? Right!?!...if so...enter `y` +# Then use ctrl+c to end the server +``` + +> If the date of the last commit in the above quakejs GitHub repo is after +> 2020-06-09, let Jerry know, he will be amused. Email: me@jerryaldrichiii.com + +After doing the above, `cd ..` then build the Docker image as you usually would diff --git a/server/entrypoint.sh b/server/entrypoint.sh new file mode 100644 index 0000000..62c4a53 --- /dev/null +++ b/server/entrypoint.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +set -e + +set_conf() { + echo "Setting: $1" + sed -i "s/$1/$2/" /srv/server.cfg.template +} + +if [ -f /bootstrap/server.cfg.override ]; then + echo "Config file override exists, copying to final location" + cp /bootstrap/server.cfg.override /srv/quakejs/base/baseq3/server.cfg +else + set_conf QUAKEJS_NETPORT ${QUAKEJS_NETPORT:=27960} + + set_conf QUAKEJS_HOSTNAME "${QUAKEJS_HOSTNAME:=Docker QuakeJS Server}" + set_conf QUAKEJS_MOTD "${QUAKEJS_MOTD:=DOCKER + QuakeJS = <3}" + + set_conf QUAKEJS_MAXCLIENTS ${QUAKEJS_MAXCLIENT:=12} + set_conf QUAKEJS_QUADFACTOR ${QUAKEJS_QUADEFACTOR:=3} + set_conf QUAKEJS_GAMETYPE ${QUAKEJS_GAMETYPE:=0} + set_conf QUAKEJS_TIMELIMIT ${QUAKEJS_TIMELIMIT:=10} + set_conf QUAKEJS_FRAGLIMIT ${QUAKEJS_FRAGLIMIT:=10} + set_conf QUAKEJS_WEAPONRESPAWN ${QUAKEJS_WEAPONRESPAWN:=3} + set_conf QUAKEJS_INACTIVITY ${QUAKEJS_INACTIVITY:=300} + set_conf QUAKEJS_FORCERESPAWN ${QUAKEJS_FORCERESPAWN:=0} + set_conf QUAKEJS_BOT_ENABLE ${QUAKEJS_BOT_ENABLE:=1} + + cp /srv/server.cfg.template /srv/quakejs/base/baseq3/server.cfg +fi + +if [ -f /bootstrap/rcon.cfg.override ]; then + echo "RCON config file override exists, copying to final location" + cp /bootstrap/rcon.cfg.override /srv/quakejs/base/baseq3/rcon.cfg +else + set_conf QUAKEJS_RCON_PASSWORD ${QUAKEJS_RCON_PASSWORD:=changemeorbehacked} + cp /srv/rcon.cfg.template /srv/quakejs/base/baseq3/rcon.cfg +fi + +cd /srv/quakejs + +node build/ioq3ded.js +set fs_game baseq3 +set dedicated 0 +exec server.cfg +exec rcon.cfg diff --git a/server/rcon.cfg.template b/server/rcon.cfg.template new file mode 100644 index 0000000..e3b12a7 --- /dev/null +++ b/server/rcon.cfg.template @@ -0,0 +1 @@ +seta rconPassword QUAKEJS_RCON_PASSWORD diff --git a/server/server.cfg.template b/server/server.cfg.template new file mode 100644 index 0000000..7c6690a --- /dev/null +++ b/server/server.cfg.template @@ -0,0 +1,24 @@ +seta net_port QUAKEJS_NETPORT +seta rconPassword QUAKEJS_RCON_PASSWORD + +seta sv_hostname QUAKEJS_HOSTNAME +seta g_motd QUAKEJS_MOTD + +seta sv_maxclients QUAKEJS_MAXCLIENTS +seta g_quadfactor QUAKEJS_QUADFACTOR +seta g_gametype QUAKEJS_GAMETYPE +seta timelimit QUAKEJS_TIMELIMIT +seta fraglimit QUAKEJS_FRAGLIMIT +seta g_weaponrespawn QUAKEJS_WEAPONRESPAWN +seta g_inactivity QUAKEJS_INACTIVITY +seta g_forcerespawn QUAKEJS_FORCERESPAWN +seta bot_enable QUAKEJS_BOT_ENABLE +set d1 "map q3dm1 ; set nextmap vstr d2" +set d2 "map q3dm7 ; set nextmap vstr d3" +set d3 "map q3dm17 ; set nextmap vstr d4" +set d4 "map pro-q3tourney2 ; set nextmap vstr d5" +set d5 "map pro-q3tourney4 ; set nextmap vstr d6" +set d6 "map pro-q3dm6 ; set nextmap vstr d7" +set d7 "map pro-q3dm13 ; set nextmap vstr d8" +set d8 "map q3tourney2 ; set nextmap vstr d1" +vstr d1