Skip to content

Commit 82aabe6

Browse files
committed
bump up base image and node, use begleysm fork, replace apache2 with nginx, add websocket endpoint, patch frontend for dynamic ssl support, add supervisord and non-root user, trim image and update docs
1 parent 96a5aeb commit 82aabe6

File tree

7 files changed

+109
-49
lines changed

7 files changed

+109
-49
lines changed

Dockerfile

+50-23
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,60 @@
1-
FROM ubuntu:20.04
1+
# Use current Ubuntu LTS as the base image
2+
FROM ubuntu:latest
23

3-
ARG DEBIAN_FRONTEND=noninteractive
4-
ENV TZ=US/Eastern
4+
# Update apt-get and install essential tools like curl, gpg, git, nginx, and supervisor
5+
RUN apt-get update && \
6+
apt-get install -y curl gpg git nginx supervisor
57

6-
RUN apt-get update
7-
RUN apt-get upgrade -y
8+
# Set Node.js major version for installation
9+
ENV NODE_MAJOR=20
810

9-
RUN apt-get install sudo curl git nodejs npm jq apache2 wget apt-utils -y
11+
# Add the NodeSource GPG key and repository for Node.js
12+
RUN mkdir -p /etc/apt/keyrings && \
13+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
14+
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 && \
15+
apt-get update && apt-get install -y nodejs
1016

11-
RUN curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
12-
13-
RUN git clone --branch fix_module https://github.com/nerosketch/quakejs.git
17+
# Set the working directory for the QuakeJS server
1418
WORKDIR /quakejs
15-
RUN npm install
16-
RUN ls
17-
COPY server.cfg /quakejs/base/baseq3/server.cfg
18-
COPY server.cfg /quakejs/base/cpma/server.cfg
19-
# The two following lines are not necessary because we copy assets from include. Leaving them here for continuity.
20-
# WORKDIR /var/www/html
21-
# RUN bash /var/www/html/get_assets.sh
19+
20+
# Clone the QuakeJS server repository and install dependencies
21+
RUN git clone https://github.com/begleysm/quakejs . && \
22+
npm install
23+
24+
# Copy server configuration files
25+
COPY server.cfg /quakejs/base/baseq3/
26+
COPY server.cfg /quakejs/base/cpma/
27+
28+
# Replace the fixed JavaScript file for ioq3ded
2229
COPY ./include/ioq3ded/ioq3ded.fixed.js /quakejs/build/ioq3ded.js
2330

