Skip to content

Commit be86fa7

Browse files
committed
Add Adminer 5.0.1
1 parent 33a7e87 commit be86fa7

File tree

10 files changed

+391
-1
lines changed

10 files changed

+391
-1
lines changed

.github/workflows/image.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
variant:
1313
- "4"
1414
- "4/fastcgi"
15+
- "5"
16+
- "5/fastcgi"
1517
steps:
1618
- uses: actions/checkout@v4
1719
- name: Build the image.

5/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM php:8.4-alpine
2+
3+
RUN echo "upload_max_filesize = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
4+
&& echo "post_max_size = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
5+
&& echo "memory_limit = 1G" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
6+
&& echo "max_execution_time = 600" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
7+
&& echo "max_input_vars = 5000" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini
8+
9+
STOPSIGNAL SIGINT
10+
11+
RUN addgroup -S adminer \
12+
&& adduser -S -G adminer adminer \
13+
&& mkdir -p /var/www/html \
14+
&& mkdir /var/www/html/plugins-enabled \
15+
&& chown -R adminer:adminer /var/www/html
16+
17+
WORKDIR /var/www/html
18+
19+
RUN set -x \
20+
&& apk add --no-cache --virtual .build-deps \
21+
postgresql-dev \
22+
sqlite-dev \
23+
unixodbc-dev \
24+
freetds-dev \
25+
&& docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
26+
&& docker-php-ext-install \
27+
mysqli \
28+
pdo_pgsql \
29+
pdo_sqlite \
30+
pdo_odbc \
31+
pdo_dblib \
32+
&& runDeps="$( \
33+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
34+
| tr ',' '\n' \
35+
| sort -u \
36+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
37+
)" \
38+
&& apk add --virtual .phpexts-rundeps $runDeps \
39+
&& apk del --no-network .build-deps
40+
41+
COPY *.php /var/www/html/
42+
43+
ENV ADMINER_VERSION=5.0.1
44+
ENV ADMINER_DOWNLOAD_SHA256=cc6ffbbe75e4a0cdae537b90bbc426515bbc373364c215bac4773ea9e5130686
45+
ENV ADMINER_SRC_DOWNLOAD_SHA256=aae7f30b6ed38e523418bd326e73704d3abeeafb7ba9804a952474774ad708c2
46+
47+
RUN set -x \
48+
&& curl -fsSL https://github.com/vrana/adminer/releases/download/v$ADMINER_VERSION/adminer-$ADMINER_VERSION.php -o adminer.php \
49+
&& echo "$ADMINER_DOWNLOAD_SHA256 adminer.php" |sha256sum -c - \
50+
&& curl -fsSL https://github.com/vrana/adminer/archive/v$ADMINER_VERSION.tar.gz -o source.tar.gz \
51+
&& echo "$ADMINER_SRC_DOWNLOAD_SHA256 source.tar.gz" |sha256sum -c - \
52+
&& tar xzf source.tar.gz --strip-components=1 "adminer-$ADMINER_VERSION/designs/" "adminer-$ADMINER_VERSION/plugins/" \
53+
&& rm source.tar.gz
54+
55+
COPY entrypoint.sh /usr/local/bin/
56+
ENTRYPOINT [ "entrypoint.sh", "docker-php-entrypoint" ]
57+
58+
USER adminer
59+
CMD [ "php", "-S", "[::]:8080", "-t", "/var/www/html" ]
60+
61+
EXPOSE 8080

5/entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ -n "$ADMINER_DESIGN" ]; then
5+
# Only create link on initial start, to ensure that explicit changes to
6+
# adminer.css after the container was started once are preserved.
7+
if [ ! -e .adminer-init ]; then
8+
ln -sf "designs/$ADMINER_DESIGN/adminer.css" .
9+
fi
10+
fi
11+
12+
number=1
13+
for PLUGIN in $ADMINER_PLUGINS; do
14+
php plugin-loader.php "$PLUGIN" > plugins-enabled/$(printf "%03d" $number)-$PLUGIN.php
15+
number=$(($number+1))
16+
done
17+
18+
touch .adminer-init || true
19+
20+
exec "$@"

