From 5280e3af2a82a33eddece5aa26094969d921bd62 Mon Sep 17 00:00:00 2001 From: Torben Date: Tue, 3 Dec 2024 17:21:43 +0100 Subject: [PATCH 1/2] Add evo and evo-fastcgi variants --- 4/evo-fastcgi/Dockerfile | 58 ++++++++++++++++++++++++++ 4/evo-fastcgi/entrypoint.sh | 20 +++++++++ 4/evo-fastcgi/index.php | 43 +++++++++++++++++++ 4/evo-fastcgi/plugin-loader.php | 73 +++++++++++++++++++++++++++++++++ 4/evo/Dockerfile | 64 +++++++++++++++++++++++++++++ 4/evo/entrypoint.sh | 20 +++++++++ 4/evo/index.php | 43 +++++++++++++++++++ 4/evo/plugin-loader.php | 73 +++++++++++++++++++++++++++++++++ 8 files changed, 394 insertions(+) create mode 100644 4/evo-fastcgi/Dockerfile create mode 100755 4/evo-fastcgi/entrypoint.sh create mode 100644 4/evo-fastcgi/index.php create mode 100644 4/evo-fastcgi/plugin-loader.php create mode 100644 4/evo/Dockerfile create mode 100755 4/evo/entrypoint.sh create mode 100644 4/evo/index.php create mode 100644 4/evo/plugin-loader.php diff --git a/4/evo-fastcgi/Dockerfile b/4/evo-fastcgi/Dockerfile new file mode 100644 index 0000000..ea79174 --- /dev/null +++ b/4/evo-fastcgi/Dockerfile @@ -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" ] diff --git a/4/evo-fastcgi/entrypoint.sh b/4/evo-fastcgi/entrypoint.sh new file mode 100755 index 0000000..15fa976 --- /dev/null +++ b/4/evo-fastcgi/entrypoint.sh @@ -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 "$@" diff --git a/4/evo-fastcgi/index.php b/4/evo-fastcgi/index.php new file mode 100644 index 0000000..a48629f --- /dev/null +++ b/4/evo-fastcgi/index.php @@ -0,0 +1,43 @@ + 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". +'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 '> /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 diff --git a/4/evo/entrypoint.sh b/4/evo/entrypoint.sh new file mode 100755 index 0000000..15fa976 --- /dev/null +++ b/4/evo/entrypoint.sh @@ -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 "$@" diff --git a/4/evo/index.php b/4/evo/index.php new file mode 100644 index 0000000..a48629f --- /dev/null +++ b/4/evo/index.php @@ -0,0 +1,43 @@ + 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". +'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 ' Date: Tue, 3 Dec 2024 17:22:21 +0100 Subject: [PATCH 2/2] Add evo and evo-fastcgi variants to helper scripts --- generate-stackbrew-library.sh | 4 +++- update.sh | 41 ++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index d0fe6e7..ff79abd 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -79,7 +79,9 @@ for version in "${versions[@]}"; do for variant in \ '' \ - fastcgi \ + 'evo' \ + 'evo-fastcgi' \ + 'fastcgi' \ ; do dir="$version${variant:+/$variant}" [ -f "$dir/Dockerfile" ] || continue diff --git a/update.sh b/update.sh index f2e017c..54babfc 100755 --- a/update.sh +++ b/update.sh @@ -3,6 +3,8 @@ set -Eeuo pipefail cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" +# update Adminer + versions=( "$@" ) if [ ${#versions[@]} -eq 0 ]; then versions=( */ ) @@ -21,7 +23,7 @@ for version in "${versions[@]}"; do echo >&2 "error: cannot determine full version for '$version'" fi - echo "$version: $fullVersion" + echo "Adminer $version: $fullVersion" downloadSha256="$( curl -fsSL "https://github.com/vrana/adminer/releases/download/v${fullVersion}/adminer-${fullVersion}.php" \ @@ -37,3 +39,40 @@ for version in "${versions[@]}"; do "$version/fastcgi/Dockerfile" \ "$version/Dockerfile" done + +# update AdminerEvo + +versions=( "$@" ) +if [ ${#versions[@]} -eq 0 ]; then + versions=( */ ) +fi +versions=( "${versions[@]%/}" ) + +read -r commit_hash fullVersion << EOF +$(git ls-remote --tags https://github.com/adminerevo/adminerevo.git \ + | awk '{gsub(/refs\/tags\/v/, "", $2); print}' \ + | sort -rVk2 \ + | head -1) +EOF + +for version in "${versions[@]}"; do + if [[ "$fullVersion" != $version* ]]; then + echo >&2 "error: cannot determine full version for '$version'" + fi + + echo "AdminerEvo $version: $fullVersion" + + downloadSha256="$( + curl -fsSL "https://github.com/adminerevo/adminerevo/releases/download/v${fullVersion}/adminer-${fullVersion}.php" \ + | sha256sum \ + | cut -d' ' -f1 + )" + echo " - adminer-${fullVersion}.php: $downloadSha256" + + sed -ri \ + -e 's/^(ENV\s+ADMINER_VERSION\s+).*/\1'"$fullVersion"'/' \ + -e 's/^(ENV\s+ADMINER_DOWNLOAD_SHA256\s+).*/\1'"$downloadSha256"'/' \ + -e 's/^(ENV\s+ADMINER_COMMIT\s+).*/\1'"$commit_hash"'/' \ + "$version/evo-fastcgi/Dockerfile" \ + "$version/evo/Dockerfile" +done