diff --git a/Dockerfile b/Dockerfile index 59243f7..ecf22da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,60 @@ -FROM ubuntu:20.04 +# Use current Ubuntu LTS as the base image +FROM ubuntu:latest -ARG DEBIAN_FRONTEND=noninteractive -ENV TZ=US/Eastern +# Update apt-get and install essential tools like curl, gpg, git, nginx, and supervisor +RUN apt-get update && \ + apt-get install -y curl gpg git nginx supervisor -RUN apt-get update -RUN apt-get upgrade -y +# Set Node.js major version for installation +ENV NODE_MAJOR=20 -RUN apt-get install sudo curl git nodejs npm jq apache2 wget apt-utils -y +# Add the NodeSource GPG key and repository for Node.js +RUN mkdir -p /etc/apt/keyrings && \ + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ + echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \ + apt-get update && apt-get install -y nodejs -RUN curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - - -RUN git clone --branch fix_module https://github.com/nerosketch/quakejs.git +# Set the working directory for the QuakeJS server WORKDIR /quakejs -RUN npm install -RUN ls -COPY server.cfg /quakejs/base/baseq3/server.cfg -COPY server.cfg /quakejs/base/cpma/server.cfg -# The two following lines are not necessary because we copy assets from include. Leaving them here for continuity. -# WORKDIR /var/www/html -# RUN bash /var/www/html/get_assets.sh + +# Clone the QuakeJS server repository and install dependencies +RUN git clone https://github.com/begleysm/quakejs . && \ + npm install + +# Copy server configuration files +COPY server.cfg /quakejs/base/baseq3/ +COPY server.cfg /quakejs/base/cpma/ + +# Replace the fixed JavaScript file for ioq3ded COPY ./include/ioq3ded/ioq3ded.fixed.js /quakejs/build/ioq3ded.js -RUN rm /var/www/html/index.html && cp /quakejs/html/* /var/www/html/ +# Modify the QuakeJS HTML to dynamically set the hostname and protocol for resources +RUN sed -i "s#'quakejs:[0-9]\+'#window.location.hostname#g" /quakejs/html/index.html && \ + sed -i "s#var url = 'http://' + fs_cdn + '/assets/manifest.json';#var url = '//' + window.location.host + '/assets/manifest.json';#" /quakejs/html/ioquake3.js && \ + sed -i "s#var url = 'http://' + root + '/assets/' + name;#var url = '//' + window.location.host + '/assets/' + name;#" /quakejs/html/ioquake3.js && \ + sed -i "s#var url = 'ws://' + addr + ':' + port;#var url = window.location.protocol.replace('http', 'ws') + window.location.host;#" /quakejs/html/ioquake3.js + +# Link QuakeJS to the nginx web root +RUN rm -rf /var/www/html && ln -s /quakejs/html /var/www/html + +# Copy game assets to the web root COPY ./include/assets/ /var/www/html/assets -RUN ls /var/www/html -WORKDIR / -ADD entrypoint.sh /entrypoint.sh -# Was having issues with Linux and Windows compatibility with chmod -x, but this seems to work in both -RUN chmod 777 ./entrypoint.sh +# Remove unnecessary packages to reduce image size +RUN apt-get purge curl gpg git -y && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Configure supervisord and nginx +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY nginx.conf /etc/nginx/sites-available/default + +# Create a non-root user for running the QuakeJS server +RUN groupadd -r quakejs && useradd -r -g quakejs quakejs + +# Set permissions for the QuakeJS server and web root +RUN chown -R quakejs:quakejs /quakejs /var/www/html -ENTRYPOINT ["/entrypoint.sh"] +# Start the supervisor daemon +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] diff --git a/README.md b/README.md index eff0bef..1b25136 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,58 @@
- + ![logo](https://github.com/treyyoder/quakejs-docker/blob/master/quakejs-docker.png?raw=true) -# quakejs-docker +# quakejs-docker ![Docker Image CI](https://github.com/treyyoder/quakejs-docker/workflows/Docker%20Image%20CI/badge.svg) +
-### A fully local and Dockerized quakejs server. Independent, unadulterated, and free from the middleman. +### A fully local and Dockerized quakejs server. Independent, unadulterated, and free from the middleman. The goal of this project was to create a fully independent quakejs server in Docker that does not require content to be served from the internet. Hence, once pulled, this does not need to connect to any external provider, ie. content.quakejs.com. Nor does this server need to be proxied/served/relayed from quakejs.com #### Simply pull the image [treyyoder/quakejs](https://hub.docker.com/r/treyyoder/quakejs) + ``` docker pull treyyoder/quakejs:latest ``` + #### and run it: ``` -docker run -d --name quakejs -e HTTP_PORT= -p :80 -p 27960:27960 treyyoder/quakejs:latest +docker run -d --name quakejs -p 8080:80 treyyoder/quakejs:latest ``` #### Example: ``` -docker run -d --name quakejs -e HTTP_PORT=8080 -p 8080:80 -p 27960:27960 treyyoder/quakejs:latest +docker run -d --name quakejs -p 8080:80 treyyoder/quakejs:latest ``` Send all you friends/coworkers the link: ex. http://localhost:8080 and start fragging ;) #### server.cfg: + Refer to [quake3world](https://www.quake3world.com/q3guide/servers.html) for instructions on its usage. #### docker-compose.yml + ``` version: '2' services: quakejs: container_name: quakejs - environment: - - HTTP_PORT=8080 ports: - '8080:80' - - '27960:27960' image: 'treyyoder/quakejs:latest' ``` #### Building the Image -After pulling the repo, change both `Dockerfile` and `entrypoint.sh` from CRLF to LF. Build the image with: -`docker build --add-host=content.quakejs.com:127.0.0.1 -t treyyoder/quakejs:latest .` +`docker build . -t treyyoder/quakejs:latest` ## Credits: diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 5ee3885..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -cd /var/www/html - -sed -i "s/'quakejs:/window.location.hostname + ':/g" index.html - -sed -i "s/':80'/':${HTTP_PORT}'/g" index.html - -/etc/init.d/apache2 start - -cd /quakejs - -node build/ioq3ded.js +set fs_game baseq3 set dedicated 1 +exec server.cfg diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..5d3cc28 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,22 @@ +server { + listen 80 default_server; + + root /var/www/html; + index index.html; + server_name _; + + location / { + try_files /nonexistent @$http_upgrade; + } + + location @ { + try_files $uri $uri/ =404; + } + + location @websocket { + proxy_pass http://localhost:27960; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } +} diff --git a/supervisord.conf b/supervisord.conf new file mode 100644 index 0000000..45dc867 --- /dev/null +++ b/supervisord.conf @@ -0,0 +1,23 @@ +[supervisord] +user=root +nodaemon=true +logfile=/dev/stdout +logfile_maxbytes=0 + +[program:nginx] +user=root +command=/usr/sbin/nginx -g 'daemon off;' +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:quakejs] +user=quakejs +directory=/quakejs +command=node /quakejs/build/ioq3ded.js +set fs_game baseq3 set dedicated 1 +exec server.cfg +autorestart=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0