5/fastcgi/Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM php:8.4-fpm-alpine
2+
3+
RUN echo "upload_max_filesize = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
4+
&& echo "post_max_size = 128M" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
5+
&& echo "memory_limit = 1G" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
6+
&& echo "max_execution_time = 600" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini \
7+
&& echo "max_input_vars = 5000" >> /usr/local/etc/php/conf.d/0-upload_large_dumps.ini
8+
9+
RUN addgroup -S adminer \
10+
&& adduser -S -G adminer adminer \
11+
&& mkdir -p /var/www/html \
12+
&& mkdir /var/www/html/plugins-enabled \
13+
&& chown -R adminer:adminer /var/www/html
14+
15+
RUN set -x \
16+
&& apk add --no-cache --virtual .build-deps \
17+
postgresql-dev \
18+
sqlite-dev \
19+
unixodbc-dev \
20+
freetds-dev \
21+
&& docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr \
22+
&& docker-php-ext-install \
23+
mysqli \
24+
pdo_pgsql \
25+
pdo_sqlite \
26+
pdo_odbc \
27+
pdo_dblib \
28+
&& runDeps="$( \
29+
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
30+
| tr ',' '\n' \
31+
| sort -u \
32+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
33+
)" \
34+
&& apk add --virtual .phpexts-rundeps $runDeps \
35+
&& apk del --no-network .build-deps
36+
37+
COPY *.php /var/www/html/
38+
39+
ENV ADMINER_VERSION=5.0.1
40+
ENV ADMINER_DOWNLOAD_SHA256=cc6ffbbe75e4a0cdae537b90bbc426515bbc373364c215bac4773ea9e5130686
41+
ENV ADMINER_SRC_DOWNLOAD_SHA256=aae7f30b6ed38e523418bd326e73704d3abeeafb7ba9804a952474774ad708c2
42+
43+
RUN set -x \
44+
&& curl -fsSL https://github.com/vrana/adminer/releases/download/v$ADMINER_VERSION/adminer-$ADMINER_VERSION.php -o adminer.php \
45+
&& echo "$ADMINER_DOWNLOAD_SHA256 adminer.php" |sha256sum -c - \
46+
&& curl -fsSL https://github.com/vrana/adminer/archive/v$ADMINER_VERSION.tar.gz -o source.tar.gz \
47+
&& echo "$ADMINER_SRC_DOWNLOAD_SHA256 source.tar.gz" |sha256sum -c - \
48+
&& tar xzf source.tar.gz --strip-components=1 "adminer-$ADMINER_VERSION/designs/" "adminer-$ADMINER_VERSION/plugins/" \
49+
&& rm source.tar.gz
50+
51+
COPY entrypoint.sh /usr/local/bin/
52+
ENTRYPOINT [ "entrypoint.sh", "docker-php-entrypoint" ]
53+
54+
USER adminer
55+
CMD [ "php-fpm" ]

5/fastcgi/entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ -n "$ADMINER_DESIGN" ]; then
5+
# Only create link on initial start, to ensure that explicit changes to
6+
# adminer.css after the container was started once are preserved.
7+
if [ ! -e .adminer-init ]; then
8+
ln -sf "designs/$ADMINER_DESIGN/adminer.css" .
9+
fi
10+
fi
11+
12+
number=1
13+
for PLUGIN in $ADMINER_PLUGINS; do
14+
php plugin-loader.php "$PLUGIN" > plugins-enabled/$(printf "%03d" $number)-$PLUGIN.php
15+
number=$(($number+1))
16+
done
17+
18+
touch .adminer-init || true
19+
20+
exec "$@"

