Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP-FPM variant #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 7 additions & 8 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ ENV PHP_INI_UPLOAD_MAX_FILESIZE 2M
ENV PHP_INI_POST_MAX_SIZE 8M
ENV PHP_INI_ALLOW_URL_FOPEN 0

RUN sed -i \
-e 's/^\(ServerSignature On\)$/#\1/g' \
-e 's/^#\(ServerSignature Off\)$/\1/g' \
-e 's/^\(ServerTokens\) OS$/\1 Prod/g' \
/etc/apache2/conf-available/security.conf
%EXTRAS%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll probably have to create a second template for the FPM version of your image instead of editing this one ...


RUN apt-get update -y \
&& apt-get dist-upgrade -y \
Expand All @@ -61,6 +57,7 @@ RUN apt-get update -y \
default-mysql-client \
postgresql-client \
cron \
rsync \
&& apt-get autoremove -y \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) calendar intl mysqli pdo_mysql gd soap zip \
Expand All @@ -76,20 +73,22 @@ RUN apt-get update -y \
# Get Dolibarr
RUN curl -fLSs https://github.com/Dolibarr/dolibarr/archive/${DOLI_VERSION}.tar.gz |\
tar -C /tmp -xz && \
cp -r /tmp/dolibarr-${DOLI_VERSION}/htdocs/* /var/www/html/ && \
mkdir -p /usr/src/dolibarr && \
cp -r /tmp/dolibarr-${DOLI_VERSION}/htdocs/* /usr/src/dolibarr/ && \
ln -s /var/www/html /var/www/htdocs && \
cp -r /tmp/dolibarr-${DOLI_VERSION}/scripts /var/www/ && \
rm -rf /tmp/* && \
mkdir -p /var/www/documents && \
mkdir -p /var/www/html/custom && \
chown -R www-data:www-data /var/www

EXPOSE 80
EXPOSE %EXPOSE%
VOLUME /var/www/documents
VOLUME /var/www/html
VOLUME /var/www/html/custom

COPY docker-init.php /var/www/scripts/
COPY docker-run.sh /usr/local/bin/
ENTRYPOINT ["docker-run.sh"]

CMD ["apache2-foreground"]
CMD ["%CMD%"]
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Dolibarr is a modern software package to manage your organization's activity (co

## Supported tags

* 15.0.3-php7.4 15.0.3 15
* 16.0.5-php8.1 16.0.5 16
* 17.0.4-php8.1 17.0.4 17
* 18.0.5-php8.1 18.0.5 18
* 19.0.3-php8.2 19.0.3 19 latest
* develop
* 15.0.3-php7.4 15.0.3-php7.4-fpm 15.0.3 15 15.0.3-fpm 15-fpm
* 16.0.5-php8.1 16.0.5-php8.1-fpm 16.0.5 16 16.0.5-fpm 16-fpm
* 17.0.4-php8.1 17.0.4-php8.1-fpm 17.0.4 17 17.0.4-fpm 17-fpm
* 18.0.5-php8.1 18.0.5-php8.1-fpm 18.0.5 18 18.0.5-fpm 18-fpm
* 19.0.3-php8.2 19.0.3-php8.2-fpm 19.0.3 19 19.0.3-fpm 19-fpm latest latest-fpm
* develop develop-fpm

**End of support for PHP < 7.4**

Expand Down
12 changes: 11 additions & 1 deletion docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ EOF

if [[ ! -f /var/www/html/conf/conf.php ]]; then
echo "[INIT] => update Dolibarr Config ..."
mkdir /var/www/html/conf
cat > /var/www/html/conf/conf.php << EOF
<?php
\$dolibarr_main_url_root='${DOLI_URL_ROOT}';
Expand Down Expand Up @@ -155,6 +156,13 @@ function runScripts()
fi
}

# Function called to update the htdocs folde with the new code
function updateHtdocs()
{
echo "Updating htdocs folder..."
rsync -rlD --chown www-data:www-data --delete --exclude custom --exclude conf/conf.php /usr/src/dolibarr/ /var/www/html/
}

# Function called to initialize the database (creation of tables and init data)
function initializeDatabase()
{
Expand Down Expand Up @@ -202,7 +210,7 @@ function initializeDatabase()

if [[ ${DOLI_INIT_DEMO} -eq 1 ]]; then
mkdir -p /var/www/dev/initdemo/
> /var/www/documents/vi
> /var/www/documents/vi
versiondemo=`echo "${DOLI_VERSION}" | sed "s/^\([0-9]*\.[0-9]*\).*/\1.0/"`
echo "Get demo data from file https://raw.githubusercontent.com/Dolibarr/dolibarr/${DOLI_VERSION}/dev/initdemo/mysqldump_dolibarr_$versiondemo.sql ..."
curl -fLSs -o /var/www/dev/initdemo/initdemo.sql https://raw.githubusercontent.com/Dolibarr/dolibarr/${DOLI_VERSION}/dev/initdemo/mysqldump_dolibarr_$versiondemo.sql
Expand Down Expand Up @@ -281,11 +289,13 @@ function run()
mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "SELECT Q.LAST_INSTALLED_VERSION FROM (SELECT INET_ATON(CONCAT(value, REPEAT('.0', 3 - CHAR_LENGTH(value) + CHAR_LENGTH(REPLACE(value, '.', ''))))) as VERSION_ATON, value as LAST_INSTALLED_VERSION FROM llx_const WHERE name IN ('MAIN_VERSION_LAST_INSTALL', 'MAIN_VERSION_LAST_UPGRADE') and entity=0) Q ORDER BY VERSION_ATON DESC LIMIT 1" > /tmp/lastinstall.result 2>&1
r=$?
if [[ ${r} -ne 0 ]]; then
updateHtdocs
initializeDatabase
else
INSTALLED_VERSION=`grep -v LAST_INSTALLED_VERSION /tmp/lastinstall.result`
echo "Last installed Version is : ${INSTALLED_VERSION}"
if [[ "$(echo ${INSTALLED_VERSION} | cut -d. -f1)" -lt "$(echo ${DOLI_VERSION} | cut -d. -f1)" ]]; then
updateHtdocs
migrateDatabase
else
echo "Schema update is not required ... Enjoy !!"
Expand Down
65 changes: 65 additions & 0 deletions examples/with-fpm-nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

