Skip to content

Commit 929fa19

Browse files
authored
php-fpm: change upstream image to php project (#102)
NethServer/dev#7610
1 parent 36a8185 commit 929fa19

File tree

15 files changed

+180
-29
lines changed

15 files changed

+180
-29
lines changed

build-images.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,60 @@ repobase="${REPOBASE:-ghcr.io/nethserver}"
1010
# Configure the image name
1111
reponame="webserver"
1212

13+
podman build \
14+
--force-rm \
15+
--layers \
16+
--tag "${repobase}/php8.4-fpm" \
17+
--build-arg "PHP_VERSION=docker.io/library/php:8.4.11-fpm" \
18+
container
19+
20+
images+=("${repobase}/php8.4-fpm")
21+
22+
podman build \
23+
--force-rm \
24+
--layers \
25+
--tag "${repobase}/php8.3-fpm" \
26+
--build-arg "PHP_VERSION=docker.io/library/php:8.3.4-fpm" \
27+
container
28+
29+
images+=("${repobase}/php8.3-fpm")
30+
31+
podman build \
32+
--force-rm \
33+
--layers \
34+
--tag "${repobase}/php8.2-fpm" \
35+
--build-arg "PHP_VERSION=docker.io/library/php:8.2.29-fpm" \
36+
container
37+
38+
images+=("${repobase}/php8.2-fpm")
39+
40+
podman build \
41+
--force-rm \
42+
--layers \
43+
--tag "${repobase}/php8.1-fpm" \
44+
--build-arg "PHP_VERSION=docker.io/library/php:8.1.33-fpm" \
45+
container
46+
47+
images+=("${repobase}/php8.1-fpm")
48+
49+
podman build \
50+
--force-rm \
51+
--layers \
52+
--tag "${repobase}/php8.0-fpm" \
53+
--build-arg "PHP_VERSION=docker.io/library/php:8.0.30-fpm" \
54+
container
55+
56+
images+=("${repobase}/php8.0-fpm")
57+
58+
podman build \
59+
--force-rm \
60+
--layers \
61+
--tag "${repobase}/php7.4-fpm" \
62+
--build-arg "PHP_VERSION=docker.io/library/php:7.4.33-fpm" \
63+
container
64+
65+
images+=("${repobase}/php7.4-fpm")
66+
1367
# Create a new empty container image
1468
container=$(buildah from scratch)
1569

container/Containerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
ARG PHP_VERSION
2+
ENV PHP_VERSION=$PHP_VERSION
3+
4+
FROM $PHP_VERSION
5+
6+
# Installation des dépendances nécessaires à la compilation
7+
RUN apt-get update && apt-get install -y \
8+
libzip-dev \
9+
libldap2-dev \
10+
libtidy-dev \
11+
libpng-dev \
12+
libjpeg-dev \
13+
libwebp-dev \
14+
libfreetype6-dev \
15+
libicu-dev \
16+
libbz2-dev \
17+
libssl-dev \
18+
libargon2-dev \
19+
zlib1g-dev \
20+
libgmp-dev \
21+
libcurl4-openssl-dev \
22+
libsqlite3-dev \
23+
libxml2-dev \
24+
libpq-dev \
25+
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
26+
&& docker-php-ext-install \
27+
soap \
28+
sockets \
29+
tidy \
30+
ldap \
31+
gd \
32+
intl \
33+
zip \
34+
bcmath \
35+
opcache \
36+
exif \
37+
pdo_mysql \
38+
pdo_pgsql \
39+
pgsql \
40+
mysqli \
41+
bz2 \
42+
xml \
43+
&& apt-get purge -y \
44+
libzip-dev \
45+
libldap2-dev \
46+
libtidy-dev \
47+
libpng-dev \
48+
libjpeg-dev \
49+
libwebp-dev \
50+
libfreetype6-dev \
51+
libicu-dev \
52+
libbz2-dev \
53+
libssl-dev \
54+
libargon2-dev \
55+
zlib1g-dev \
56+
libgmp-dev \
57+
libcurl4-openssl-dev \
58+
libsqlite3-dev \
59+
libxml2-dev \
60+
libpq-dev \
61+
&& apt-get autoremove -y \
62+
&& apt-get clean \
63+
&& rm -rf /var/lib/apt/lists/* \
64+
&& rm -rf /tmp/* /var/tmp/*
65+
66+
# copie docker-php-ext-opcache.ini to /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
67+
COPY docker-php-ext-opcache.ini /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
zend_extension=opcache

imageroot/actions/clone-module/60pull-php-image

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ import re
2626
PhpServiceArray = glob.glob('php*-fpm-custom.d')
2727
for folder in PhpServiceArray:
2828
ConfiguredServices = re.findall('php[0-9\.]+', folder)
29-
ListConfigurations = glob.glob(folder+'/*.conf')
29+
ListConfigurations = glob.glob(folder+'/dyn-*.conf')
3030
if ListConfigurations :
3131
subprocess.run(["download-php-fpm",ConfiguredServices[0].replace('php','')])

imageroot/actions/destroy-vhost/30restart_services

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ subprocess.run(["systemctl", "--user", "reload", "nginx.service"])
3232
PhpServiceArray = glob.glob('php*-fpm-custom.d')
3333
for folder in PhpServiceArray:
3434
ConfiguredServices = re.findall('php[0-9\.]+', folder)
35-
ListConfigurations = glob.glob(folder+'/*.conf')
35+
ListConfigurations = glob.glob(folder+'/dyn-*.conf')
3636
if not ListConfigurations :
3737
subprocess.run(["systemctl", "--user", "disable","--now", "phpfpm@"+ConfiguredServices[0].replace('php','')+".service"])
3838

imageroot/actions/restore-module/60systemd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ agent.run_helper("systemctl", "--user", "restart", "sftpgo.service").check_retur
3737
PhpServiceArray = glob.glob('php*-fpm-custom.d')
3838
for folder in PhpServiceArray:
3939
ConfiguredServices = re.findall('php[0-9\.]+', folder)
40-
ListConfigurations = glob.glob(folder+'/*.conf')
40+
ListConfigurations = glob.glob(folder+'/dyn-*.conf')
4141
if ListConfigurations :
4242
subprocess.run(["download-php-fpm",ConfiguredServices[0].replace('php','')])
4343
subprocess.run(["systemctl", "--user", "enable","--now", "phpfpm@"+ConfiguredServices[0].replace('php','')+".service"])

imageroot/actions/update-vhost/30SystemdServices

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if PhpVersion:
4444
PhpServiceArray = glob.glob('php*-fpm-custom.d')
4545
for folder in PhpServiceArray:
4646
ConfiguredServices = re.findall('php[0-9\.]+', folder)
47-
ListConfigurations = glob.glob(folder+'/*.conf')
47+
ListConfigurations = glob.glob(folder+'/dyn-*.conf')
4848
if not ListConfigurations :
4949
subprocess.run(["systemctl", "--user", "disable","--now", "phpfpm@"+ConfiguredServices[0].replace('php','')+".service"])
5050
# pull the image if missing

imageroot/bin/download-php-fpm

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,13 @@ set -e
99

1010
minor_version="${1:?We expect one argument}"
1111

12-
declare -A version_map
12+
# retrieve environment IMAGE_URL, remove the registry if present and keep the tag, e.g. `1.1.1`
13+
image_url="${IMAGE_URL:-? We expect IMAGE_URL environment variable}"
14+
# remove `ghcr.io/nethserver/webserver:`
15+
tag="${image_url##*:}"
1316

14-
version_map[7.4]=7.4.33
15-
version_map[8.0]=8.0.30
16-
version_map[8.1]=8.1.31
17-
version_map[8.2]=8.2.26
18-
version_map[8.3]=8.3.14
19-
version_map[8.4]=8.4.11
20-
# Check if major_version is mapped properly
21-
if [[ -z "${version_map[$minor_version]}" ]]; then
22-
echo "PHP version $minor_version is not supported" 1>&2
23-
exit 1
24-
fi
17+
# save the php tag for later use in the systemd service
18+
echo "IMAGE_URL_TAG=$tag" > image_url_tag.env
2519

2620
# pull the image
27-
podman-pull-missing "docker.io/bitnami/php-fpm:${version_map[$minor_version]}"
28-
# systemd service use docker.io/bitnami/php-fpm:8.1
29-
# we need to tag with major version to use it locally
30-
/usr/bin/podman tag "docker.io/bitnami/php-fpm:${version_map[$minor_version]}" "docker.io/bitnami/php-fpm:${minor_version}"
21+
podman-pull-missing "ghcr.io/nethserver/php$minor_version-fpm:$tag"

imageroot/bin/expand-vhosts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import os
2424
import glob
2525
import configparser
2626
import json
27-
import sys
28-
import subprocess
27+
import shutil
2928
from jinja2 import Environment, FileSystemLoader, select_autoescape
3029

3130
for file in glob.iglob("conf.d/dyn-*.conf"):
@@ -87,3 +86,8 @@ for file in glob.iglob("databases/vhosts/*.ini"):
8786
f.write(output)
8887
# php-fpm expects to find its customisation file
8988
open("php"+str(PhpVersion)+"-fpm-custom.d/dyn-"+str(port)+".custom", "a").close
89+
# copy the default configurations
90+
shutil.copyfile(
91+
os.path.join(os.getenv("AGENT_INSTALL_DIR"), "templates", "docker.conf"),
92+
f"php{PhpVersion}-fpm-custom.d/docker.conf"
93+
)

imageroot/systemd/user/phpfpm@.service

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ConditionDirectoryNotEmpty=%S/state/php%i-fpm-custom.d/
77
[Service]
88
Environment=PODMAN_SYSTEMD_UNIT=%n
99
EnvironmentFile=%S/state/environment
10+
EnvironmentFile=%S/state/image_url_tag.env
1011
WorkingDirectory=%S/state
1112
Restart=always
1213
TimeoutStopSec=70
@@ -15,8 +16,9 @@ ExecStartPre=/usr/bin/mkdir -p %S/state/php%i-fpm-custom.d
1516
ExecStart=/usr/bin/podman run --conmon-pidfile %t/php%i-fpm.pid \
1617
--cidfile %t/php%i-fpm.ctr-id --cgroups=no-conmon \
1718
--pod-id-file %t/webserver.pod-id --replace -d --name php%i-fpm \
18-
--volume websites:/app:z --volume %S/state/php%i-fpm-custom.d:/opt/bitnami/php/etc/php-fpm.d:Z \
19-
docker.io/bitnami/php-fpm:%i
19+
--volume websites:/var/www/html:z \
20+
--volume %S/state/php%i-fpm-custom.d:/usr/local/etc/php-fpm.d:z \
21+
ghcr.io/nethserver/php%i-fpm:${IMAGE_URL_TAG}
2022
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/php%i-fpm.ctr-id -t 10
2123
ExecReload=/usr/bin/mkdir -p %S/state/php%i-fpm-custom.d
2224
ExecReload=/usr/bin/podman kill -s USR2 php%i-fpm

0 commit comments

Comments
 (0)