Skip to content

Commit

Permalink
optimized statements to have smalle image
Browse files Browse the repository at this point in the history
  • Loading branch information
MyUncleSam committed Nov 23, 2020
1 parent 4f353b3 commit 3fd3bad
Showing 1 changed file with 55 additions and 64 deletions.
119 changes: 55 additions & 64 deletions php-7.4/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,85 +10,76 @@ ENV MEMORY_LIMIT="512M"
ENV CRON_INTERVAL="* * * * *"

# install dependencies
RUN /usr/bin/apt-get update
RUN /usr/bin/apt-get install -y wget libzip-dev libcurl4-openssl-dev libpng-dev unzip tzdata cron libfreetype6-dev libjpeg-dev libpng-dev memcached libmemcached-dev

# set timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# link extensions directory
RUN ln -s $(php-config --extension-dir --extension-dir) /php_ext
# set timezone and link extensions directory
# create tsi base folder
RUN /usr/bin/apt-get update \
&& /usr/bin/apt-get install -y wget libzip-dev libcurl4-openssl-dev libpng-dev unzip tzdata cron libfreetype6-dev libjpeg-dev libpng-dev memcached libmemcached-dev \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
&& ln -s $(php-config --extension-dir --extension-dir) /php_ext \
&& mkdir /opt/tsi

# there is a bug by gd configuration of freetype, it needs to be installed at first to be able to enable freetype
# https://github.com/docker-library/php/issues/926#issuecomment-567230723
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-configure zip

RUN docker-php-ext-install -j$(nproc) gd curl zip bcmath pdo pdo_mysql opcache

# installing ioncube
RUN wget -O /tmp/ioncube.tar.gz https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
RUN tar -xvzf /tmp/ioncube.tar.gz --directory=/tmp
# also install ioncube
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg \
&& docker-php-ext-configure zip \\
&& docker-php-ext-install -j$(nproc) gd curl zip bcmath pdo pdo_mysql opcache \
&& wget -O /tmp/ioncube.tar.gz https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz \
&& tar -xvzf /tmp/ioncube.tar.gz --directory=/tmp

# ioncube needs to be loaded as first plugin, as they are loaded in alphabetical order, we need to make it the first in line
RUN cp /tmp/ioncube/ioncube_loader_lin_7.4.so /php_ext/ioncube.so
RUN PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "zend_extension = $PHP_EXT_DIR/ioncube.so" > /usr/local/etc/php/conf.d/_ioncube.ini

# installing and enabling cache extensions
RUN printf '\n' | pecl install apcu
RUN printf '\n' | pecl install memcached
RUN printf '\n' | pecl install redis
RUN printf '\n' | pecl install mongodb

RUN PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/memcached.so" > /usr/local/etc/php/conf.d/cache-extensions.ini
RUN PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/apcu.so" >> /usr/local/etc/php/conf.d/cache-extensions.ini
RUN PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/redis.so" >> /usr/local/etc/php/conf.d/cache-extensions.ini
RUN PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/mongodb.so" >> /usr/local/etc/php/conf.d/cache-extensions.ini

# enabling apache modules
RUN /usr/sbin/a2enmod rewrite
# also installing and enabling cache extensions and enable mod rewrite
RUN cp /tmp/ioncube/ioncube_loader_lin_7.4.so /php_ext/ioncube.so \
&& PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) \
&& echo "zend_extension = $PHP_EXT_DIR/ioncube.so" > /usr/local/etc/php/conf.d/_ioncube.ini \
&& printf '\n' | pecl install apcu \
&& printf '\n' | pecl install memcached \
&& printf '\n' | pecl install redis \
&& printf '\n' | pecl install mongodb \
&& PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/memcached.so" > /usr/local/etc/php/conf.d/cache-extensions.ini \
&& PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/apcu.so" >> /usr/local/etc/php/conf.d/cache-extensions.ini \
&& PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/redis.so" >> /usr/local/etc/php/conf.d/cache-extensions.ini \
&& PHP_EXT_DIR=$(php-config --extension-dir --extension-dir) && echo "extension=$PHP_EXT_DIR/mongodb.so" >> /usr/local/etc/php/conf.d/cache-extensions.ini \
&& /usr/sbin/a2enmod rewrite

# php configuration
RUN echo "max_execution_time = ${MAX_EXECUTION_TIME}" > /usr/local/etc/php/conf.d/tsi-config.ini
RUN echo "max_input_time = ${MAX_INPUT_TIME}" >> /usr/local/etc/php/conf.d/tsi-config.ini
RUN echo "post_max_size = ${POST_MAX_SIZE}" >> /usr/local/etc/php/conf.d/tsi-config.ini
RUN echo "upload_max_filesize = ${UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/tsi-config.ini
RUN echo "allow_url_fopen = on" >> /usr/local/etc/php/conf.d/tsi-config.ini
RUN echo "memory_limit = ${MEMORY_LIMIT}" >> /usr/local/etc/php/conf.d/tsi-config.ini

