Skip to content
Closed
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
58 changes: 58 additions & 0 deletions 4/evo-fastcgi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
FROM php:7.4-fpm-alpine

RUN echo "upload_max_filesize = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "post_max_size = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "memory_limit = 1G" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "max_execution_time = 600" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "max_input_vars = 5000" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini

RUN addgroup -S adminer \
&& adduser -S -G adminer adminer \
&& mkdir -p /var/www/html \
&& mkdir /var/www/html/plugins-enabled \
&& chown -R adminer:adminer /var/www/html

RUN set -x \
&& apk add --no-cache --virtual .build-deps \
postgresql-dev \
sqlite-dev \
unixodbc-dev \
freetds-dev \
&& docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
&& docker-php-ext-install \
mysqli \
pdo_pgsql \
pdo_sqlite \
pdo_odbc \
pdo_dblib \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --virtual .phpexts-rundeps $runDeps \
&& apk del --no-network .build-deps

COPY *.php /var/www/html/

ENV ADMINER_VERSION 4.8.4
ENV ADMINER_DOWNLOAD_SHA256 e9a9bc2cc2ac46d6d92f008de9379d2b21a3764a5f8956ed68456e190814b149
ENV ADMINER_COMMIT f1e13af9252bfd88d816ef72593513c13adf1dd5

RUN set -x \
&& apk add --no-cache --virtual .build-deps git \
&& curl -fsSL "https://github.com/adminerevo/adminerevo/releases/download/v$ADMINER_VERSION/adminer-$ADMINER_VERSION.php" -o adminer.php \
&& echo "$ADMINER_DOWNLOAD_SHA256 adminer.php" |sha256sum -c - \
&& git clone --recurse-submodules=designs --depth 1 --shallow-submodules --branch "v$ADMINER_VERSION" https://github.com/adminerevo/adminerevo.git /tmp/adminer \
&& commit="$(git -C /tmp/adminer/ rev-parse HEAD)" \
&& [ "$commit" = "$ADMINER_COMMIT" ] \
&& cp -r /tmp/adminer/designs/ /tmp/adminer/plugins/ . \
&& rm -rf /tmp/adminer/ \
&& apk del --no-network .build-deps

COPY entrypoint.sh /usr/local/bin/
ENTRYPOINT [ "entrypoint.sh", "docker-php-entrypoint" ]

USER adminer
CMD [ "php-fpm" ]
20 changes: 20 additions & 0 deletions 4/evo-fastcgi/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
set -e

if [ -n "$ADMINER_DESIGN" ]; then
# Only create link on initial start, to ensure that explicit changes to
# adminer.css after the container was started once are preserved.
if [ ! -e .adminer-init ]; then
ln -sf "designs/$ADMINER_DESIGN/adminer.css" .
fi
fi

number=1
for PLUGIN in $ADMINER_PLUGINS; do
php plugin-loader.php "$PLUGIN" > plugins-enabled/$(printf "%03d" $number)-$PLUGIN.php
number=$(($number+1))
done

touch .adminer-init || true

exec "$@"
43 changes: 43 additions & 0 deletions 4/evo-fastcgi/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace docker {
function adminer_object() {
require_once('plugins/plugin.php');

class Adminer extends \AdminerPlugin {
function _callParent($function, $args) {
if ($function === 'loginForm') {
ob_start();
$return = \Adminer::loginForm();
$form = ob_get_clean();

echo str_replace('name="auth[server]" value="" title="hostname[:port]"', 'name="auth[server]" value="'.($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db').'" title="hostname[:port]"', $form);

return $return;
}

return parent::_callParent($function, $args);
}
}

$plugins = [];
foreach (glob('plugins-enabled/*.php') as $plugin) {
$plugins[] = require($plugin);
}

return new Adminer($plugins);
}
}

namespace {
if (basename($_SERVER['DOCUMENT_URI'] ?? $_SERVER['REQUEST_URI']) === 'adminer.css' && is_readable('adminer.css')) {
header('Content-Type: text/css');
readfile('adminer.css');
exit;
}

function adminer_object() {
return \docker\adminer_object();
}

require('adminer.php');
}
73 changes: 73 additions & 0 deletions 4/evo-fastcgi/plugin-loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
if (PHP_SAPI !== 'cli') exit;
if ($_SERVER['argc'] !== 2) exit;

$name = $_SERVER['argv'][1];
// Sanity checks.
if (basename($name) !== $name) {
fwrite(STDERR, 'Refusing to load plugin file "'.$name.'" for security reasons.'."\n");
exit(1);
}
if (!is_readable('plugins/'.$name.'.php')) {
fwrite(STDERR, 'Unable to find plugin file "'.$name.'".'."\n");
exit(1);
}

// Try to find class.
$file = 'plugins/'.$name.'.php';
$code = file_get_contents('plugins/'.$name.'.php');
$tokens = token_get_all($code);

$classFound = false;
$classes = [];
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
if ($tokens[$i][0] === T_CLASS) $classFound = true;
if ($classFound && $tokens[$i][0] === T_STRING) {
$classes[] = $tokens[$i][1];
$classFound = false;
}
}

// Sanity checks.
if (count($classes) == 0) {
fwrite(STDERR, 'Unable to load plugin file "'.$name.'", because it does not define any classes.'."\n");
exit(1);
}

if (count($classes) > 1) {
fwrite(STDERR, 'Unable to load plugin file "'.$name.'", because it defines multiple classes.'."\n");
exit(1);
}

// Check constructor.
$class = $classes[0];
require($file);

$constructor = (new \ReflectionClass($class))->getConstructor();

if ($constructor && $constructor->getNumberOfRequiredParameters() > 0) {
$requiredParameters = array_slice($constructor->getParameters(), 0, $constructor->getNumberOfRequiredParameters());

fwrite(STDERR, 'Unable to load plugin file "'.$name.'", because it has required parameters: '.implode(', ', array_map(function ($item) {
return $item->getName();
}, $requiredParameters))."\n".
'Create a file "'.getcwd().'/plugins-enabled/'.$name.'.php" with the following contents to load the plugin:'."\n\n".
'<?php
require_once('.var_export($file, true).');

'.$constructor->getDocComment().'
return new '.$class.'(
'.implode(",\n\t", array_map(function ($item) {
return '$'.$item->getName()." = ".($item->isOptional() ? var_export($item->getDefaultValue(), true) : '???');
}, $constructor->getParameters())).'
);
');
exit(1);
}

