-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds support for run-time configuration which is executed as part of the startup of the container. Two options are supported: * shell scripts; and * .ini files for PHP configuration. These can be placed into a new directory, located at /docker-entrypoint-initdb.d and files are executed in lexical order returned by a bash glob.
- Loading branch information
1 parent
251fea0
commit 7c90b9c
Showing
9 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
|
||
docker_process_init_files() { | ||
local f | ||
for f; do | ||
case "$f" in | ||
*.sh) | ||
# Note: This hack is required for MacOS because the exeute bit is not checked for bind mounts. | ||
# The executable bit is stored, but the test -x flag does not return corretly. | ||
# Copying the file to an alternate file system allows it to be respected. | ||
rm -f /tmp/testscript | ||
cp "$f" /tmp/testscript | ||
if [ -x "/tmp/testscript" ]; then | ||
echo "$0: running $f" | ||
"$f" | ||
else | ||
echo "$0: sourcing $f" | ||
. "$f" | ||
fi | ||
;; | ||
*.ini) | ||
echo "$0: copying $f into /usr/local/etc/php/conf.d/" | ||
cp "$f" /usr/local/etc/php/conf.d/ | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
echo "Running entrypoint files from /docker-entrypoint.d/*" | ||
docker_process_init_files /docker-entrypoint.d/* | ||
echo | ||
|
||
echo "Starting docker-php-entrypoint with $@" | ||
source /usr/local/bin/docker-php-entrypoint | ||
echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
; Test file which disable file uploads. | ||
file_uploads = Off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file should not have a shbang! as it is expected to be sourced. | ||
# It should not be executable either. | ||
|
||
mkdir -p /var/www/data | ||
|
||
(return 0 2>/dev/null) && sourced=1 || sourced=0 | ||
|
||
if [ $(sourced) -eq 1 ]; then | ||
echo "Sourced" >> /var/www/data/sourced.txt | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file should not have a shbang! as it is expected to be sourced. | ||
# It should not be executable either. | ||
|
||
mkdir -p /var/www/data | ||
|
||
(return 0 2>/dev/null) && sourced=1 || sourced=0 | ||
|
||
if [ $(sourced) -eq 0 ]; then | ||
echo "Executed" >> /var/www/data/executed.txt | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
$sourced = file_exists('/var/www/data/sourced.txt'); | ||
$executed = file_exists('/var/www/data/executed.txt'); | ||
|
||
if (php_sapi_name() === 'cli') { | ||
if ($sourced && $executed) { | ||
echo "OK\n"; | ||
exit(0); | ||
} else if ($sourced && !$executed) { | ||
echo "Executable file was not executed"; | ||
} else { | ||
echo "non-executable file was not sourced"; | ||
} | ||
exit(1); | ||
} else { | ||
if ($sourced && $executed) { | ||
header('HTTP/1.1 200 - OK'); | ||
exit(0); | ||
} else if ($sourced && !$executed) { | ||
$message = "Executable file was not executed"; | ||
} else { | ||
$message = "non-executable file was not sourced"; | ||
} | ||
header('HTTP/1.1 500 - ' . $message); | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
$uploadsEnabled = ini_get('file_uploads'); | ||
|
||
if (php_sapi_name() === 'cli') { | ||
if (empty($uploadsEnabled)) { | ||
echo "OK\n"; | ||
exit(0); | ||
} | ||
echo "Uploads are enabled and should be disabled."; | ||
var_dump($uploadsEnabled); | ||
exit(1); | ||
} else { | ||
if (empty($uploadsEnabled)) { | ||
header('HTTP/1.1 200 - OK'); | ||
exit(0); | ||
} | ||
header('HTTP/1.1 500 - Uploads are enabled and should be disabled: ' . var_export($uploadsEnabled, true)); | ||
exit(1); | ||
} |