This developer needed to turn back the clock in the PHP-FPM container, you will not believe what he did next! (#1675)

* Added documentation for installing libfaketime in the php-fpm container
* Enabled installing and using libfaketime system-wide inside the php-fpm container
This commit is contained in:
Youri Westerman 2018-08-21 12:41:34 +07:00 committed by Shao Yu-Lung (Allen)
parent 1b865dd153
commit 89051de67d
4 changed files with 45 additions and 0 deletions

View File

@ -1499,10 +1499,33 @@ e) set it to `true`
3 - Set it to `true`
<br>
4 - Re-build the containers `docker-compose build php-fpm`
<br>
<br>
<a name="Install-Faketime"></a>
## Install libfaketime in the php-fpm container
Libfaketime allows you to control the date and time that is returned from the operating system.
It can be used by specifying a special string in the `PHP_FPM_FAKETIME` variable in the `.env` file.
For example:
`PHP_FPM_FAKETIME=-1d`
will set the clock back 1 day. See (https://github.com/wolfcw/libfaketime) for more information.
1 - Open the `.env` file
<br>
2 - Search for the `PHP_FPM_INSTALL_FAKETIME` argument under the PHP-FPM container
<br>
3 - Set it to `true`
<br>
4 - Search for the `PHP_FPM_FAKETIME` argument under the PHP-FPM container
<br>
5 - Set it to the desired string
<br>
6 - Re-build the containers `docker-compose build php-fpm`<br>
<br>
<a name="phpstorm-debugging"></a>

View File

@ -144,6 +144,7 @@ services:
- INSTALL_IMAGE_OPTIMIZERS=${PHP_FPM_INSTALL_IMAGE_OPTIMIZERS}
- INSTALL_IMAGEMAGICK=${PHP_FPM_INSTALL_IMAGEMAGICK}
- INSTALL_CALENDAR=${PHP_FPM_INSTALL_CALENDAR}
- INSTALL_FAKETIME=${PHP_FPM_INSTALL_FAKETIME}
volumes:
- ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
@ -154,6 +155,7 @@ services:
environment:
- PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
- DOCKER_HOST=tcp://docker-in-docker:2375
- FAKETIME=${PHP_FPM_FAKETIME}
depends_on:
- workspace
networks:

View File

@ -149,6 +149,8 @@ PHP_FPM_INSTALL_SWOOLE=false
PHP_FPM_INSTALL_PG_CLIENT=false
PHP_FPM_INSTALL_PCNTL=false
PHP_FPM_INSTALL_CALENDAR=false
PHP_FPM_INSTALL_FAKETIME=false
PHP_FPM_FAKETIME=-0
### PHP_WORKER ############################################

View File

@ -485,6 +485,18 @@ RUN if [ ${INSTALL_CALENDAR} = true ]; then \
docker-php-ext-install calendar \
;fi
###########################################################################
# libfaketime:
###########################################################################
USER root
ARG INSTALL_FAKETIME=false
RUN if [ ${INSTALL_FAKETIME} = true ]; then \
apt-get install -y libfaketime \
;fi
###########################################################################
# Check PHP version:
###########################################################################
@ -509,6 +521,12 @@ RUN apt-get clean && \
RUN usermod -u 1000 www-data
# Adding the faketime library to the preload file needs to be done last
# otherwise it will preload it for all commands that follow in this file
RUN if [ ${INSTALL_FAKETIME} = true ]; then \
echo "/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1" > /etc/ld.so.preload \
;fi
WORKDIR /var/www
CMD ["php-fpm"]