Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1c15829
add Dockerfile and docker-compose to build and host server via docker
hthetiot Mar 9, 2025
2f792bb
backport src/3rdparty/clean.bat to src/3rdparty/clean for linux, remo…
hthetiot Mar 9, 2025
df2d604
fix #include <malloc.h> usage on __GNUC__ (MacOs)
hthetiot Mar 9, 2025
cacf55d
fix clang: error: '-I-' not supported in src/aeh/analaeh/makefile.lin
hthetiot Mar 9, 2025
eb8bfce
add 'EXTRA_FLAGS=-Wno-implicit-function-declaration' to avoid build f…
hthetiot Mar 9, 2025
2182bab
restore
hthetiot Mar 9, 2025
dafc8e1
add .gitignore
hthetiot Mar 9, 2025
c2d5a46
add .dockerignore
hthetiot Mar 9, 2025
9d91760
fix dptabt1.c:678:1: error: type specifier missing, defaults to 'int'…
hthetiot Mar 9, 2025
6e36442
add **/(debug|log|normal|profile) to .gitignore to avoid commiting ge…
hthetiot Mar 9, 2025
34f7e4e
add UPDATER_URL src/linux/server/etc/servfil for debug
hthetiot Mar 9, 2025
ee7c22d
move Dockerfile to docker/Dockerfile, add docker/entrypoint.sh that c…
hthetiot Mar 9, 2025
4d6bae0
fix wget -O src/linux/server/etc/servfil
hthetiot Mar 9, 2025
ee4ef36
make wget in servfil quiet
hthetiot Mar 9, 2025
8f55e1e
add lighttpd to serve /anet2 on port 8080
hthetiot Mar 9, 2025
186d195
setup ~alink/public_html/ and start lighttpd
hthetiot Mar 9, 2025
959e540
add default port to docker-compose.yml
hthetiot Mar 9, 2025
c14c10d
migrate from lightttp to apache2 running as alink, add cgi support, a…
hthetiot Mar 9, 2025
9af465d
optimize docker/entrypoint.sh and docker/supervisord.conf
hthetiot Mar 9, 2025
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
47 changes: 47 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# System Files
*.DS_Store
*Thumbs.db

# Library
src/3rdparty/md5/
src/3rdparty/d3des/

# Ignore build directories
/build/
/bin/
/obj/
/linux86/
/src/linux/runsrvfil/runsrvfil.cgi
/**/debug/
/**/log/
/**/normal/
/**/profile/

# Ignore object files and binaries
*.o
*.out
*.a
*.so
*.exe
*.dll

# Ignore compiled libraries
*.lib
*.la
*.lo

# Ignore debug and profiling files
*.dSYM/
*.gcda
*.gcno
*.gcov

# Ignore editor/IDE files
*.swp
*.swo
*.vscode/
*.idea/

linux86
*.zip
*.tgz
47 changes: 47 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# System Files
*.DS_Store
*Thumbs.db

# Library
src/3rdparty/md5/
src/3rdparty/d3des/

# Ignore build directories
/build/
/bin/
/obj/
/linux86/
/src/linux/runsrvfil/runsrvfil.cgi
/**/debug/
/**/log/
/**/normal/
/**/profile/

# Ignore object files and binaries
*.o
*.out
*.a
*.so
*.exe
*.dll

# Ignore compiled libraries
*.lib
*.la
*.lo

# Ignore debug and profiling files
*.dSYM/
*.gcda
*.gcno
*.gcov

# Ignore editor/IDE files
*.swp
*.swo
*.vscode/
*.idea/

linux86
*.zip
*.tgz
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ all:

clean:
rm -f *.tgz *.zip
cd src/3rdparty; ./clean
cd src/linux; ./clean

bootstrap:
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
anet-server:
container_name: anet-server
platform: linux/amd64
image: anet-server:latest
build:
context: .
dockerfile: docker/Dockerfile
#entrypoint: ["/home/anet/bin/server"]
#entrypoint: ["sh", "-c", "ls /home/alink/etc"]
#entrypoint: ["sh", "-c", "cd /home/alink/etc && ./servfil"]
#entrypoint: ["sh", "-c", "cd /home/alink/anetmon && ./getservers.sh"]
#entrypoint: ["/bin/sh", "-ec", "sleep infinity"]
ports:
- 8080:8080/tcp
- 21157:21157/udp
123 changes: 123 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Build stage
FROM debian:stable-slim AS build

