dumamai/java-fpm
0
1#!/bin/bash2 3# Disable Strict Host checking for non interactive git clones4 5mkdir -p -m 0700 /root/.ssh6# Prevent config files from being filled to infinity by force of stop and restart the container 7echo "" > /root/.ssh/config8echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config9 10if [[ "$GIT_USE_SSH" == "1" ]] ; then11 echo -e "Host *\n\tUser ${GIT_USERNAME}\n\n" >> /root/.ssh/config12fi13 14if [ ! -z "$SSH_KEY" ]; then15 echo $SSH_KEY > /root/.ssh/id_rsa.base6416 base64 -d /root/.ssh/id_rsa.base64 > /root/.ssh/id_rsa17 chmod 600 /root/.ssh/id_rsa18fi19 20# Set custom webroot21if [ ! -z "$WEBROOT" ]; then22 sed -i "s#root /var/www/html;#root ${WEBROOT};#g" /etc/nginx/sites-available/default.conf23else24 webroot=/var/www/html25fi26 27# Enables 404 pages through php index28if [ ! -z "$PHP_CATCHALL" ]; then29 sed -i 's#try_files $uri $uri/ =404;#try_files $uri $uri/ /index.php?$args;#g' /etc/nginx/sites-available/default.conf30fi31 32# Disable opcache33if [ ! -z "$OPcache" ]; then34 sed -i 's#zend_extension=opcache#;zend_extension=opcache#g' /usr/local/etc/php/php.ini35fi36 37# Setup git variables38if [ ! -z "$GIT_EMAIL" ]; then39 git config --global user.email "$GIT_EMAIL"40fi41if [ ! -z "$GIT_NAME" ]; then42 git config --global user.name "$GIT_NAME"43 git config --global push.default simple44fi45 46# Dont pull code down if the .git folder exists47if [ ! -d "/var/www/html/.git" ]; then48 # Pull down code from git for our site!49 if [ ! -z "$GIT_REPO" ]; then50 # Remove the test index file if you are pulling in a git repo51 if [ ! -z ${REMOVE_FILES} ] && [ ${REMOVE_FILES} == 0 ]; then52 echo "skiping removal of files"53 else54 rm -Rf /var/www/html/*55 fi56 GIT_COMMAND='git clone '57 if [ ! -z "$GIT_BRANCH" ]; then58 GIT_COMMAND=${GIT_COMMAND}" -b ${GIT_BRANCH}"59 fi60 61 if [ -z "$GIT_USERNAME" ] && [ -z "$GIT_PERSONAL_TOKEN" ]; then62 GIT_COMMAND=${GIT_COMMAND}" ${GIT_REPO}"63 else64 if [[ "$GIT_USE_SSH" == "1" ]]; then65 GIT_COMMAND=${GIT_COMMAND}" ${GIT_REPO}"66 else67 GIT_COMMAND=${GIT_COMMAND}" https://${GIT_USERNAME}:${GIT_PERSONAL_TOKEN}@${GIT_REPO}"68 fi69 fi70 ${GIT_COMMAND} /var/www/html || exit 171 if [ ! -z "$GIT_TAG" ]; then72 git checkout ${GIT_TAG} || exit 173 fi74 if [ ! -z "$GIT_COMMIT" ]; then75 git checkout ${GIT_COMMIT} || exit 176 fi77 if [ -z "$SKIP_CHOWN" ]; then78 chown -Rf nginx.nginx /var/www/html79 fi80 fi81fi82 83# Enable custom nginx config files if they exist84if [ -f /var/www/html/conf/nginx/nginx.conf ]; then85 cp /var/www/html/conf/nginx/nginx.conf /etc/nginx/nginx.conf86fi87 88if [ -f /var/www/html/conf/nginx/nginx-site.conf ]; then89 cp /var/www/html/conf/nginx/nginx-site.conf /etc/nginx/sites-available/default.conf90fi91 92if [ -f /var/www/html/conf/nginx/nginx-site-ssl.conf ]; then93 cp /var/www/html/conf/nginx/nginx-site-ssl.conf /etc/nginx/sites-available/default-ssl.conf94fi95 96 97# Prevent config files from being filled to infinity by force of stop and restart the container98lastlinephpconf="$(grep "." /usr/local/etc/php-fpm.conf | tail -1)"99if [[ $lastlinephpconf == *"php_flag[display_errors]"* ]]; then100 sed -i '$ d' /usr/local/etc/php-fpm.conf101fi102 103# Display PHP error's or not104if [[ "$ERRORS" != "1" ]] ; then105 echo php_flag[display_errors] = off >> /usr/local/etc/php-fpm.d/www.conf106else107 echo php_flag[display_errors] = on >> /usr/local/etc/php-fpm.d/www.conf108fi109 110# Display Version Details or not111if [[ "$HIDE_NGINX_HEADERS" == "0" ]] ; then112 sed -i "s/server_tokens off;/server_tokens on;/g" /etc/nginx/nginx.conf113else114 sed -i "s/expose_php = On/expose_php = Off/g" /usr/local/etc/php-fpm.conf115fi116 117# Pass real-ip to logs when behind ELB, etc118if [[ "$REAL_IP_HEADER" == "1" ]] ; then119 sed -i "s/#real_ip_header X-Forwarded-For;/real_ip_header X-Forwarded-For;/" /etc/nginx/sites-available/default.conf120 sed -i "s/#set_real_ip_from/set_real_ip_from/" /etc/nginx/sites-available/default.conf121 if [ ! -z "$REAL_IP_FROM" ]; then122 sed -i "s#172.16.0.0/12#$REAL_IP_FROM#" /etc/nginx/sites-available/default.conf123 fi124fi125# Do the same for SSL sites126if [ -f /etc/nginx/sites-available/default-ssl.conf ]; then127 if [[ "$REAL_IP_HEADER" == "1" ]] ; then128 sed -i "s/#real_ip_header X-Forwarded-For;/real_ip_header X-Forwarded-For;/" /etc/nginx/sites-available/default-ssl.conf129 sed -i "s/#set_real_ip_from/set_real_ip_from/" /etc/nginx/sites-available/default-ssl.conf130 if [ ! -z "$REAL_IP_FROM" ]; then131 sed -i "s#172.16.0.0/12#$REAL_IP_FROM#" /etc/nginx/sites-available/default-ssl.conf132 fi133 fi134fi135 136# Set the desired timezone137echo date.timezone=Europe/London > /usr/local/etc/php/conf.d/timezone.ini138 139# Display errors in docker logs140if [ ! -z "$PHP_ERRORS_STDERR" ]; then141 echo "log_errors = On" >> /usr/local/etc/php/conf.d/docker-vars.ini142 echo "error_log = /dev/stderr" >> /usr/local/etc/php/conf.d/docker-vars.ini143fi144 145# Increase the memory_limit146if [ ! -z "$PHP_MEM_LIMIT" ]; then147 sed -i "s/memory_limit = 128M/memory_limit = ${PHP_MEM_LIMIT}M/g" /usr/local/etc/php/conf.d/docker-vars.ini148fi149 150# Increase the post_max_size151if [ ! -z "$PHP_POST_MAX_SIZE" ]; then152 sed -i "s/post_max_size = 100M/post_max_size = ${PHP_POST_MAX_SIZE}M/g" /usr/local/etc/php/conf.d/docker-vars.ini153fi154 155# Increase the upload_max_filesize156if [ ! -z "$PHP_UPLOAD_MAX_FILESIZE" ]; then157 sed -i "s/upload_max_filesize = 100M/upload_max_filesize= ${PHP_UPLOAD_MAX_FILESIZE}M/g" /usr/local/etc/php/conf.d/docker-vars.ini158fi159 160# Enable xdebug161XdebugFile='/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini'162if [[ "$ENABLE_XDEBUG" == "1" ]] ; then163 if [ -f $XdebugFile ]; then164 echo "Xdebug enabled"165 else166 echo "Enabling xdebug"167 echo "If you get this error, you can safely ignore it: /usr/local/bin/docker-php-ext-enable: line 83: nm: not found"168 # see https://github.com/docker-library/php/pull/420169 docker-php-ext-enable xdebug170 # see if file exists171 if [ -f $XdebugFile ]; then172 # See if file contains xdebug text.173 if grep -q xdebug.remote_enable "$XdebugFile"; then174 echo "Xdebug already enabled... skipping"175 else176 echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > $XdebugFile # Note, single arrow to overwrite file.177 echo "xdebug.start_with_request=yes" >> $XdebugFile178 echo "xdebug.client_host=host.docker.internal" >> $XdebugFile179 echo "xdebug.mode=debug" >> $XdebugFile180 echo "xdebug.remote_log=/tmp/xdebug.log" >> $XdebugFile181 echo "xdebug.remote_autostart=false " >> $XdebugFile # I use the xdebug chrome extension instead of using autostart182 # NOTE: xdebug.remote_host is not needed here if you set an environment variable in docker-compose like so `- XDEBUG_CONFIG=remote_host=192.168.111.27`.183 # you also need to set an env var `- PHP_IDE_CONFIG=serverName=docker`184 fi185 fi186 fi187else188 if [ -f $XdebugFile ]; then189 echo "Disabling Xdebug"190 rm $XdebugFile191 fi192fi193 194if [ ! -z "$PUID" ]; then195 if [ -z "$PGID" ]; then196 PGID=${PUID}197 fi198 deluser nginx199 addgroup -g ${PGID} nginx200 adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx -u ${PUID} nginx201else202 if [ -z "$SKIP_CHOWN" ]; then203 chown -Rf nginx.nginx /var/www/html204 fi205fi206 207# Run custom scripts208#if [[ "$RUN_SCRIPTS" == "1" ]] ; then209# scripts_dir="${SCRIPTS_DIR:-/var/www/html/scripts}"210# if [ -d "$scripts_dir" ]; then211# if [ -z "$SKIP_CHMOD" ]; then212 # make scripts executable incase they aren't213# chmod -Rf 750 $scripts_dir; sync;214# fi215 # run scripts in number order216# for i in `ls $scripts_dir`; do $scripts_dir/$i ; done217# else218# echo "Can't find script directory"219# fi220#fi221 222composer install --no-dev --working-dir=/var/www/html223 224echo "Caching config..."225php artisan config:cache226 227echo "Caching routes..."228php artisan route:cache229 230if [ -z "$SKIP_COMPOSER" ]; then231 # Try auto install for composer232 if [ -f "/var/www/html/composer.lock" ]; then233 if [ "$APPLICATION_ENV" == "development" ]; then234 composer global require hirak/prestissimo235 composer install --working-dir=/var/www/html236 else237 composer global require hirak/prestissimo238 composer install --no-dev --working-dir=/var/www/html239 fi240 fi241fi242 243# Start supervisord and services244exec /usr/bin/supervisord -n -c /etc/supervisord.conf245 246 