echo '<?php
require_once('.var_export($file, true).');

return new '.$class.'();
';
exit(0);
64 changes: 64 additions & 0 deletions 4/evo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM php:7.4-alpine

RUN echo "upload_max_filesize = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "post_max_size = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "memory_limit = 1G" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "max_execution_time = 600" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
&& echo "max_input_vars = 5000" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini

STOPSIGNAL SIGINT

RUN addgroup -S adminer \
&& adduser -S -G adminer adminer \
&& mkdir -p /var/www/html \
&& mkdir /var/www/html/plugins-enabled \
&& chown -R adminer:adminer /var/www/html

WORKDIR /var/www/html

RUN set -x \
&& apk add --no-cache --virtual .build-deps \
postgresql-dev \
sqlite-dev \
unixodbc-dev \
freetds-dev \
&& docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
&& docker-php-ext-install \
mysqli \
pdo_pgsql \
pdo_sqlite \
pdo_odbc \
pdo_dblib \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --virtual .phpexts-rundeps $runDeps \
&& apk del --no-network .build-deps

COPY *.php /var/www/html/

ENV ADMINER_VERSION 4.8.4
ENV ADMINER_DOWNLOAD_SHA256 e9a9bc2cc2ac46d6d92f008de9379d2b21a3764a5f8956ed68456e190814b149
ENV ADMINER_COMMIT f1e13af9252bfd88d816ef72593513c13adf1dd5

RUN set -x \
&& apk add --no-cache --virtual .build-deps git \
&& curl -fsSL "https://github.com/adminerevo/adminerevo/releases/download/v$ADMINER_VERSION/adminer-$ADMINER_VERSION.php" -o adminer.php \
&& echo "$ADMINER_DOWNLOAD_SHA256 adminer.php" |sha256sum -c - \
&& git clone --recurse-submodules=designs --depth 1 --shallow-submodules --branch "v$ADMINER_VERSION" https://github.com/adminerevo/adminerevo.git /tmp/adminer \
&& commit="$(git -C /tmp/adminer/ rev-parse HEAD)" \
&& [ "$commit" = "$ADMINER_COMMIT" ] \
&& cp -r /tmp/adminer/designs/ /tmp/adminer/plugins/ . \
&& rm -rf /tmp/adminer/ \
&& apk del --no-network .build-deps

COPY entrypoint.sh /usr/local/bin/
ENTRYPOINT [ "entrypoint.sh", "docker-php-entrypoint" ]

USER adminer
CMD [ "php", "-S", "[::]:8080", "-t", "/var/www/html" ]

EXPOSE 8080
20 changes: 20 additions & 0 deletions 4/evo/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
set -e

if [ -n "$ADMINER_DESIGN" ]; then
# Only create link on initial start, to ensure that explicit changes to
# adminer.css after the container was started once are preserved.
if [ ! -e .adminer-init ]; then
ln -sf "designs/$ADMINER_DESIGN/adminer.css" .
fi
fi

number=1
for PLUGIN in $ADMINER_PLUGINS; do
php plugin-loader.php "$PLUGIN" > plugins-enabled/$(printf "%03d" $number)-$PLUGIN.php
number=$(($number+1))
done

touch .adminer-init || true

exec "$@"
43 changes: 43 additions & 0 deletions 4/evo/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace docker {
function adminer_object() {
require_once('plugins/plugin.php');

class Adminer extends \AdminerPlugin {
function _callParent($function, $args) {
if ($function === 'loginForm') {
ob_start();
$return = \Adminer::loginForm();
$form = ob_get_clean();

echo str_replace('name="auth[server]" value="" title="hostname[:port]"', 'name="auth[server]" value="'.($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db').'" title="hostname[:port]"', $form);

return $return;
}

return parent::_callParent($function, $args);
}
}

$plugins = [];
foreach (glob('plugins-enabled/*.php') as $plugin) {
$plugins[] = require($plugin);
}

return new Adminer($plugins);
}
}

namespace {
if (basename($_SERVER['DOCUMENT_URI'] ?? $_SERVER['REQUEST_URI']) === 'adminer.css' && is_readable('adminer.css')) {
header('Content-Type: text/css');
readfile('adminer.css');
exit;
}

function adminer_object() {
return \docker\adminer_object();
}

require('adminer.php');
}
Loading