upstream dolibarr {
server dolibarr:9000;
}

server {
listen 80;
keepalive_timeout 70;

root /var/www/html/;
index index.php;

try_files $uri $uri/ =404;

location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;

# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";

fastcgi_pass dolibarr;
fastcgi_index index.php;

include fastcgi_params;

fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $request_filename;

# Dolibarr Rest API path support
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $request_filename;
fastcgi_param CONTEXT_DOCUMENT_ROOT $document_root;
}

client_max_body_size 8m;
}
}
53 changes: 53 additions & 0 deletions examples/with-fpm-nginx/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
networks:
internal-pod:
internal: true
external-pod:
internal: false

volumes:
dolibarr-htdocs:
dolibarr-custom:
dolibarr-docs:
mysql-data:

services:
nginx:
image: nginx
ports:
- 80:80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
- dolibarr-htdocs:/var/www/html:ro
- dolibarr-custom:/var/www/html/custom:ro
networks:
- internal-pod
- external-pod

dolibarr:
image: dolibarr/dolibarr:latest-fpm
environment:
DOLI_DB_HOST: "mysql"
DOLI_DB_HOST_PORT: "3306"
DOLI_DB_USER: "dolibarr"
DOLI_DB_PASSWORD: "mysupersecretpasswordfordatabase"
DOLI_DB_NAME: "dolibarr"
DOLI_ADMIN_LOGIN: "admin"
DOLI_ADMIN_PASSWORD: "mysuperhypersecretpasswordforadminacount"
volumes:
- dolibarr-docs:/var/www/documents
- dolibarr-htdocs:/var/www/html
- dolibarr-custom:/var/www/html/custom
networks:
- internal-pod

mysql:
image: mysql:latest
environment:
MYSQL_DATABASE: "dolibarr"
MYSQL_USER: "dolibarr"
MYSQL_PASSWORD: "mysupersecretpasswordfordatabase"
MYSQL_ROOT_PASSWORD: "mysupersupersecretpasswordforrootuser"
volumes:
- mysql-data:/var/lib/mysql
networks:
- internal-pod
3 changes: 3 additions & 0 deletions examples/with-fpm-nginx/dolibarr-with-fpm-nginx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Dolibarr with FPM and Nginx

This example use the PHP-FPM image with Nginx instead of Apache2.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ ENV PHP_INI_UPLOAD_MAX_FILESIZE 2M
ENV PHP_INI_POST_MAX_SIZE 8M
ENV PHP_INI_ALLOW_URL_FOPEN 0

RUN sed -i \
-e 's/^\(ServerSignature On\)$/#\1/g' \
-e 's/^#\(ServerSignature Off\)$/\1/g' \
-e 's/^\(ServerTokens\) OS$/\1 Prod/g' \
/etc/apache2/conf-available/security.conf
RUN sed -i -e 's/^\(ServerSignature On\)$/#\1/g' -e 's/^#\(ServerSignature Off\)$/\1/g' -e 's/^\(ServerTokens\) OS$/\1 Prod/g' /etc/apache2/conf-available/security.conf

