Skip to content

Commit f029dbc

Browse files
Add support for switching PHP version in contributor container.
Also use build in packages for pcov, since pecl is not working with multiple PHP versions. Get rid of ghc and fp-compiler since install seems flaky and contributors don't use it anyway.
1 parent 9cab3f4 commit f029dbc

File tree

6 files changed

+102
-33
lines changed

6 files changed

+102
-33
lines changed

docker-contributor/Dockerfile

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
1212
FPM_MAX_CHILDREN=40 \
1313
DJ_SKIP_MAKE=0 \
1414
DJ_DB_INSTALL_BARE=0 \
15-
PHPSUPPORTED="7.2 7.3 8.0 8.1" \
15+
PHPSUPPORTED="7.2 7.3 7.4 8.0 8.1" \
16+
DEFAULTPHPVERSION="8.1" \
1617
APTINSTALL="apt install -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold"
1718

1819
# Install required packages and clean up afterwards to make this image layer smaller
@@ -22,20 +23,18 @@ RUN apt update \
2223
gcc g++ make zip unzip mariadb-client \
2324
nginx php7.4 php7.4-cli php7.4-fpm php7.4-zip \
2425
php7.4-gd php7.4-curl php7.4-mysql php7.4-json php7.4-intl \
25-
php7.4-gmp php7.4-xml php7.4-mbstring php-xdebug \
26+
php7.4-gmp php7.4-xml php7.4-mbstring php-xdebug php-pcov \
2627
bsdmainutils ntp \
2728
linuxdoc-tools linuxdoc-tools-text groff \
2829
python3-sphinx python3-sphinx-rtd-theme python3-pip fontconfig python3-yaml \
2930
texlive-latex-recommended texlive-latex-extra \
3031
texlive-fonts-recommended texlive-lang-european latexmk \
3132
sudo debootstrap libcgroup-dev procps \
32-
default-jre-headless \
33-
default-jdk ghc fp-compiler \
33+
default-jre-headless default-jdk \
3434
supervisor apache2-utils lsb-release \
3535
libcurl4-gnutls-dev libjsoncpp-dev libmagic-dev \
3636
enscript lpr ca-certificates less vim \
3737
php-pear php-dev software-properties-common \
38-
&& pecl install pcov \
3938
&& rm -rf /var/lib/apt/lists/*
4039

4140
# Needed for building the docs
@@ -61,26 +60,42 @@ RUN apt update && \
6160
# Install all supported PHP versions
6261
RUN add-apt-repository ppa:ondrej/php -y && apt update
6362
RUN for VERSION in $PHPSUPPORTED; do \
64-
$APTINSTALL php${VERSION}; \
63+
if [ "${VERSION}" != "7.4" ]; then \
64+
$APTINSTALL php${VERSION}; \
65+
fi; \
6566
done
6667
RUN PACKAGES=$(dpkg-query -f '${binary:Package}\n' -W|grep "^php.*-"); \
6768
for PACKAGE in $PACKAGES; do \
6869
PACKAGEALLVERSIONS="" && \
6970
for VERSION in $PHPSUPPORTED; do \
70-
PACKAGEALLVERSIONS="$PACKAGEALLVERSIONS php${VERSION}-${PACKAGE#php*-}"; \
71+
if [ "${VERSION}" != "7.4" ]; then \
72+
PACKAGEALLVERSIONS="$PACKAGEALLVERSIONS php${VERSION}-${PACKAGE#php*-}"; \
73+
fi; \
7174
done; \
7275
$APTINSTALL $PACKAGEALLVERSIONS; \
7376
done
74-
RUN update-alternatives --set php /usr/bin/php7.4
77+
RUN update-alternatives --set php /usr/bin/php${DEFAULTPHPVERSION}
78+
79+
# Set up alternatives for PHP-FPM
80+
RUN for VERSION in $PHPSUPPORTED; do \
81+
PRIORTIY=$(echo ${VERSION} | tr -d '.'); \
82+
update-alternatives --install /usr/sbin/php-fpm php-fpm /usr/sbin/php-fpm${VERSION} ${PRIORTIY}; \
83+
done
84+
RUN update-alternatives --set php-fpm /usr/sbin/php-fpm${DEFAULTPHPVERSION}
7585

7686
# Add exposed volume
7787
VOLUME ["/domjudge"]
7888

7989
WORKDIR /domjudge
8090

8191
# Add PHP configuration
82-
COPY ["php-config", "//etc/php/7.4/fpm/conf.d"]
83-
COPY ["php-config", "//etc/php/7.4/cli/conf.d"]
92+
RUN mkdir /php-config
93+
COPY ["php-config", "/php-config"]
94+
RUN for VERSION in $PHPSUPPORTED; do \
95+
cp -Rf /php-config/* /etc/php/${VERSION}/cli/conf.d; \
96+
cp -Rf /php-config/* /etc/php/${VERSION}/fpm/conf.d; \
97+
done; \
98+
rm -Rf /php-config
8499

85100
# Disable Xdebug by default
86101
RUN phpdismod xdebug

docker-contributor/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ The following commands are available:
9696
* `submit-test-programs`: submit all test programs (by executing `make check test-stress` in the `tests` directory of the DOMjudge installation. This will also add a `dummy` user to your database if it does not exist yet. It's password will be set to `dummy`.
9797
* `xdebug-enable`: enable Xdebug debugging. See note below
9898
* `xdebug-disable`: disable Xdebug debugging. See note below
99+
* `switch-php <version>`: switch to using the given PHP version.
99100

100101
Of course, you can always run `docker exec -it domjudge bash` to get a bash shell inside the container.
101102

docker-contributor/php-config/30-pcov.ini

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
3+
import glob
4+
import os
5+
import shlex
6+
import sys
7+
8+
if os.getuid() != 0:
9+
# Automatically give ourself root privileges
10+
arguments = " ".join(shlex.quote(arg) for arg in sys.argv)
11+
command = f"sudo {arguments}"
12+
exit(os.system(command))
13+
14+
def currentPhpVersion():
15+
return os.readlink('/etc/alternatives/php').replace('/usr/bin/php', '')
16+
17+
def supportedVersions():
18+
return sorted([binary.replace('/usr/bin/php', '') for binary in glob.glob('/usr/bin/php?.?')])
19+
20+
def usage():
21+
u = f"Usage: {sys.argv[0]} <version>\n\n"
22+
u += f"Supported PHP versions:\n"
23+
for version in supportedVersions():
24+
u += f"- {version}"
25+
if version == currentPhpVersion():
26+
u += " *"
27+
u += "\n"
28+
29+
u += "\n*: currently used version"
30+
31+
print(u)
32+
33+
if len(sys.argv) != 2:
34+
usage()
35+
exit(0)
36+
37+
newVersion = sys.argv[1]
38+
39+
if newVersion not in supportedVersions():
40+
print(f"{newVersion} is not a supported PHP version")
41+
usage()
42+
exit(1)
43+
44+
# Version is supported, switch to it
45+
os.system(f"update-alternatives --set php /usr/bin/php{newVersion}")
46+
os.system(f"update-alternatives --set php-fpm /usr/sbin/php-fpm{newVersion}")
47+
48+
# Restart PHP FPM supervisor job
49+
os.system("supervisorctl restart php")
50+
51+
print(f"Successfully switched to PHP {newVersion} and restarted PHP FPM")

docker-contributor/scripts/start.sh

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ echo "[ok] Container timezone set to: ${CONTAINER_TIMEZONE}"; echo
1818
echo "[..] Changing nginx and PHP configuration settings"
1919
# Set correct settings
2020
sed -ri -e "s/^user.*/user domjudge;/" /etc/nginx/nginx.conf
21-
sed -ri -e "s/^upload_max_filesize.*/upload_max_filesize = 100M/" \
22-
-e "s/^post_max_size.*/post_max_size = 100M/" \
23-
-e "s/^memory_limit.*/memory_limit = 2G/" \
24-
-e "s/^max_file_uploads.*/max_file_uploads = 200/" \
25-
-e "s#^;date\.timezone.*#date.timezone = ${CONTAINER_TIMEZONE}#" \
26-
/etc/php/7.4/fpm/php.ini
27-
sed -ri -e "s#^;date\.timezone.*#date.timezone = ${CONTAINER_TIMEZONE}#" \
28-
/etc/php/7.4/cli/php.ini
21+
for VERSION in $PHPSUPPORTED
22+
do
23+
sed -ri -e "s/^upload_max_filesize.*/upload_max_filesize = 100M/" \
24+
-e "s/^post_max_size.*/post_max_size = 100M/" \
25+
-e "s/^memory_limit.*/memory_limit = 2G/" \
26+
-e "s/^max_file_uploads.*/max_file_uploads = 200/" \
27+
-e "s#^;date\.timezone.*#date.timezone = ${CONTAINER_TIMEZONE}#" \
28+
"/etc/php/${VERSION}/fpm/php.ini"
29+
sed -ri -e "s#^;date\.timezone.*#date.timezone = ${CONTAINER_TIMEZONE}#" \
30+
"/etc/php/${VERSION}/cli/php.ini"
31+
done
2932
echo "[ok] Done changing nginx and PHP configuration settings"; echo
3033