# prepare tsi folder
RUN mkdir /opt/tsi
RUN echo "max_execution_time = ${MAX_EXECUTION_TIME}" > /usr/local/etc/php/conf.d/tsi-config.ini \
&&echo "max_input_time = ${MAX_INPUT_TIME}" >> /usr/local/etc/php/conf.d/tsi-config.ini \
&& echo "post_max_size = ${POST_MAX_SIZE}" >> /usr/local/etc/php/conf.d/tsi-config.ini \
&& echo "upload_max_filesize = ${UPLOAD_MAX_FILESIZE}" >> /usr/local/etc/php/conf.d/tsi-config.ini \
&& echo "allow_url_fopen = on" >> /usr/local/etc/php/conf.d/tsi-config.ini \
&& echo "memory_limit = ${MEMORY_LIMIT}" >> /usr/local/etc/php/conf.d/tsi-config.ini

# create cronjob file to only execute if cron.php is available
RUN echo "#!/bin/bash" > /opt/tsi/cron.sh
RUN echo "" >> /opt/tsi/cron.sh
RUN echo "if [ -f /var/www/html/inc/cron.php ]; then" >> /opt/tsi/cron.sh
RUN echo " echo 'Found cron.php file'" >> /opt/tsi/cron.sh
RUN echo " /usr/local/bin/php /var/www/html/inc/cron.php" >> /opt/tsi/cron.sh
RUN echo "fi" >> /opt/tsi/cron.sh
RUN chmod a+r /opt/tsi/cron.sh
RUN chmod a+x /opt/tsi/cron.sh
RUN echo "#!/bin/bash" > /opt/tsi/cron.sh \
&& echo "" >> /opt/tsi/cron.sh \
&& echo "if [ -f /var/www/html/inc/cron.php ]; then" >> /opt/tsi/cron.sh \
&& echo " echo 'Found cron.php file'" >> /opt/tsi/cron.sh \
&& echo " /usr/local/bin/php /var/www/html/inc/cron.php" >> /opt/tsi/cron.sh \
&& echo "fi" >> /opt/tsi/cron.sh \
&& chmod a+r /opt/tsi/cron.sh \
&& chmod a+x /opt/tsi/cron.sh

# add cronjob which is executed every minute
RUN echo "# tsi crontab import file" > /opt/tsi/crontab-file.txt
RUN echo "${CRON_INTERVAL} /opt/tsi/cron.sh > /dev/null 2>&1" >> /opt/tsi/crontab-file.txt
RUN crontab -u www-data /opt/tsi/crontab-file.txt
RUN echo "# tsi crontab import file" > /opt/tsi/crontab-file.txt \
&& echo "${CRON_INTERVAL} /opt/tsi/cron.sh > /dev/null 2>&1" >> /opt/tsi/crontab-file.txt \
&& crontab -u www-data /opt/tsi/crontab-file.txt

# custom startscript to modify permissions
RUN echo "#!/bin/bash" > /opt/tsi/start.sh
RUN echo "chown -c -R www-data: /var/www/html" >> /opt/tsi/start.sh
RUN echo "cron &" >> /opt/tsi/start.sh
RUN echo "apache2-foreground" >> /opt/tsi/start.sh
RUN chmod u+x /opt/tsi/start.sh
RUN echo "#!/bin/bash" > /opt/tsi/start.sh \
&& echo "chown -c -R www-data: /var/www/html" >> /opt/tsi/start.sh \
&& echo "cron &" >> /opt/tsi/start.sh \
&& echo "apache2-foreground" >> /opt/tsi/start.sh \
&& chmod u+x /opt/tsi/start.sh

# cleanup
RUN rm /php_ext
RUN rm -rf /tmp/*
RUN rm /opt/tsi/crontab-file.txt
RUN apt-get remove -y wget unzip
RUN apt-get autoclean -y
RUN apt-get clean -y
RUN apt-get autoremove -y
RUN rm /php_ext \
&& rm -rf /tmp/* \
&& rm /opt/tsi/crontab-file.txt \
&& apt-get remove -y wget unzip \
&& apt-get autoclean -y \
&& apt-get clean -y \
&& apt-get autoremove -y

# volumes
VOLUME ["/var/www/html", "/var/www/html"]
Expand Down

0 comments on commit 3fd3bad

Please sign in to comment.