24-
RUN rm /var/www/html/index.html && cp /quakejs/html/* /var/www/html/
31+
# Modify the QuakeJS HTML to dynamically set the hostname and protocol for resources
32+
RUN sed -i "s#'quakejs:[0-9]\+'#window.location.hostname#g" /quakejs/html/index.html && \
33+
sed -i "s#var url = 'http://' + fs_cdn + '/assets/manifest.json';#var url = '//' + window.location.host + '/assets/manifest.json';#" /quakejs/html/ioquake3.js && \
34+
sed -i "s#var url = 'http://' + root + '/assets/' + name;#var url = '//' + window.location.host + '/assets/' + name;#" /quakejs/html/ioquake3.js && \
35+
sed -i "s#var url = 'ws://' + addr + ':' + port;#var url = window.location.protocol.replace('http', 'ws') + window.location.host;#" /quakejs/html/ioquake3.js
36+
37+
# Link QuakeJS to the nginx web root
38+
RUN rm -rf /var/www/html && ln -s /quakejs/html /var/www/html
39+
40+
# Copy game assets to the web root
2541
COPY ./include/assets/ /var/www/html/assets
26-
RUN ls /var/www/html
2742

28-
WORKDIR /
29-
ADD entrypoint.sh /entrypoint.sh
30-
# Was having issues with Linux and Windows compatibility with chmod -x, but this seems to work in both
31-
RUN chmod 777 ./entrypoint.sh
43+
# Remove unnecessary packages to reduce image size
44+
RUN apt-get purge curl gpg git -y && \
45+
apt-get autoremove -y && \
46+
apt-get clean && \
47+
rm -rf /var/lib/apt/lists/*
48+
49+
# Configure supervisord and nginx
50+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
51+
COPY nginx.conf /etc/nginx/sites-available/default
52+
53+
# Create a non-root user for running the QuakeJS server
54+
RUN groupadd -r quakejs && useradd -r -g quakejs quakejs
55+
56+
# Set permissions for the QuakeJS server and web root
57+
RUN chown -R quakejs:quakejs /quakejs /var/www/html
3258

33-
ENTRYPOINT ["/entrypoint.sh"]
59+
# Start the supervisor daemon
60+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,58 @@
11
<div align="center">
2-
2+
33
![logo](https://github.com/treyyoder/quakejs-docker/blob/master/quakejs-docker.png?raw=true)
4-
# quakejs-docker
4+
# quakejs-docker
55

66
![Docker Image CI](https://github.com/treyyoder/quakejs-docker/workflows/Docker%20Image%20CI/badge.svg)
7+
78
</div>
89

9-
### A fully local and Dockerized quakejs server. Independent, unadulterated, and free from the middleman.
10+
### A fully local and Dockerized quakejs server. Independent, unadulterated, and free from the middleman.
1011

1112
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.
1213
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
1314

1415
#### Simply pull the image [treyyoder/quakejs](https://hub.docker.com/r/treyyoder/quakejs)
16+
1517
```
1618
docker pull treyyoder/quakejs:latest
1719
```
20+
1821
#### and run it:
1922

2023
```
21-
docker run -d --name quakejs -e HTTP_PORT=<HTTP_PORT> -p <HTTP_PORT>:80 -p 27960:27960 treyyoder/quakejs:latest
24+
docker run -d --name quakejs -p 8080:80 treyyoder/quakejs:latest
2225
```
2326

2427
#### Example:
2528

2629
```
27-
docker run -d --name quakejs -e HTTP_PORT=8080 -p 8080:80 -p 27960:27960 treyyoder/quakejs:latest
30+
docker run -d --name quakejs -p 8080:80 treyyoder/quakejs:latest
2831
```
2932

3033
Send all you friends/coworkers the link: ex. http://localhost:8080 and start fragging ;)
3134

3235
#### server.cfg:
36+
3337
Refer to [quake3world](https://www.quake3world.com/q3guide/servers.html) for instructions on its usage.
3438

3539
#### docker-compose.yml
40+
3641
```
3742
version: '2'
3843
services:
3944
quakejs:
4045
container_name: quakejs
41-
environment:
42-
- HTTP_PORT=8080
4346
ports:
4447
- '8080:80'
45-
- '27960:27960'
4648
image: 'treyyoder/quakejs:latest'
4749
```
4850

4951
#### Building the Image
50-
After pulling the repo, change both `Dockerfile` and `entrypoint.sh` from CRLF to LF.
5152

5253
Build the image with:
5354

54-
`docker build --add-host=content.quakejs.com:127.0.0.1 -t treyyoder/quakejs:latest .`
55+
`docker build . -t treyyoder/quakejs:latest`
5556

5657
## Credits:
5758

entrypoint.sh

-13
This file was deleted.

include/ioq3ded/ioq3ded.fixed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9947,7 +9947,7 @@ function copyTempDouble(ptr) {
99479947
} else {
99489948
// create the actual websocket object and connect
99499949
try {
9950-
var url = 'ws://' + addr + ':' + port;
9950+
var url = 'ws://' + addr;
99519951
// the node ws library API is slightly different than the browser's
99529952
var opts = ENVIRONMENT_IS_NODE ? {headers: {'websocket-protocol': ['binary']}} : ['binary'];
99539953
// If node we use the ws library.

nginx.conf

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
server {
2+
listen 80 default_server;
3+
4+
root /var/www/html;
5+
index index.html;
6+
server_name _;
7+
8+
location / {
9+
try_files /nonexistent @$http_upgrade;
10+
}
11+
12+
location @ {
13+
try_files $uri $uri/ =404;
14+
}
15+
16+
location @websocket {
17+
proxy_pass http://localhost:27960;
18+
proxy_http_version 1.1;
19+
proxy_set_header Upgrade $http_upgrade;
20+
proxy_set_header Connection "upgrade";
21+
}
22+
}

server.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
seta sv_hostname "quakejs"
2-
seta sv_maxclients 12
2+
seta sv_maxclients 16
33
seta g_motd "Welcome to the Local baseq3 QuakeJS Server"
44
seta g_quadfactor 3
55
seta g_gametype 0
66
seta timelimit 10
77
seta fraglimit 20
88
seta g_weaponrespawn 3
99
seta g_inactivity 3000
10-
seta g_forcerespawn 0
10+
seta g_forcerespawn 1
1111
seta rconpassword "quakejs"
1212
set d1 "map q3dm1 ; set nextmap vstr d2"
1313
set d2 "map q3dm7 ; set nextmap vstr d3"

supervisord.conf

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[supervisord]
2+
user=root
3+
nodaemon=true
4+
logfile=/dev/stdout
5+
logfile_maxbytes=0
6+
7+
[program:nginx]
8+
user=root
9+
command=/usr/sbin/nginx -g 'daemon off;'
10+
stdout_logfile=/dev/stdout
11+
stdout_logfile_maxbytes=0
12+
stderr_logfile=/dev/stderr
13+
stderr_logfile_maxbytes=0
14+
15+
[program:quakejs]
16+
user=quakejs
17+
directory=/quakejs
18+
command=node /quakejs/build/ioq3ded.js +set fs_game baseq3 set dedicated 1 +exec server.cfg
19+
autorestart=true
20+
stdout_logfile=/dev/stdout
21+
stdout_logfile_maxbytes=0
22+
stderr_logfile=/dev/stderr
23+
stderr_logfile_maxbytes=0

0 commit comments

Comments
 (0)