RUN apt-get update -y \
&& apt-get dist-upgrade -y \
Expand All @@ -61,6 +57,7 @@ RUN apt-get update -y \
default-mysql-client \
postgresql-client \
cron \
rsync \
&& apt-get autoremove -y \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) calendar intl mysqli pdo_mysql gd soap zip \
Expand All @@ -76,7 +73,8 @@ RUN apt-get update -y \
# Get Dolibarr
RUN curl -fLSs https://github.com/Dolibarr/dolibarr/archive/${DOLI_VERSION}.tar.gz |\
tar -C /tmp -xz && \
cp -r /tmp/dolibarr-${DOLI_VERSION}/htdocs/* /var/www/html/ && \
mkdir -p /usr/src/dolibarr && \
cp -r /tmp/dolibarr-${DOLI_VERSION}/htdocs/* /usr/src/dolibarr/ && \
ln -s /var/www/html /var/www/htdocs && \
cp -r /tmp/dolibarr-${DOLI_VERSION}/scripts /var/www/ && \
rm -rf /tmp/* && \
Expand All @@ -86,6 +84,7 @@ RUN curl -fLSs https://github.com/Dolibarr/dolibarr/archive/${DOLI_VERSION}.tar.

EXPOSE 80
VOLUME /var/www/documents
VOLUME /var/www/html
VOLUME /var/www/html/custom

COPY docker-init.php /var/www/scripts/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ EOF

if [[ ! -f /var/www/html/conf/conf.php ]]; then
echo "[INIT] => update Dolibarr Config ..."
mkdir /var/www/html/conf
cat > /var/www/html/conf/conf.php << EOF
<?php
\$dolibarr_main_url_root='${DOLI_URL_ROOT}';
Expand Down Expand Up @@ -155,6 +156,13 @@ function runScripts()
fi
}

# Function called to update the htdocs folde with the new code
function updateHtdocs()
{
echo "Updating htdocs folder..."
rsync -rlD --chown www-data:www-data --delete --exclude custom --exclude conf/conf.php /usr/src/dolibarr/ /var/www/html/
}

# Function called to initialize the database (creation of tables and init data)
function initializeDatabase()
{
Expand Down Expand Up @@ -202,7 +210,7 @@ function initializeDatabase()

if [[ ${DOLI_INIT_DEMO} -eq 1 ]]; then
mkdir -p /var/www/dev/initdemo/
> /var/www/documents/vi
> /var/www/documents/vi
versiondemo=`echo "${DOLI_VERSION}" | sed "s/^\([0-9]*\.[0-9]*\).*/\1.0/"`
echo "Get demo data from file https://raw.githubusercontent.com/Dolibarr/dolibarr/${DOLI_VERSION}/dev/initdemo/mysqldump_dolibarr_$versiondemo.sql ..."
curl -fLSs -o /var/www/dev/initdemo/initdemo.sql https://raw.githubusercontent.com/Dolibarr/dolibarr/${DOLI_VERSION}/dev/initdemo/mysqldump_dolibarr_$versiondemo.sql
Expand Down Expand Up @@ -281,11 +289,13 @@ function run()
mysql -u ${DOLI_DB_USER} -p${DOLI_DB_PASSWORD} -h ${DOLI_DB_HOST} -P ${DOLI_DB_HOST_PORT} ${DOLI_DB_NAME} -e "SELECT Q.LAST_INSTALLED_VERSION FROM (SELECT INET_ATON(CONCAT(value, REPEAT('.0', 3 - CHAR_LENGTH(value) + CHAR_LENGTH(REPLACE(value, '.', ''))))) as VERSION_ATON, value as LAST_INSTALLED_VERSION FROM llx_const WHERE name IN ('MAIN_VERSION_LAST_INSTALL', 'MAIN_VERSION_LAST_UPGRADE') and entity=0) Q ORDER BY VERSION_ATON DESC LIMIT 1" > /tmp/lastinstall.result 2>&1
r=$?
if [[ ${r} -ne 0 ]]; then
updateHtdocs
initializeDatabase
else
INSTALLED_VERSION=`grep -v LAST_INSTALLED_VERSION /tmp/lastinstall.result`
echo "Last installed Version is : ${INSTALLED_VERSION}"
if [[ "$(echo ${INSTALLED_VERSION} | cut -d. -f1)" -lt "$(echo ${DOLI_VERSION} | cut -d. -f1)" ]]; then
updateHtdocs
migrateDatabase
else
echo "Schema update is not required ... Enjoy !!"
Expand Down
Loading
Loading