aboutsummaryrefslogtreecommitdiff
path: root/Dockerfile
blob: f95e3d4191ed3d91c9f6f88f8a70eea808847ac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
FROM debian:bullseye-slim

RUN apt-get update \
    && apt-get install -y apache2 perl build-essential \
      libdbi-perl \
      libdbd-sqlite3-perl \
      libjson-perl \
      libimage-size-perl \
      libanyevent-perl \
      libio-all-lwp-perl \
    	libfcgi-perl \
      libgeography-countries-perl \
      libapache2-mod-fcgid \
    && cpan TUWF \
    && cpan "LWP::Simple" \
    && apt-get autoclean

RUN a2enmod rewrite fcgid proxy_fcgi cgi

COPY . /masterserver

# Create Apache VirtualHost configuration on custom listen port
RUN echo 'Listen 8080\n\
    <VirtualHost *:8080>\n\
    DocumentRoot "/masterserver/s"\n\
    AddHandler cgi-script .pl\n\
    \
    RewriteEngine On\n\
    RewriteCond "%{DOCUMENT_ROOT}/%{REQUEST_URI}" !-s\n\
    RewriteRule ^/ /masterinterface.pl\n\
    \
    ErrorLog  /masterserver/log/error.log\n\
    CustomLog /masterserver/log/access.log combined\n\
    \
    <Directory "/masterserver/s">\n\
        Options +FollowSymLinks +ExecCGI\n\
        AllowOverride None\n\
        Require all granted\n\
    </Directory>\n\
    </VirtualHost>' > /etc/apache2/sites-available/000-default.conf

# Create FastFGI configuration which works with our stand-alone Apache instance
RUN echo '<IfModule mod_fcgid.c>\n\
		FcgidIPCDir                /run/mod_fcgid\n\
		FcgidProcessTableFile      /run/mod_fcgid/fcgid_shm\n\
		FcgidMinProcessesPerClass  0\n\
		FcgidMaxProcessesPerClass  8\n\
		FcgidMaxProcesses          100\n\
    FcgidConnectTimeout 			 20\n\
		FcgidIdleTimeout           60\n\
		FcgidProcessLifeTime       120\n\
		FcgidIdleScanInterval      10\n\
		\
		<IfModule mod_mime.c>\n\
			AddHandler fcgid-script .fcgi\n\
		</IfModule>\n\
		</IfModule>' > /etc/apache2/mods-enabled/fcgid.conf

# Create a script which runns the IP to Country lookup in the background, and runs Apache in the foreground
RUN echo '#!/bin/sh\n\
    if [ ! $NO_IP_TO_COUNTRY ]; then\n\
    	echo "Running IP to Country lookup"\n\
    	cd /masterserver/util && ./listcountry.pl > /masterserver/log/listcountry.log &\n\
    else\n\
			echo "Not using IP to Country lookup"\n\
    fi\n\
    cd /masterserver && apache2 -DFOREGROUND' > /masterserver/launch.sh

RUN mkdir -p /run/mod_fcgid \
    && chown -R daemon:daemon /run/mod_fcgid /masterserver \
    && chmod +x /masterserver/launch.sh

USER daemon

# Supply variables expected by Debian's Apache distribution
ENV APACHE_RUN_USER=daemon\
    APACHE_RUN_GROUP=daemon\
    APACHE_RUN_DIR=/masterserver\
    APACHE_PID_FILE=/masterserver/apache2.pid\
    APACHE_LOG_DIR=/masterserver/log\
    NO_IP_TO_COUNTRY=""

CMD ["/masterserver/launch.sh"]