5/fastcgi/index.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace docker {
3+
function adminer_object() {
4+
require_once('plugins/plugin.php');
5+
6+
class Adminer extends \AdminerPlugin {
7+
function _callParent($function, $args) {
8+
if ($function === 'loginForm') {
9+
ob_start();
10+
$return = \Adminer\Adminer::loginForm();
11+
$form = ob_get_clean();
12+
13+
echo str_replace('name="auth[server]" value="" title="hostname[:port]"', 'name="auth[server]" value="'.($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db').'" title="hostname[:port]"', $form);
14+
15+
return $return;
16+
}
17+
18+
return parent::_callParent($function, $args);
19+
}
20+
}
21+
22+
$plugins = [];
23+
foreach (glob('plugins-enabled/*.php') as $plugin) {
24+
$plugins[] = require($plugin);
25+
}
26+
27+
return new Adminer($plugins);
28+
}
29+
}
30+
31+
namespace {
32+
if (basename($_SERVER['DOCUMENT_URI'] ?? $_SERVER['REQUEST_URI']) === 'adminer.css' && is_readable('adminer.css')) {
33+
header('Content-Type: text/css');
34+
readfile('adminer.css');
35+
exit;
36+
}
37+
38+
function adminer_object() {
39+
return \docker\adminer_object();
40+
}
41+
42+
require('adminer.php');
43+
}

5/fastcgi/plugin-loader.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
if (PHP_SAPI !== 'cli') exit;
3+
if ($_SERVER['argc'] !== 2) exit;
4+
5+
$name = $_SERVER['argv'][1];
6+
// Sanity checks.
7+
if (basename($name) !== $name) {
8+
fwrite(STDERR, 'Refusing to load plugin file "'.$name.'" for security reasons.'."\n");
9+
exit(1);
10+
}
11+
if (!is_readable('plugins/'.$name.'.php')) {
12+
fwrite(STDERR, 'Unable to find plugin file "'.$name.'".'."\n");
13+
exit(1);
14+
}
15+
16+
// Try to find class.
17+
$file = 'plugins/'.$name.'.php';
18+
$code = file_get_contents('plugins/'.$name.'.php');
19+
$tokens = token_get_all($code);
20+
21+
$classFound = false;
22+
$classes = [];
23+
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
24+
if ($tokens[$i][0] === T_CLASS) $classFound = true;
25+
if ($classFound && $tokens[$i][0] === T_STRING) {
26+
$classes[] = $tokens[$i][1];
27+
$classFound = false;
28+
}
29+
}
30+
31+
// Sanity checks.
32+
if (count($classes) == 0) {
33+
fwrite(STDERR, 'Unable to load plugin file "'.$name.'", because it does not define any classes.'."\n");
34+
exit(1);
35+
}
36+
37+
if (count($classes) > 1) {
38+
fwrite(STDERR, 'Unable to load plugin file "'.$name.'", because it defines multiple classes.'."\n");
39+
exit(1);
40+
}
41+
42+
// Check constructor.
43+
$class = $classes[0];
44+
require($file);
45+
46+
$constructor = (new \ReflectionClass($class))->getConstructor();
47+
48+
if ($constructor && $constructor->getNumberOfRequiredParameters() > 0) {
49+
$requiredParameters = array_slice($constructor->getParameters(), 0, $constructor->getNumberOfRequiredParameters());
50+
51+
fwrite(STDERR, 'Unable to load plugin file "'.$name.'", because it has required parameters: '.implode(', ', array_map(function ($item) {
52+
return $item->getName();
53+
}, $requiredParameters))."\n".
54+
'Create a file "'.getcwd().'/plugins-enabled/'.$name.'.php" with the following contents to load the plugin:'."\n\n".
55+
'<?php
56+
require_once('.var_export($file, true).');
57+
58+
'.$constructor->getDocComment().'
59+
return new '.$class.'(
60+
'.implode(",\n\t", array_map(function ($item) {
61+
return '$'.$item->getName()." = ".($item->isOptional() ? var_export($item->getDefaultValue(), true) : '???');
62+
}, $constructor->getParameters())).'
63+
);
64+
');
65+
exit(1);
66+
}
67+
68+
echo '<?php
69+
require_once('.var_export($file, true).');
70+
71+
return new '.$class.'();
72+
';
73+
exit(0);

5/index.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace docker {
3+
function adminer_object() {
4+
require_once('plugins/plugin.php');
5+
6+
class Adminer extends \AdminerPlugin {
7+
function _callParent($function, $args) {
8+
if ($function === 'loginForm') {
9+
ob_start();
10+
$return = \Adminer\Adminer::loginForm();
11+
$form = ob_get_clean();
12+
13+
echo str_replace('name="auth[server]" value="" title="hostname[:port]"', 'name="auth[server]" value="'.($_ENV['ADMINER_DEFAULT_SERVER'] ?: 'db').'" title="hostname[:port]"', $form);
14+
15+
return $return;
16+
}
17+
18+
return parent::_callParent($function, $args);
19+
}
20+
}
21+
22+
$plugins = [];
23+
foreach (glob('plugins-enabled/*.php') as $plugin) {
24+
$plugins[] = require($plugin);
25+
}
26+
27+
return new Adminer($plugins);
28+
}
29+
}
30+
31+
namespace {
32+
if (basename($_SERVER['DOCUMENT_URI'] ?? $_SERVER['REQUEST_URI']) === 'adminer.css' && is_readable('adminer.css')) {
33+
header('Content-Type: text/css');
34+
readfile('adminer.css');
35+
exit;
36+
}
37+
38+
function adminer_object() {
39+
return \docker\adminer_object();
40+
}
41+
42+
require('adminer.php');
43+
}

0 commit comments

Comments
 (0)