3134
cd /domjudge
@@ -114,16 +117,19 @@ cp etc/nginx-conf /etc/nginx/sites-enabled/default
114117
# Replace nginx php socket location
115118
sed -i 's/server unix:.*/server unix:\/var\/run\/php-fpm-domjudge.sock;/' /etc/nginx/sites-enabled/default
116119
# Remove default FPM pool config and link in DOMjudge version
117-
if [[ -f /etc/php/7.4/fpm/pool.d/www.conf ]]
118-
then
119-
rm /etc/php/7.4/fpm/pool.d/www.conf
120-
fi
121-
if [[ ! -f /etc/php/7.4/fpm/pool.d/domjudge.conf ]]
122-
then
123-
ln -s /domjudge/etc/domjudge-fpm.conf /etc/php/7.4/fpm/pool.d/domjudge.conf
124-
fi
125-
# Change pm.max_children
126-
sed -i "s/^pm\.max_children = .*$/pm.max_children = ${FPM_MAX_CHILDREN}/" /etc/php/7.4/fpm/pool.d/domjudge.conf
120+
for VERSION in $PHPSUPPORTED
121+
do
122+
if [[ -f /etc/php/${VERSION}/fpm/pool.d/www.conf ]]
123+
then
124+
rm "/etc/php/${VERSION}/fpm/pool.d/www.conf"
125+
fi
126+
if [[ ! -f /etc/php/${VERSION}/fpm/pool.d/domjudge.conf ]]
127+
then
128+
ln -s /domjudge/etc/domjudge-fpm.conf "/etc/php/${VERSION}/fpm/pool.d/domjudge.conf"
129+
fi
130+
# Change pm.max_children
131+
sed -i "s/^pm\.max_children = .*$/pm.max_children = ${FPM_MAX_CHILDREN}/" "/etc/php/${VERSION}/fpm/pool.d/domjudge.conf"
132+
done
127133

128134
chown domjudge: /domjudge/etc/dbpasswords.secret
129135
chown domjudge: /domjudge/etc/restapi.secret
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[program:php]
2-
command=php-fpm7.4 -F
2+
command=php-fpm -F
33
numprocs=1
44
autostart=true
55
autorestart=true

0 commit comments

Comments
 (0)