#!/bin/bash set -e # Update `myhostname` in Postfix in order to send emails postconf -e myhostname=$(hostname) if [ -n "$NEW_RELIC_LICENSE_KEY" ]; then echo '[ New Relic ] Enabled' sed -i 's/;extension/extension/' $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini sed -i -e "s/REPLACE_WITH_REAL_KEY/$NEW_RELIC_LICENSE_KEY/" $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini sed -i -e '$anewrelic.distributed_tracing_enabled=true' $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini if [ -n "$NEW_RELIC_DAEMON_ADDRESS" ]; then echo "[ New Relic ] Daemon address set to $NEW_RELIC_DAEMON_ADDRESS:31339" echo "newrelic.daemon.address=\"$NEW_RELIC_DAEMON_ADDRESS:31339\"" >> $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini fi if [ -n "$NEW_RELIC_APPNAME" ]; then echo "[ New Relic ] App name set to $NEW_RELIC_APPNAME" sed -i -e "s/newrelic.appname[[:space:]]=[[:space:]].*/newrelic.appname=\"$NEW_RELIC_APPNAME\"/" $(php -r "echo(PHP_CONFIG_FILE_SCAN_DIR);")/newrelic.ini fi fi if [ "$ENV" != "prod" ]; then echo "Environment is set to DEV" # Disable Opcache echo "[ opcache ] Configuring dev mode" sed -i "s/opcache.revalidate_freq\s*=\s*[[:digit:]]\+/opcache.revalidate_freq=0/" /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini # Enable Blackfire if [ "$PHP_BLACKFIRE_ENABLED" = "1" ]; then echo "[ blackfire ] Enabling Blackfire" sed -i "s/^;//" /usr/local/etc/php/conf.d/blackfire.ini fi # Enable XDebug if not disabled explicitly if [ "$PHP_XDEBUG_ENABLED" != "0" ]; then echo "[ xdebug ] Enabled" sed -i "1s/^;//" /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini if [ -z "$XDEBUG_CLIENT_HOST" ]; then docker_host_ip=$( (dig +time=1 +tries=2 +short host.docker.internal | grep -v ';;' | head -1) || true ) if [ "$docker_host_ip" != "" ]; then # MacOS XDEBUG_CLIENT_HOST=$docker_host_ip else # Linux XDEBUG_CLIENT_HOST=$(ip route show | awk '/default/ {print $3}') fi fi if [ -n "$XDEBUG_CLIENT_HOST" ]; then echo "[ xdebug ] Set client host to $XDEBUG_CLIENT_HOST" sed -i "s/xdebug.client_host\s*=\s*.*/xdebug.client_host=$XDEBUG_CLIENT_HOST/" /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini fi if [ -n "$XDEBUG_CLIENT_PORT" ]; then echo "[ xdebug ] Set client port to $XDEBUG_CLIENT_PORT" sed -i "s/xdebug.client_port\s*=\s*.*/xdebug.client_port=$XDEBUG_CLIENT_PORT/" /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini fi if [ -n "$XDEBUG_START_WITH_REQUEST" ]; then echo "[ xdebug ] Set xdebug.start_with_request to $XDEBUG_START_WITH_REQUEST" sed -i "s/xdebug.start_with_request\s*=\s*.*/xdebug.start_with_request=$XDEBUG_START_WITH_REQUEST/" /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini fi fi fi # first arg is `-f` or `--some-option` if [ "${1#-}" != "$1" ]; then set -- php-fpm "$@" fi # first arg is `sh` or `bash` if [ "$1" = 'sh' ] || [ "$1" = 'bash' ]; then # GitLab Says: # To ensure a job can run, its Docker image must: # - Provide sh or bash # - Define an ENTRYPOINT that starts a shell when passed sh/bash as argument set -- "$@" fi exec "$@"