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

Ensure that all the output on bootstrap goes to stderr #180

Open
wants to merge 1 commit 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
8 changes: 8 additions & 0 deletions .github/workflows/test_buildx_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ jobs:
docker exec test0 php /var/www/html/check-entrypoint-scripts.php
curl --fail http://127.0.0.1:8000/test.php
curl --fail http://127.0.0.1:8000/check-ini.php
# Verify that CLI execution only includes the expected output (if we discard stderr).
stdout=$(docker run --rm -v $PWD/tests/fixtures:/var/www/html \
moodle-php-apache php /var/www/html/check-stderr.php 2>/dev/null)
[[ ${stdout} == "Hello World!" ]] && echo "OK" || echo "Fail"
# Verify that stderr still contains information about the bootstrap.
stdout=$(docker run --rm -v $PWD/tests/fixtures:/var/www/html \
moodle-php-apache php /var/www/html/check-stderr.php 2>&1)
[[ ${stdout} =~ "Checking for php configuration" ]] && echo "OK" || echo "Fail"

- name: Display container logs on failure
if: failure()
Expand Down
15 changes: 6 additions & 9 deletions root/usr/local/bin/moodle-docker-php-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,26 @@ docker_process_init_files() {
rm -f /tmp/testscript
cp "$f" /tmp/testscript
if [ -x "/tmp/testscript" ]; then
echo "$0: running $f"
echo "$0: running $f" >/dev/stderr
"$f"
else
echo "$0: sourcing $f"
echo "$0: sourcing $f" >/dev/stderr
. "$f"
fi
;;
*.ini)
echo "$0: copying $f into /usr/local/etc/php/conf.d/"
echo "$0: copying $f into /usr/local/etc/php/conf.d/" >/dev/stderr
cp "$f" /usr/local/etc/php/conf.d/
;;
esac
done
}

echo "Running PHP Configuration fetcher"
echo "Running PHP Configuration fetcher" >/dev/stderr
/usr/local/bin/moodle-docker-php-ini
echo

echo "Running entrypoint files from /docker-entrypoint.d/*"
echo "Running entrypoint files from /docker-entrypoint.d/*" >/dev/stderr
docker_process_init_files /docker-entrypoint.d/*
echo

echo "Starting docker-php-entrypoint with $@"
echo "Starting docker-php-entrypoint with $@" >/dev/stderr
source /usr/local/bin/docker-php-entrypoint
echo
10 changes: 5 additions & 5 deletions root/usr/local/bin/moodle-docker-php-ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

echo "Checking for php configuration in environment"
echo "Checking for php configuration in environment" >/dev/stderr

localinifile="/usr/local/etc/php/conf.d/20-local.ini"

Expand All @@ -18,7 +18,7 @@ env | while IFS= read -r line; do
fullname=${line%%=*}
if [[ $fullname = PHP_INI-* ]]; then
name=`echo $fullname | sed 's/^PHP_INI-//'`
echo "=> Found '${name}' with value '${value}'"
echo "=> Found '${name}' with value '${value}'" >/dev/stderr

cat << EOF >> $localinifile
; $fullname=$value
Expand All @@ -29,11 +29,11 @@ EOF

if [[ $fullname = PHP_EXTENSION_* ]]; then
extension=`echo $fullname | sed 's/^PHP_EXTENSION_//'`
echo "=> Found extension to enable: '${extension}'"
echo "=> Found extension to enable: '${extension}'" >/dev/stderr
if [[ -f "/usr/local/etc/php/conf.d/docker-php-ext-${extension}.ini" ]]; then
echo "=> Extension already enabled: '${extension}'"
echo "=> Extension already enabled: '${extension}'" >/dev/stderr
else
echo "=> Enabling extension '${extension}'"
echo "=> Enabling extension '${extension}'" >/dev/stderr
docker-php-ext-enable ${extension}
fi
fi
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/check-stderr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

echo "Hello World!";