-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
182 lines (139 loc) · 5.12 KB
/
Copy pathDockerfile
File metadata and controls
182 lines (139 loc) · 5.12 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
FROM almalinux:9
# Set environment variables
ENV GLPI_HOME_DIR=/var/www/glpi
ENV GLPI_DATA_DIR=/var/glpi
ENV HOME_DIR=/var/www
ENV GLPI_INSTALL_MODE=DOCKER
ENV GLPI_CONFIG_DIR=${GLPI_DATA_DIR}/config
ENV GLPI_VAR_DIR=${GLPI_DATA_DIR}/files
ENV GLPI_MARKETPLACE_DIR=${GLPI_DATA_DIR}/marketplace
ENV GLPI_LOG_DIR=${GLPI_DATA_DIR}/logs
ENV GLPI_USER=nginx
ENV GLPI_GROUP=nginx
# Add metadata to an image.
LABEL description="GLPI Docker Container with php-fpm"
LABEL version="GLPI Latest Stable"
LABEL maintainer="Tiozão do Linux <jarbas.junior@gmail.com>"
LABEL org.opencontainers.image.authors="Tiozão do Linux <jarbas.junior@gmail.com>"
# Use heredoc to run multiple commands in a single RUN instruction.
# https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/
# Install necessary packages
RUN <<_EOF_
# Install necessary packages
# Configure PHP repository Remi - https://rpms.remirepo.net/
dnf -qy install 'dnf-command(config-manager)'
dnf -qy config-manager --set-enabled crb
dnf -qy install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
dnf -qy install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf -qy module switch-to php:remi-8.5
# Cron for GLPI automatic actions
#dnf -qy install cronie procps-ng supervisor
dnf -qy install supervisor
# Necessary packages
dnf -qy install php-{fpm,cli,ldap,soap,curl,snmp,zip,apcu,gd,mbstring,xml,bz2,intl,bcmath,mysqlnd}
# Additional PHP extensions
dnf -qy install php-{opcache,sodium}
# The TLS_REQCERT never setting in the context of PHP and LDAP refers to disabling the server
# certificate validation when establishing a TLS (Transport Layer Security) connection to an LDAP server.
echo -e "TLS_REQCERT\tnever" >> /etc/openldap/ldap.conf
# Extra packages
dnf -qy install epel-release
dnf -qy install net-tools nmap htop
# # Update packages
# dnf -qy upgrade
# Clean up
dnf clean all
# Define a new home directory for the GLPI user
usermod -d ${HOME_DIR} ${GLPI_USER}
_EOF_
# Where the GLPI files will be stored inside the container
WORKDIR ${GLPI_HOME_DIR}
# Install GLPI
RUN <<_EOF_
# Up one level to download and extract GLPI
cd ..
# Download and extract latest stable release of GLPI
LATEST=`curl -sI https://github.com/glpi-project/glpi/releases/latest | awk -F'/' '/^location/ {sub("\r","",$NF); print $NF }'`
curl -s -L "https://github.com/glpi-project/glpi/releases/download/${LATEST}/glpi-${LATEST}.tgz" -o glpi-${LATEST}.tgz
# Extract GLPI files
tar xzf glpi-${LATEST}.tgz --no-same-owner -C ./
# Remove downloaded file
rm -f glpi-${LATEST}.tgz
# Set proper permissions
chown -R ${GLPI_USER}:${GLPI_GROUP} ${GLPI_HOME_DIR}
# Create a directory for persistent files
mkdir -p ${GLPI_DATA_DIR}
chown -R ${GLPI_USER}:${GLPI_GROUP} ${GLPI_DATA_DIR}
_EOF_
# Configure PHP-FPM and Supervisor and Cron Job
RUN <<_EOF_
# Configure PHP-FPM and Supervisor and Cron Job
# Create loop script to simulate a cron job
cat > /usr/bin/cronjob.sh << _INSIDE_EOF_
#!/bin/bash
set -e -u -o pipefail
while true; do
echo "[GLPI Cron Job][\$(date)][${GLPI_USER}] : [php ${GLPI_HOME_DIR}/front/cron.php]"
php ${GLPI_HOME_DIR}/front/cron.php
sleep 60
done
_INSIDE_EOF_
chmod +x /usr/bin/cronjob.sh
# Adjust permissions for run PHP-FPM with ${GLPI_USER}
##ln -s /tmp/php-fpm.pid /var/run/php-fpm.pid
sed -i 's|^pid =.*|pid = /tmp/php-fpm.pid|' /etc/php-fpm.conf
##mkdir -p /var/log/php-fpm
chown -R ${GLPI_USER}:${GLPI_GROUP} /var/log/php-fpm
# Create www.conf file from scratch to avoid conflicts
cat > /etc/php-fpm.d/www.conf << _INSIDE_EOF_
[www]
;user = nginx
;group = nginx
listen = 9000
listen.acl_users = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.status_path = /status/fpm
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
_INSIDE_EOF_
# Configure Supervisor to manage php-fpm and cron
cat > /etc/supervisord.conf << _INSIDE_EOF_
[supervisord]
nodaemon=true ; (start in foreground if true;default false)
loglevel=critical ; (log level;default info; others: debug,warn,trace)
user=${GLPI_USER} ; (default is current user, required if root)
logfile=/dev/null ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=0 ; (max main logfile bytes b4 rotation;default 50MB)
[program:php-fpm]
command=/usr/sbin/php-fpm -F
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
[program:glpi-cron]
command=/usr/bin/cronjob.sh
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
_INSIDE_EOF_
_EOF_
# Copy entrypoint into the container
COPY entrypoint.sh /entrypoint.sh
# Defines volumes to be supported
VOLUME [ ${GLPI_HOME_DIR} ${GLPI_DATA_DIR} ]
# Expose the port of php-fpm
EXPOSE 9000
USER ${GLPI_USER}
ENTRYPOINT [ "/entrypoint.sh" ]
# CMD ["php-fpm", "-F"]
# CMD ["/usr/sbin/crond", "-n"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]