test: ✅ add some tests in images
This commit is contained in:
parent
3a8d0a1635
commit
44bb0ca1a3
5 changed files with 279 additions and 0 deletions
70
PHP8.5/DEV/tests.sh
Normal file
70
PHP8.5/DEV/tests.sh
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Import shared utilities.
|
||||
source "$(pwd)/PHP8.5/utils.sh"
|
||||
|
||||
startTests
|
||||
|
||||
# Import shared tests.
|
||||
source "$(pwd)/PHP8.5/common.sh"
|
||||
|
||||
section "PHP extensions"
|
||||
run "gd" "php -m | grep -qx 'gd'"
|
||||
run "exif" "php -m | grep -qx 'exif'"
|
||||
run "gettext" "php -m | grep -qx 'gettext'"
|
||||
run "intl" "php -m | grep -qx 'intl'"
|
||||
run "mysqli" "php -m | grep -qx 'mysqli'"
|
||||
run "pdo_mysql" "php -m | grep -qx 'pdo_mysql'"
|
||||
run "xsl" "php -m | grep -qx 'xsl'"
|
||||
run "zip" "php -m | grep -qx 'zip'"
|
||||
run "bcmath" "php -m | grep -qx 'bcmath'"
|
||||
run "ldap" "php -m | grep -qx 'ldap'"
|
||||
run "gmp" "php -m | grep -qx 'gmp'"
|
||||
run "mbstring" "php -m | grep -qx 'mbstring'"
|
||||
run "imagick" "php -m | grep -qx 'imagick'"
|
||||
run "redis" "php -m | grep -qx 'redis'"
|
||||
run "xdebug" "php -m | grep -qx 'xdebug'"
|
||||
run "pcov" "php -m | grep -qx 'pcov'"
|
||||
|
||||
section "Compiled extensions"
|
||||
run "gd: imagecreate" "php -r '\$i = imagecreate(10,10); echo \$i ? \"ok\" : \"fail\";'"
|
||||
run "imagick: instanciation" "php -r 'new Imagick(); echo \"ok\";'"
|
||||
run "xdebug: mode configurable" "php -d xdebug.mode=off -m | grep -q xdebug"
|
||||
run "pcov: driver disponible" "php -m | grep -q pcov"
|
||||
|
||||
section "Apache & PHP-FPM"
|
||||
run "httpd binaire present" "which httpd"
|
||||
run "php-fpm binaire present" "which php-fpm"
|
||||
run "httpd -v" "httpd -v"
|
||||
run "php-fpm -v" "php-fpm -v"
|
||||
run "module proxy_fcgi enabled" "grep -r 'proxy_fcgi' /etc/apache2/"
|
||||
run "module rewrite enabled" "grep -r 'rewrite_module' /etc/apache2/"
|
||||
run "module remoteip enabled" "grep -r 'remoteip_module' /etc/apache2/"
|
||||
run "module headers active" "grep -r 'headers_module' /etc/apache2/"
|
||||
run "vhost.conf present" "test -f /etc/apache2/conf.d/vhost.conf"
|
||||
run "php-fpm.conf present" "test -f /usr/local/etc/php-fpm.d/www.conf"
|
||||
run "xdebug.ini present" "test -f /usr/local/etc/php/conf.d/xdebug.ini"
|
||||
|
||||
section "QA tools"
|
||||
run_output "composer version" "composer --version 2>/dev/null | awk '{print \$1,\$2,\$3}'"
|
||||
run_output "bun version" "bun --version"
|
||||
run_output "node version" "node --version"
|
||||
run_output "npm version" "npm --version"
|
||||
|
||||
section "Utilities"
|
||||
run "git disponible" "git --version"
|
||||
run "curl disponible" "curl --version"
|
||||
run "unzip disponible" "unzip -v"
|
||||
run "mariadb disponible" "mysql --version"
|
||||
|
||||
section "Shell"
|
||||
run "zsh disponible" "which zsh"
|
||||
run "oh-my-zsh installed" "test -d /root/.oh-my-zsh"
|
||||
run "zsh-autosuggestions" "test -d /root/.oh-my-zsh/custom/plugins/zsh-autosuggestions"
|
||||
run "SHELL=zsh" "[ \"\$SHELL\" = '/bin/zsh' ]"
|
||||
|
||||
section "Paths"
|
||||
run "WORKDIR = /app/srcs" "[ \"\$(pwd)\" = '/app/srcs' ]"
|
||||
run "docker-entrypoint present" "test -x /usr/local/bin/docker-entrypoint.sh"
|
||||
|
||||
endTests
|
||||
64
PHP8.5/PROD/tests.sh
Normal file
64
PHP8.5/PROD/tests.sh
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Import shared utilities.
|
||||
source "$(pwd)/PHP8.5/utils.sh"
|
||||
|
||||
startTests
|
||||
|
||||
# Import shared tests.
|
||||
source "$(pwd)/PHP8.5/common.sh"
|
||||
|
||||
section "PHP extensions"
|
||||
run "bcmath" "php -m | grep -qx 'bcmath'"
|
||||
run "exif" "php -m | grep -qx 'exif'"
|
||||
run "gd" "php -m | grep -qx 'gd'"
|
||||
run "gettext" "php -m | grep -qx 'gettext'"
|
||||
run "gmp" "php -m | grep -qx 'gmp'"
|
||||
run "imagick" "php -m | grep -qx 'imagick'"
|
||||
run "ldap" "php -m | grep -qx 'ldap'"
|
||||
run "mbstring" "php -m | grep -qx 'mbstring'"
|
||||
run "memcached" "php -m | grep -qx 'memcached'"
|
||||
run "mysqli" "php -m | grep -qx 'mysqli'"
|
||||
run "pdo_mysql" "php -m | grep -qx 'pdo_mysql'"
|
||||
run "redis" "php -m | grep -qx 'redis'"
|
||||
run "xsl" "php -m | grep -qx 'xsl'"
|
||||
run "zip" "php -m | grep -qx 'zip'"
|
||||
|
||||
section "Compiled extensions"
|
||||
run "gd: imagecreate" "php -r '\$i = imagecreate(10,10); echo \$i ? \"ok\" : \"fail\";'"
|
||||
run "imagick: instanciation" "php -r 'new Imagick(); echo \"ok\";'"
|
||||
|
||||
section "Check: no development tools"
|
||||
run "pcov absent" "php -m | grep -qx 'pcov' && exit 1 || exit 0"
|
||||
run "zsh absent" "which zsh 2>/dev/null && exit 1 || exit 0"
|
||||
run "bun absent" "which bun 2>/dev/null && exit 1 || exit 0"
|
||||
run "xdebug absent" "php -m | grep -qx 'xdebug' && exit 1 || exit 0"
|
||||
run "xdebug.ini absent" "test ! -f /usr/local/etc/php/conf.d/xdebug.ini"
|
||||
|
||||
section "Apache & PHP-FPM"
|
||||
run "httpd binaire present" "which httpd"
|
||||
run "php-fpm binaire present" "which php-fpm"
|
||||
run "httpd -v" "httpd -v"
|
||||
run "php-fpm -v" "php-fpm -v"
|
||||
run "module proxy_fcgi enabled" "grep -r 'proxy_fcgi' /etc/apache2/"
|
||||
run "module rewrite enabled" "grep -r 'rewrite_module' /etc/apache2/"
|
||||
run "module remoteip enabled" "grep -r 'remoteip_module' /etc/apache2/"
|
||||
run "module headers enabled" "grep -r 'headers_module' /etc/apache2/"
|
||||
run "vhost.conf present" "test -f /etc/apache2/conf.d/vhost.conf"
|
||||
run "php-fpm.conf present" "test -f /usr/local/etc/php-fpm.d/www.conf"
|
||||
run "ssl.conf absent" "test ! -f /etc/apache2/conf.d/ssl.conf"
|
||||
|
||||
section "QA tools"
|
||||
run_output "composer version" "composer --version 2>/dev/null | awk '{print \$1,\$2,\$3}'"
|
||||
|
||||
section "Utilities"
|
||||
run "git disponible" "git --version"
|
||||
run "curl disponible" "curl --version"
|
||||
run "unzip disponible" "unzip -v"
|
||||
run "mariadb disponible" "mysql --version"
|
||||
|
||||
section "Paths"
|
||||
run "WORKDIR = /app/srcs" "[ \"\$(pwd)\" = '/app/srcs' ]"
|
||||
run "docker-entrypoint present" "test -x /usr/local/bin/docker-entrypoint.sh"
|
||||
|
||||
endTests
|
||||
52
PHP8.5/QA/tests.sh
Normal file
52
PHP8.5/QA/tests.sh
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Import shared utilities.
|
||||
source "$(pwd)/PHP8.5/utils.sh"
|
||||
|
||||
startTests
|
||||
|
||||
# Import shared tests.
|
||||
source "$(pwd)/PHP8.5/common.sh"
|
||||
|
||||
section "PHP extensions"
|
||||
run "bcmath" "php -m | grep -qx 'bcmath'"
|
||||
run "exif" "php -m | grep -qx 'exif'"
|
||||
run "gd" "php -m | grep -qx 'gd'"
|
||||
run "gettext" "php -m | grep -qx 'gettext'"
|
||||
run "gmp" "php -m | grep -qx 'gmp'"
|
||||
run "imagick" "php -m | grep -qx 'imagick'"
|
||||
run "intl" "php -m | grep -qx 'intl'"
|
||||
run "ldap" "php -m | grep -qx 'ldap'"
|
||||
run "mbstring" "php -m | grep -qx 'mbstring'"
|
||||
run "memcached" "php -m | grep -qx 'memcached'"
|
||||
run "mysqli" "php -m | grep -qx 'mysqli'"
|
||||
run "pcov" "php -m | grep -qx 'pcov'"
|
||||
run "pdo_mysql" "php -m | grep -qx 'pdo_mysql'"
|
||||
run "xsl" "php -m | grep -qx 'xsl'"
|
||||
run "zip" "php -m | grep -qx 'zip'"
|
||||
|
||||
section "Compiled extensions"
|
||||
run "gd: imagecreate" "php -r '\$i = imagecreate(10,10); echo \$i ? \"ok\" : \"fail\";'"
|
||||
run "imagick: instanciation" "php -r 'new Imagick(); echo \"ok\";'"
|
||||
run "pcov: driver" "php -d pcov.enabled=1 -r 'echo pcov\\\\Collector::start() ? \"ok\" : \"ok\";' 2>/dev/null || true; php -m | grep -q pcov"
|
||||
|
||||
section "QA tools"
|
||||
run "local-php-security-checker present" "local-php-security-checker -help 2>&1 | grep -qi 'version'"
|
||||
run_output "composer version" "composer --version 2>/dev/null | awk '{print \$1,\$2,\$3}'"
|
||||
run_output "audit-ci version" "audit-ci --version 2>/dev/null || npx audit-ci --version 2>/dev/null"
|
||||
run_output "node version" "node --version"
|
||||
run_output "npm version" "npm --version"
|
||||
|
||||
section "Utilities"
|
||||
run "git disponible" "git --version"
|
||||
run "curl disponible" "curl --version"
|
||||
run "unzip disponible" "unzip -v"
|
||||
|
||||
section "Paths"
|
||||
run "WORKDIR = /project" "[ \"\$(pwd)\" = '/project' ]"
|
||||
run "/tools dans le PATH" "echo \$PATH | grep -q '/tools'"
|
||||
run "composer dans le PATH" "which composer"
|
||||
run "audit-ci dans le PATH" "which audit-ci"
|
||||
run "security-checker dans PATH" "which local-php-security-checker"
|
||||
|
||||
endTests
|
||||
10
PHP8.5/common.sh
Normal file
10
PHP8.5/common.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
section "PHP version"
|
||||
run_output "php -v" "php -r 'echo PHP_VERSION;'"
|
||||
run "php -l (lint)" "php -r 'echo 42;'"
|
||||
run "php.ini loaded" "php -i | grep -q 'Loaded Configuration'"
|
||||
run "app.ini loaded" "php -i | grep -q 'app.ini\|/usr/local/etc/php/conf.d/app.ini'"
|
||||
|
||||
section "Locales"
|
||||
run "LC_ALL=fr_FR.UTF-8" "[ \"\$LC_ALL\" = 'fr_FR.UTF-8' ]"
|
||||
run "LANG=fr_FR.UTF-8" "[ \"\$LANG\" = 'fr_FR.UTF-8' ]"
|
||||
run "locale fr_FR disponible" "locale -a 2>/dev/null | grep -qi 'fr_FR'"
|
||||
83
PHP8.5/utils.sh
Normal file
83
PHP8.5/utils.sh
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
# Variables
|
||||
IMAGE="${1:-image-name:latest}"
|
||||
PASS=0
|
||||
FAIL=0
|
||||
ERRORS=()
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
# Functions to test element in target image.
|
||||
|
||||
## run <label> <command>
|
||||
run() {
|
||||
local label="$1";
|
||||
local labelColored="${NC} ${label}"
|
||||
|
||||
if docker run --rm --entrypoint /bin/sh "$IMAGE" -c "$2" > /dev/null 2>&1; then
|
||||
echo -e " ${GREEN}✔ ${labelColored}"
|
||||
(( PASS++ )) || true
|
||||
else
|
||||
echo -e " ${RED}✘ ${labelColored}"
|
||||
ERRORS+=("$label")
|
||||
(( FAIL++ )) || true
|
||||
fi
|
||||
}
|
||||
|
||||
## run_output <label> <command>
|
||||
run_output() {
|
||||
local label="$1";
|
||||
local labelColored="${NC} ${label}"
|
||||
local out
|
||||
|
||||
if out=$(docker run --rm --entrypoint /bin/sh "$IMAGE" -c "$2" 2>&1); then
|
||||
echo -e " ${GREEN}✔ ${labelColored}${CYAN} → $(echo "$out" | head -1)${NC}"
|
||||
(( PASS++ )) || true
|
||||
else
|
||||
echo -e " ${RED}✘ ${labelColored}"
|
||||
echo -e " ${YELLOW}↳ $out${NC}"
|
||||
ERRORS+=("$label")
|
||||
(( FAIL++ )) || true
|
||||
fi
|
||||
}
|
||||
|
||||
# Functions to display some content & errors.
|
||||
|
||||
## section <label>
|
||||
section() {
|
||||
echo ""
|
||||
echo -e "${CYAN}▶ $1${NC}"
|
||||
}
|
||||
|
||||
startTests() {
|
||||
# valid image
|
||||
echo ""
|
||||
echo -e " Image: ${YELLOW}${IMAGE}${NC}"
|
||||
if ! docker image inspect "$IMAGE" > /dev/null 2>&1; then
|
||||
echo -e "${RED}✘ Image not found: ${IMAGE}${NC}"
|
||||
echo ""
|
||||
echo " To create a new docker image: docker build -t ${IMAGE} ."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Results passed + failed.
|
||||
endTests() {
|
||||
TOTAL=$(( PASS + FAIL ))
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}▶ ${PASS}/${TOTAL} tests passed${NC} $([ $FAIL -gt 0 ] || echo "")\n"
|
||||
|
||||
if [ ${#ERRORS[@]} -gt 0 ]; then
|
||||
echo -e "${RED}▶ ${FAIL} tests failed:${NC}"
|
||||
for e in "${ERRORS[@]}"; do
|
||||
echo -e " ${RED}✘ ${NC} $e"
|
||||
done
|
||||
echo ""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue