Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade, add dynamic protocol and hostname support #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 50 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
<div align="center">

![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)

</div>

### 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=<HTTP_PORT> -p <HTTP_PORT>: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:

Expand Down
13 changes: 0 additions & 13 deletions entrypoint.sh

This file was deleted.

22 changes: 22 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -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";
}
}
23 changes: 23 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -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