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 @@