# Install necessary packages
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
make \
zip \
gzip \
libbsd-dev \
libc6-dev \
&& rm -rf /var/lib/apt/lists/*


# Select the architecture (assuming environment variables or ARG can determine this)
ARG ARCHITECTURE=x86_64 # Default to x86_64 if not specified

# Automatically detect architecture
RUN ARCHITECTURE=$(uname -m) && \
if [ "$ARCHITECTURE" = "aarch64" ]; then \
ln -s /usr/lib/aarch64-linux-gnu/libm.a /usr/lib/libm.a && \
ln -s /usr/lib/aarch64-linux-gnu/libbsd.a /usr/lib/libbsd.a; \
elif [ "$ARCHITECTURE" = "x86_64" ]; then \
ln -s /usr/lib/x86_64-linux-gnu/libm.a /usr/lib/libm.a && \
ln -s /usr/lib/x86_64-linux-gnu/libbsd.a /usr/lib/libbsd.a; \
else \
echo "Unsupported architecture: $ARCHITECTURE"; exit 1; \
fi

# Copy from build stage using the variable
WORKDIR /build

# Define build directory
ENV APP_DIR=/build/linux86

# Copy only necessary files first (to leverage caching)
COPY Makefile ./
COPY src ./src
COPY demo ./demo
COPY h ./h

# Compile (invalidates cache only when source files change)
RUN make

# Runtime stage
FROM debian:stable-slim

# Install cron and wget
RUN apt-get update && \
apt-get install -y cron wget apache2 procps sudo supervisor && \
rm -rf /var/lib/apt/lists/*

# Set environment variable
ENV BUILD_DIR=/build/linux86
ENV APP_DIR=/home/anet

# Copy from build stage using the variable
COPY --from=build $BUILD_DIR $APP_DIR

# Create non-root user
RUN useradd -m alink

# Sudo
#RUN apt-get update && \
# apt-get install -y csudo && \
# rm -rf /var/lib/apt/lists/*
#RUN echo 'alink:darkreign' | chpasswd
#RUN usermod -aG sudo alink

# Set proper permissions for the user
RUN chown -R alink:alink $APP_DIR

RUN mv $APP_DIR/anetmon/ /home/alink/
RUN mv $APP_DIR/server/etc /home/alink/

# Set proper permissions for cron
RUN chmod gu+rw /var/run
RUN chmod gu+s /usr/sbin/cron

# Install crontab for the game server user
RUN crontab -u alink /home/alink/etc/crontab2.lst

# Configure Apache Directory public_html
RUN mkdir -p /home/alink/public_html && \
chown -R alink: /home/alink/public_html

# Configure Apache user
RUN chown -R alink: /var/log/apache2/ && \
sed -i 's/APACHE_RUN_USER=www-data/APACHE_RUN_USER=alink/' /etc/apache2/envvars && \
sed -i 's/APACHE_RUN_GROUP=www-data/APACHE_RUN_GROUP=alink/' /etc/apache2/envvars

COPY docker/apache2.conf /etc/apache2/conf-available/anet2.conf
RUN a2enconf anet2 && \
a2enmod cgid && \
sed -i 's/Listen 80/Listen 8080/g' /etc/apache2/ports.conf

# Copy supervisor configuration file
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chown -R alink /var/log/supervisor/
RUN chown -R alink /run

# Switch to non-root user
USER alink

WORKDIR /home/alink

# Ports > 21157 since we're not root.
EXPOSE 21157/udp
EXPOSE 8080/tcp

HEALTHCHECK --interval=1m --start-period=30s --start-interval=5s --timeout=2s \
CMD ps auxww | grep 'alink.*anet3'

# Entrypoint
COPY docker/entrypoint.sh /opt/local/bin/entrypoint.sh
ENTRYPOINT ["/opt/local/bin/entrypoint.sh"]

# Switch to non-root user
USER alink

# Use supervisor as the main process
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
10 changes: 10 additions & 0 deletions docker/apache2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ServerName 0.0.0.0
Alias /anet2 /home/alink/public_html/
<Directory /home/alink/public_html>
Options FollowSymLinks ExecCGI Indexes
AllowOverride None
Require all granted
<FilesMatch "\.cgi$">
SetHandler cgi-script
</FilesMatch>
</Directory>
37 changes: 37 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash -e

# Create local-servers.txt and populate it with an IP and hostname
echo "- Create local-servers.txt..."
HOSTNAME="${HOSTNAME:=localhost}"
export EXTERNAL_IP_EXEC_SET=`wget -qO- https://checkip.amazonaws.com`
echo "${EXTERNAL_IP_EXEC_SET} $HOSTNAME" > /home/alink/etc/local-servers.txt
cat /home/alink/etc/local-servers.txt

touch /tmp/anet3srv.log
touch /tmp/anet2cron.log

echo "- Execute servfil..."
cd ~/etc
./servfil

# Deploy public_html/etc
echo "- Deploy public_html/etc"
cd ~/public_html
mkdir -p etc
cd etc
ln -s ~alink/etc/apps.txt apps.txt
ln -s ~alink/etc/names.txt names.txt
ln -s ~alink/etc/servers.txt servers.txt
ln -s ~alink/etc/types.txt types.txt

# Deploy runsrvfil.cgi
echo "- Deploy runsrvfil.cgi..."
cd ~/public_html/etc
cp ../../etc/runsrvfil.cgi .
chmod ug+sx runsrvfil.cgi

echo "- Start game server daemon..."
~alink/etc/start2

echo executing: "$@"
exec "$@"
53 changes: 53 additions & 0 deletions docker/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[supervisord]
nodaemon=true
user=alink
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:anet3srv-log]
command=tail -F /tmp/anet3srv.log
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
redirect_stderr=true
user=alink
priority=10

[program:anet2cron-log]
command=tail -F /tmp/anet2cron.log
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
redirect_stderr=true
user=alink
priority=10

[program:apache2]
command=/usr/sbin/apache2ctl -DFOREGROUND
autostart=true
autorestart=true
user=alink
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=20

[program:cron]
command=/usr/sbin/cron -f
autostart=true
autorestart=true
user=alink
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=30

[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
2 changes: 2 additions & 0 deletions src/3rdparty/clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm -fr ./d3des
rm -fr ./md5
Loading