From cf4f350773f388ee8ce346061128eeb7e8094b15 Mon Sep 17 00:00:00 2001 From: Tiana Rakoto Arimanana <5566338+b23prodtm@users.noreply.github.com> Date: Fri, 1 May 2020 02:18:36 +0200 Subject: [PATCH 1/5] Fixes: Parsing arguments --- .travis/TravisCI-OSX-PHP | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/TravisCI-OSX-PHP b/.travis/TravisCI-OSX-PHP index 4c07233f0..ed1c8bcf9 160000 --- a/.travis/TravisCI-OSX-PHP +++ b/.travis/TravisCI-OSX-PHP @@ -1 +1 @@ -Subproject commit 4c07233f0f1b31790666c610a64a8248175d2bf3 +Subproject commit ed1c8bcf9de5253e9c6a7a9bcf3eea7314ce3f35 From b4d1b392c01ca9460ed2759ae91d8dc58ca3eec2 Mon Sep 17 00:00:00 2001 From: Tiana Rakoto Arimanana <5566338+b23prodtm@users.noreply.github.com> Date: Sun, 3 May 2020 17:45:00 +0200 Subject: [PATCH 2/5] Fixes: Circle ci Build --- .circleci/config.yml | 6 +- .circleci/x86_64.env | 3 +- .travis.yml | 17 +-- Dockerfile.armhf | 10 +- Dockerfile.template | 6 +- Dockerfile.x86_64 | 6 +- README.md | 2 +- Scripts/fooargs.sh | 116 +++++++++++---------- Scripts/lib/locate.sh | 2 +- Scripts/lib/logging.sh | 10 +- Scripts/lib/parsing.sh | 72 +++++++------ Scripts/lib/shell_prompt.sh | 6 +- Scripts/lib/test/parsing.sh | 59 +++++++---- Scripts/start_daemon.sh | 29 +++--- common.env | 13 +++ composer.lock | 10 ++ configure.sh | 18 ++-- deployment/images/primary/Dockerfile.armhf | 4 +- docker-compose.x86_64 | 14 ++- docker-compose.yml | 10 +- migrate-database.sh | 100 +++++++++--------- mysqldb/Dockerfile.armhf | 16 ++- mysqldb/Dockerfile.template | 16 ++- mysqldb/Dockerfile.x86_64 | 16 ++- mysqldb/README.md | 75 +++++++++++++ mysqldb/mariadb.ans | 23 ++++ mysqldb/mariadb.conf.d/my.cnf | 4 + mysqldb/mysql_secure_shell | 2 +- start-cake.sh | 22 ++-- test-cake.sh | 19 ++-- 30 files changed, 445 insertions(+), 261 deletions(-) create mode 100644 mysqldb/README.md create mode 100644 mysqldb/mariadb.ans create mode 100644 mysqldb/mariadb.conf.d/my.cnf diff --git a/.circleci/config.yml b/.circleci/config.yml index 91fe89f47..7f69880a3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,10 +3,10 @@ jobs: build: docker: - image: betothreeprod/dind-php7 - - image: betothreeprod/mariadb-intel-nuc + - image: betothreeprod/mariadb-intel-nuc:dev environment: - PUID: 1000 - PGID: 1000 + PUID: 0 + PGID: 0 TZ: Europe/Paris MYSQL_DATABASE: foo_db MYSQL_ROOT_PASSWORD: foo_pass diff --git a/.circleci/x86_64.env b/.circleci/x86_64.env index cc7ef04ff..8b127a5b1 100644 --- a/.circleci/x86_64.env +++ b/.circleci/x86_64.env @@ -1,6 +1,6 @@ DATABASE_ENGINE=MysqlCms DATABASE_SERVICE_NAME=MYSQL -MYSQL_ROOT_HOST=% +MYSQL_ROOT_HOST=127.0.0.1 MYSQL_TCP_PORT=3306 MYSQL_HOST=127.0.0.1 PHP_CMS_DIR=app/webroot/php_cms @@ -10,4 +10,3 @@ MYSQL_ROOT_PASSWORD=foo_pass TEST_DATABASE_NAME=test MYSQL_USER=dummy_foo MYSQL_PASSWORD=foo_pass_test -SERVER_NAME=localhost.local diff --git a/.travis.yml b/.travis.yml index dbb49bf8d..042f4b2b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ os: - osx - windows -dist: xenial +dist: trusty env: matrix: @@ -33,9 +33,6 @@ env: matrix: fast_finish: true - exclude: - - os: windows - - os: linux include: - os: linux language: php @@ -52,7 +49,7 @@ matrix: env: _PHP=latest _PKG=hhvm _SSL=openssl.light allow_failures: - php: 'hhvm' - - env: _PHP=latest _PKG=hhvm + - env: _PHP=3.18 _PKG=hhvm - env: _PHP=7.3 _PKG=php - os: windows - os: osx @@ -68,11 +65,6 @@ addons: build_command_prepend: "" build_command: "./test-cake.sh --cov --travis -o .env common.env --docker" branch_pattern: coverity_scan - apt: - packages: - - php7.0 - - php7.0-xml - - hhvm update: true services: @@ -91,8 +83,9 @@ before_install: - source ./deploy.sh "${DKR_ARCH}" --nobuild install: - cd .travis/TravisCI-OSX-PHP - - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_SSL}"; /usr/local/opt/openssl/bin/c_rehash; fi - - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}" "--with-openssl"; fi + - build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_SSL}"; /usr/local/opt/openssl/bin/c_rehash + - build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}" "--with-openssl" + - build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}-xml" - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "composer"; bash -c 'composer install --dev --no-interaction'; fi - cd ../.. - if [[ "${TRAVIS_OS_NAME}" = "linux" ]]; then curl -s http://getcomposer.org/installer | php && php composer.phar install --dev --no-interaction; fi diff --git a/Dockerfile.armhf b/Dockerfile.armhf index 43bf1d6b7..8b72fe35f 100644 --- a/Dockerfile.armhf +++ b/Dockerfile.armhf @@ -50,7 +50,7 @@ ENV SERVER_NAME ${SERVER_NAME:-'localhost.local'} # Use the default production configuration #COPY $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini -# RUN [ "cross-build-start" ] +RUN [ "cross-build-start" ] RUN install_packages \ git \ ssh \ @@ -151,8 +151,8 @@ RUN a2enmod rewrite \ # Install all PHP dependencies WORKDIR /var/www/html/ -RUN git submodule update --init -RUN ./configure.sh --openshift -c -h -p=pass -s=word --development -# RUN [ "cross-build-end" ] -ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD}"] +RUN git submodule sync && git submodule update --init +RUN ./configure.sh --openshift -c -h -p pass -s word --development +RUN [ "cross-build-end" ] +ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD} --enable-authentication-plugin"] CMD [ "apache2 -D FOREGROUND" ] diff --git a/Dockerfile.template b/Dockerfile.template index 219c5b894..50ce85ad2 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -151,8 +151,8 @@ RUN a2enmod rewrite \ # Install all PHP dependencies WORKDIR /var/www/html/ -RUN git submodule update --init -RUN ./configure.sh --openshift -c -h -p=pass -s=word --development +RUN git submodule sync && git submodule update --init +RUN ./configure.sh --openshift -c -h -p pass -s word --development # RUN [ "cross-build-end" ] -ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD}"] +ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD} --enable-authentication-plugin"] CMD [ "apache2 -D FOREGROUND" ] diff --git a/Dockerfile.x86_64 b/Dockerfile.x86_64 index d3c0081ea..d5bfd646b 100644 --- a/Dockerfile.x86_64 +++ b/Dockerfile.x86_64 @@ -151,8 +151,8 @@ RUN a2enmod rewrite \ # Install all PHP dependencies WORKDIR /var/www/html/ -RUN git submodule update --init -RUN ./configure.sh --openshift -c -h -p=pass -s=word --development +RUN git submodule sync && git submodule update --init +RUN ./configure.sh --openshift -c -h -p pass -s word --development # RUN [ "cross-build-end" ] -ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD}"] +ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD} --enable-authentication-plugin"] CMD [ "apache2 -D FOREGROUND" ] diff --git a/README.md b/README.md index 759cbb21e..2df52ed4d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ However, if these files exist they will affect the behavior of the build process  The myphpcms folder includes modules that need to be pulled in order to install locally. After the first checkout browse to myphpcms folder and do - ```git submodule update --init --recursive``` + ```git submodule sync && git submodule update --init --recursive``` You'll see modules populating the subfolder app/webroot/... If something goes wrong, erase the myphpcms folder and start over. > After a sucessful ```git checkout```each time, run once ```git submodule update --init --recursive``` to ensure submodules are downloaded from git. Otherwise your build may fail. diff --git a/Scripts/fooargs.sh b/Scripts/fooargs.sh index b97dff285..a04127c73 100755 --- a/Scripts/fooargs.sh +++ b/Scripts/fooargs.sh @@ -1,58 +1,62 @@ #!/usr/bin/env bash -source ./Scripts/lib/logging.sh -source ./Scripts/lib/parsing.sh -set -eu -docker=$(parse_arg_exists "--docker" "$@") -#; colorize shell script -nc="\033[0m" -red="\033[0;31m" -green="\033[0;32m" -orange="\033[0;33m" -cyan="\033[0;36m" -slogger -st $0 "Loading ${orange}Test environment${nc} : $0..." -#; To change Model/Datasource/Database -export DB=${DB:-Mysql} -[ "${DB}" = "Mysql" ] && export DATABASE_ENGINE=MysqlCms && export DATABASE_SERVICE_NAME=MYSQL -[ "${DB}" = "Pgsql" ] && export DATABASE_ENGINE=PostgresCms && export DATABASE_SERVICE_NAME=PGSQL -[ "${DB}" = "Sqlite" ] && export DATABASE_ENGINE=SqliteCms && export DATABASE_SERVICE_NAME=SQLITE -slogger -st $0 "DB : ${green}${DB}${nc}" -if [ $docker 2> /dev/null ]; then - export MYSQL_ROOT_HOST=% - export PGSQL_SERVICE_HOST=localhost -fi -export MYSQL_ROOT_HOST=${MYSQL_ROOT_HOST:-%} -export PGSQL_SERVICE_HOST=${PGSQL_SERVICE_HOST:-localhost} -export MYSQL_TCP_PORT=3306 -#; To override, use shell parameter -dbase= instead -export MYSQL_DATABASE=${MYSQL_DATABASE:-foo_db} -export DATABASE_USER=${DATABASE_USER:-root} -#; To override, shell parameter -p= instead -export MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-foo_pass} -#. Test configuration ?test=1, ./test_cake.sh -if [ $docker 2> /dev/null ]; then - export MYSQL_HOST=127.0.0.1 - export TEST_PGSQL_SERVICE_HOST=127.0.0.1 -fi -export MYSQL_HOST=${MYSQL_HOST:-localhost} -export TEST_PGSQL_SERVICE_HOST=${TEST_PGSQL_SERVICE_HOST:-localhost} -#; To override, use shell parameter -tbase= instead -export TEST_DATABASE_NAME=${TEST_DATABASE_NAME:-test} -export MYSQL_USER=${MYSQL_USER:-dummy_foo} -#; To override, use shell parameter -t instead -export MYSQL_PASSWORD=${MYSQL_PASSWORD:-foo_pass_test} -export FTP_SERVICE_HOST=localhost -export FTP_SERVICE_USER=test -export FTP_SERVICE_PASSWORD=mypassword -#; More about default environment app/Config/core.php -#; Openshift Online secure keys (default_keys) -export CAKEPHP_SECURITY_SALT=${CAKEPHP_SECURITY_SALT:-Word} -export CAKEPHP_SECURITY_CIPHER_SEED=${CAKEPHP_SECURITY_CIPHER_SEED:-01234} -#; 0, 1, 2 the higher the more debug data -export CAKEPHP_DEBUG_LEVEL=${CAKEPHP_DEBUG_LEVEL:-2} -#; Shell parameters -h -p password -s salt -#; export GET_HASH_PASSWORD=wokUd0mcc -export PHP_CMS_DIR=${PHP_CMS_DIR:-app/webroot/php_cms} -if [[ $(parse_arg_exists "-[vV]+|--verbose" $*) ]]; then - echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" - echo "MYSQL_PASSWORD=${MYSQL_PASSWORD}" +incFOO_ARGS=${incFOO_ARGS:-0}; if [ $incFOO_ARGS -eq 0 ]; then + export incFOO_ARGS=1 + source ./Scripts/lib/logging.sh + source ./Scripts/lib/parsing.sh + set -eu + docker=$(parse_arg_exists "--docker" "$@") + #; colorize shell script + nc="\033[0m" + red="\033[0;31m" + green="\033[0;32m" + orange="\033[0;33m" + cyan="\033[0;36m" + slogger -st $0 "Loading ${orange}Test environment${nc} : $0..." + #; To change Model/Datasource/Database + export DB=${DB:-Mysql} + [ "${DB}" = "Mysql" ] && export DATABASE_ENGINE=MysqlCms && export DATABASE_SERVICE_NAME=MYSQL + [ "${DB}" = "Pgsql" ] && export DATABASE_ENGINE=PostgresCms && export DATABASE_SERVICE_NAME=PGSQL + [ "${DB}" = "Sqlite" ] && export DATABASE_ENGINE=SqliteCms && export DATABASE_SERVICE_NAME=SQLITE + slogger -st $0 "DB : ${green}${DB}${nc}" + if [ $docker 2> /dev/null ]; then + export MYSQL_ROOT_HOST=127.0.0.1 + export PGSQL_SERVICE_HOST=127.0.0.1 + fi + export MYSQL_ROOT_HOST=${MYSQL_ROOT_HOST:-%} + export PGSQL_SERVICE_HOST=${PGSQL_SERVICE_HOST:-%} + export MYSQL_TCP_PORT=3306 + #; To override, use shell parameter -dbase= instead + export MYSQL_DATABASE=${MYSQL_DATABASE:-foo_db} + export DATABASE_USER=${DATABASE_USER:-root} + #; To override, shell parameter -p= instead + export MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-foo_pass} + #. Test configuration ?test=1, ./test_cake.sh + if [ $docker 2> /dev/null ]; then + export MYSQL_HOST=127.0.0.1 + export TEST_PGSQL_SERVICE_HOST=127.0.0.1 + fi + export MYSQL_HOST=${MYSQL_HOST:-localhost} + export TEST_PGSQL_SERVICE_HOST=${TEST_PGSQL_SERVICE_HOST:-localhost} + #; To override, use shell parameter -tbase= instead + export TEST_DATABASE_NAME=${TEST_DATABASE_NAME:-test} + export MYSQL_USER=${MYSQL_USER:-dummy_foo} + #; To override, use shell parameter -t instead + export MYSQL_PASSWORD=${MYSQL_PASSWORD:-foo_pass_test} + export FTP_SERVICE_HOST=localhost + export FTP_SERVICE_USER=test + export FTP_SERVICE_PASSWORD=mypassword + #; More about default environment app/Config/core.php + #; Openshift Online secure keys (default_keys) + export CAKEPHP_SECURITY_SALT=${CAKEPHP_SECURITY_SALT:-Word} + export CAKEPHP_SECURITY_CIPHER_SEED=${CAKEPHP_SECURITY_CIPHER_SEED:-01234} + #; 0, 1, 2 the higher the more debug data + export CAKEPHP_DEBUG_LEVEL=${CAKEPHP_DEBUG_LEVEL:-2} + #; Shell parameters -h -p password -s salt + #; export GET_HASH_PASSWORD=wokUd0mcc + export PHP_CMS_DIR=${PHP_CMS_DIR:-app/webroot/php_cms} + if [[ $(parse_arg_exists "-[vV]+|--verbose" $*) ]]; then + echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" + echo "MYSQL_PASSWORD=${MYSQL_PASSWORD}" + fi + export SERVER_NAME=${SERVER_NAME:-$(hostname)} fi diff --git a/Scripts/lib/locate.sh b/Scripts/lib/locate.sh index e996440dd..05de7517d 100644 --- a/Scripts/lib/locate.sh +++ b/Scripts/lib/locate.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash _locate() { - [ $# -lt 1 ] && echo "Usage: $0 " && return $FALSE + [ $# -lt 1 ] && echo "Usage: $FUNCNAME " && return $FALSE find /usr -name $1 | grep -m 1 $1 } # export -f _locate diff --git a/Scripts/lib/logging.sh b/Scripts/lib/logging.sh index 37243d39d..e9f1567e9 100644 --- a/Scripts/lib/logging.sh +++ b/Scripts/lib/logging.sh @@ -1,22 +1,22 @@ #!/usr/bin/env bash _locate() { - [ $# -lt 1 ] && echo "Usage: $0 " && exit 1 + [ $# -lt 1 ] && echo "Usage: $FUNCNAME " && exit 1 find /usr -name $1 | grep -m 1 $1 } # export -f _locate function slogger() { - [ -f /dev/log ] && logger $@ && return + [ -f /dev/log ] && logger "$@" && return [ "$#" -gt 1 ] && shift - echo -e "$@" + echo -e "$*" } #; export -f slogger function new_log() { - LOG="/usr/local/var/log/$(basename $0 .sh).$(date +%Y-%m-%d_%H:%M).log" && mkdir -p $(dirname $LOG) + LOG="/usr/local/var/log/$(basename $FUNCNAME .sh).$(date +%Y-%m-%d_%H:%M).log" && mkdir -p $(dirname $LOG) touch $LOG && echo $LOG } #; export -f new_log function check_log() { if [ "$#" -gt 0 ] && [[ $(wc -l $1 | awk '{ print $1 }') -gt 0 ]]; then - slogger -st $0 "Find the log file at %s and read more detailed information.\n" $1 + slogger -st $FUNCNAME "Find the log file at %s and read more detailed information.\n" $1 fi } diff --git a/Scripts/lib/parsing.sh b/Scripts/lib/parsing.sh index d073141ef..172f176fb 100755 --- a/Scripts/lib/parsing.sh +++ b/Scripts/lib/parsing.sh @@ -7,36 +7,39 @@ green="\033[0;32m" orange="\033[0;33m" cyan="\033[0;36m" parse_sql_password() { - [ $# -lt 3 ] && echo "Usage: $0 -|--" && exit 1 + [ $# -lt 3 ] && echo "Usage: $FUNCNAME -|--" && exit 1 evar=$1 desc=$2 - shift; - shift; + shift 2 # Transform long options to short ones - for arg in "$@"; do - shift - case "${arg}" in - -[pP]*|--sql-password*) set -- $(echo "${arg}" \ - | awk 'BEGIN{ FS="[ =]+" }{ print "-p " $2 }') "$@" - OPTIND=1 - parse_and_export "p" $evar "$desc" "$@" - shift $((OPTIND -1));; - -[tT]*|--test-sql-password*) set -- $(echo "${arg}" \ - | awk 'BEGIN{ FS="[ =]+" }{ print "-t " $2 }') "$@" - OPTIND=1 - parse_and_export "t" $evar "$desc" "$@" - shift $((OPTIND -1));; - *) - set -- "$@" "${arg}";; + OPTIND_2=1 + while [ "$#" -gt 0 ]; do + case "$1" in + -[pP]*|--sql-password*) set -- $(echo "$1" \ + | awk 'BEGIN{ FS="[ =]+" }{ print "-p " $2 }') "${@:2}" + parse_and_export "p" $evar "$desc" "${@}" + OPTIND_2=$((OPTIND_2 + $((OPTIND -1)))) + break + ;; + -[tT]*|--test-sql-password*) set -- $(echo "$1" \ + | awk 'BEGIN{ FS="[ =]+" }{ print "-t " $2 }') "${@:2}" + parse_and_export "t" $evar "$desc" "${@}" + OPTIND_2=$((OPTIND_2 + $((OPTIND -1)))) + break + ;; + *) OPTIND_2=$((OPTIND_2 + 1)) + printf "%s arg #%s is %s\n" $FUNCNAME $((OPTIND_2 -1)) $1;; esac + shift; done + export OPTIND=$((OPTIND_2)) } #; export -f parse_sql_password parse_arg_export() { - [ $# -lt 3 ] && echo "Usage: $0 - " && exit 1 + [ $# -lt 3 ] && echo "Usage: $FUNCNAME - " && exit 1 evar=$1 desc=$2 - shift; shift + shift 2 zval=$(echo "$@" | awk 'BEGIN{ FS="[ =]+" }{ print $2 }') while true; do case "$zval" in "") @@ -52,7 +55,7 @@ Please, enter the $desc value now: #; export -f parse_arg_export parse_arg_exists() { [ $# -eq 1 ] && return - [ $# -lt 2 ] && echo "Usage: $0 list-or-\$* + [ $# -lt 2 ] && echo "Usage: $FUNCNAME list-or-\$* Prints the index of the item that's matched in the list (regexpression pattern)" && exit 1 arg_case=$1 shift @@ -72,22 +75,26 @@ END { #; export -f parse_arg_exists() parse_arg_trim() { [ $# -eq 1 ] && return - [ $# -lt 2 ] && echo "Usage: $0 list-or-\$* + [ $# -lt 2 ] && echo "Usage: $FUNCNAME list-or-\$* Prints the list without the items that's matched (regexpression pattern)" && exit 1 match_case_regexp=$1 shift export ARGS="$@" echo $match_case_regexp | awk 'BEGIN{FS="|"; ORS=" "; split(ENVIRON["ARGS"], a, " ")} { - n=-1 + n[0]=-1 for(i=0; ++i in a;) { for(c=1;c<=NF;c++) { - if(a[i] ~ $c) n=i + if(a[i] ~ $c) n[i]=a[i] } } } END { + p=-1 for(i=0; ++i in a;) { - if(i != n) print a[i] + for(q in n) { + if(i == q) p=n[q] + } + if(a[i] != p) print a[i] } }' } @@ -97,27 +104,28 @@ END { # Long options must be transformed into short ones before. # When an argument --name=Bob passes, transform into -n Bob: # -# arg=$1; shift; set -- $(echo "${arg}" \ -# | awk 'BEGIN{ FS="[ =]+" }{ print "-n " $2 }') "$@" -# parse_and_export -n NAME "Set user name" "$@" +# set -- $(echo "$1" \ +# | awk 'BEGIN{ FS="[ =]+" }{ print "-n " $2 }') "${@:2}" +# parse_and_export -n NAME "Set user name" "${@:2}" # # To continue arguments processing after a call to this function : # # shift # parse_and_export() { - [ $# -lt 4 ] && echo "Usage: $0 " && exit 1 + [ $# -lt 4 ] && echo "Usage: $FUNCNAME " && exit 1 optstr=$1 evar=$2 desc=$3 shift 3 OPTIND=1 - while getopts ":${optstr}:" optchar "$@"; do + while getopts "${optstr}:" optchar "$@"; do case "${optchar}" in - "${optstr}") parse_arg_export $evar "${desc}" "-${optchar}" ${OPTARG};; + "${optstr}") parse_arg_export $evar "${desc}" "-${optchar}" ${OPTARG} + break;; *) if [ "$OPTERR" != 1 ]; then echo "Non-option argument: '-${OPTARG}'" >&2; fi;; esac done; shift $((OPTIND -1)); - eval "export OPTIND=${OPTIND}" + export OPTIND=$((OPTIND -1)) } #; export -f parse_and_export() diff --git a/Scripts/lib/shell_prompt.sh b/Scripts/lib/shell_prompt.sh index 8f7f5978d..56e9ca059 100755 --- a/Scripts/lib/shell_prompt.sh +++ b/Scripts/lib/shell_prompt.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e shell_prompt() { - [ $# -lt 2 ] && echo "Usage: $0 [-y|n]" && exit 1 + [ $# -lt 2 ] && echo "Usage: $FUNCNAME [-y|n]" && exit 1 script=$1 title=$2 while true; do @@ -31,7 +31,7 @@ shell_prompt() { } #; export -f shell_prompt show_password_status() { - [ "$#" -lt 3 ] && echo "Usage: $0 '' '' " && exit 1 - slogger -st $0 "User ${green}${1}${nc} (using password:${orange} $([ -z $2 ] && echo "NO" || echo "YES")${nc}) $3...\n" + [ "$#" -lt 3 ] && echo "Usage: $FUNCNAME '' '' " && exit 1 + slogger -st $FUNCNAME "User ${green}${1}${nc} (using password:${orange} $([ -z $2 ] && echo "NO" || echo "YES")${nc}) $3...\n" } #; export -f show_password_status diff --git a/Scripts/lib/test/parsing.sh b/Scripts/lib/test/parsing.sh index 2e2e7f3d7..e7ff5a508 100644 --- a/Scripts/lib/test/parsing.sh +++ b/Scripts/lib/test/parsing.sh @@ -1,31 +1,52 @@ #!/usr/bin/env bash set -e source ./Scripts/lib/parsing.sh - +Z=("[%s] %s %s(OPTIND=%s)\n") +# During the test build, arguments were passed "inline" or "dollar-star" $* +# It turns out that bash shells passes arguments array or "dollar-array" $@. +# The difference's in layouts by printing list inline "$*" or column style "$@". function test_parse_and_export() { - args=("t" "T" "1st password" "-t pass_one") - printf "${args[*]} " + args=("t" "T" "1st password" "-t" "pass_one") parse_and_export "${args[@]}" - [ ! -z $T ] && [ "$T" = "pass_one" ] \ - && printf "[${FUNCNAME[0]}] 1° password OK\n" || printf "[${FUNCNAME[0]}] 1° password FAILED\n" + [ "$T" = "pass_one" ] \ + && printf "$Z" "OK" "1° export" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "1° export" $FUNCNAME $OPTIND - args=("p" "P" "2nd password" "-t -p pass_two") - printf "${args[*]} " + args=("p" "P" "2nd password" "-t" "-p" "pass_two") parse_and_export "${args[@]}" - [ ! -z $P ] && [ "$P" = "pass_two" ] \ - && printf "[${FUNCNAME[0]}] 2° password OK\n" || printf "[${FUNCNAME[0]}] 2° password FAILED\n" + [ "$P" = "pass_two" ] \ + && printf "$Z" "OK" "2° export" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "2° export" $FUNCNAME $OPTIND } function test_parse_sql_password() { - args=("P" "password one" "-p pass_one") - printf "${args[*]} " - parse_sql_password "${args[@]}" - [ ! -z $P ] && [ "$P" = "pass_one" ] \ - && printf "[${FUNCNAME[0]}] 1° password OK\n" || printf "[${FUNCNAME[0]}] 1° password FAILED\n" + args=("P" "password one" "-p" "pass_one" "-foo" "arg") + parse_sql_password "${args[@]}" + [ "$P" = "pass_one" ] \ + && printf "$Z" "OK" "1° password" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "1° password" $FUNCNAME $OPTIND + + args=("S" "password two" "--sql-password=pass_two" "-foo" "arg") + parse_sql_password "${args[@]}" + [ "$S" = "pass_two" ] \ + && printf "$Z" "OK" "2° password" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "2° password" $FUNCNAME $OPTIND +} + +function test_arg_exists() { + args=("-d" "me" "--open=9" "--data") + T=$(parse_arg_exists "-d" $args) + [ $T ] \ + && printf "$Z" "OK" "1° match" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "1° match" $FUNCNAME $OPTIND + + P=$(parse_arg_exists "-d|--data" $args) + [ $P ] \ + && printf "$Z" "OK" "2° match" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "2° match" $FUNCNAME $OPTIND +} + +function test_arg_trim() { + args="-d me --open --data" + T=$(parse_arg_trim "-d|--data" $args) + [[ "${#T}" -eq $(echo "me --open" | wc -m) ]] \ + && printf "$Z" "OK" "1° trim" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "1° trim" $FUNCNAME $OPTIND - args=("S" "password two" "--sql-password=pass_two") - printf "${args[*]} " - parse_sql_password "${args[@]}" - [ ! -z $S ] && [ "$S" = "pass_two" ] \ - && printf "[${FUNCNAME[0]}] 2° password OK\n" || printf "[${FUNCNAME[0]}] 2° password FAILED\n" + P=$(parse_arg_trim "--open" $args) + [[ "${#P}" -eq $(echo "-d me --data" | wc -m) ]] \ + && printf "$Z" "OK" "2° trim" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "2° trim" $FUNCNAME $OPTIND } diff --git a/Scripts/start_daemon.sh b/Scripts/start_daemon.sh index 561d63de5..dc7da9013 100755 --- a/Scripts/start_daemon.sh +++ b/Scripts/start_daemon.sh @@ -6,9 +6,9 @@ docker=$(parse_arg_exists "--docker" $*) ck_args=$(parse_arg_trim "-[oO]+|--openshift|--docker" $*) LOG=$(new_log) && slogger -st $0 $LOG wait_for_host() { - [ "$#" -lt 2 ] && printf "Usage: $0 " && exit 1 + [ "$#" -lt 2 ] && printf "Usage: $FUNCNAME " && exit 1 for i in `seq 1 10`; do - nc -z $1 $2 && slogger -st $0 "${green}Success${nc}" && sleep 2 && return 0 + nc -z $1 $2 && slogger -st $FUNCNAME "${green}Success${nc}" && sleep 2 && return 0 echo -n . sleep 1 done @@ -18,15 +18,15 @@ if [ $docker 2> /dev/null ]; then container="betothreeprod/mariadb-${BALENA_MACHINE_NAME:-intel-nuc}" slogger -st $0 "Docker list maria containers ($container)" #docker quits shell ?? - maria=$(docker ps -q -a -f "name=maria" 2>> $LOG) - if [ $maria ]; then - slogger -st $0 "Container $container can be restarted..." - maria=$(docker container restart $maria >> $LOG 2>&1) - else - slogger -st $0 "Container $container 's started up..." - maria=$(docker rm -f $maria >> $LOG 2>&1) - maria=$(docker run --name maria -d --publish $MYSQL_TCP_PORT:$MYSQL_TCP_PORT --env-file common.env ${container} 2>> $LOG) + maria=$(docker ps -q -a -f "name=maria") + if [ ! -z $maria ]; then + slogger -st $0 "Container $container already running, was stopped." + docker kill $maria >> $LOG 2>&1 || true fi + docker rm -f $maria >> $LOG 2>&1 || true + slogger -st $0 "Container $container 's started up..." + docker run --name maria -id -h $MYSQL_HOST --publish $MYSQL_TCP_PORT:$MYSQL_TCP_PORT \ + --env-file common.env --env-file .env ${container} >> $LOG 2>&1 if [ $? = 0 ]; then slogger -st $0 "Started docker container --name maria ref: $(docker ps -q -a -f "name=maria") host: $MYSQL_HOST}" wait_for_host $MYSQL_HOST ${MYSQL_TCP_PORT:-3306} @@ -36,8 +36,9 @@ if [ $docker 2> /dev/null ]; then check_log $LOG fi if [ $(parse_arg_exists "server" $ck_args) >> $LOG 2>&1 ]; then - show_password_status "${DATABASE_USER}" "${MYSQL_ROOT_PASSWORD}" "is running development server" - url="http://localhost:${CAKE_TCP_PORT:-8000}" + show_password_status "${DATABASE_USER}" "${MYSQL_ROOT_PASSWORD}" "is running development server" + : ${SERVER_NAME?} + url="http://${SERVER_NAME}:${CAKE_TCP_PORT:-8000}" slogger -st $0 "Welcome homepage ${cyan}${url}${nc}" slogger -st $0 "Administrator login ${cyan}${url}/admin/index${nc}" slogger -st $0 "Debugging echoes ${cyan}${url}${orange}?debug=1&verbose=1${nc}" @@ -57,8 +58,8 @@ elif [ $(parse_arg_exists "test" $(parse_arg_trim "--connection*" $ck_args)) >> fi elif [ $(parse_arg_exists "docker-compose" $ck_args) >> $LOG 2>&1 ]; then if [ ! $(which docker-compose) 2> /dev/null ]; then ./Scripts/install-docker-compose.sh; fi - [ -z $SERVER_NAME ] && SERVER_NAME=local - ./Scripts/configure-available-site.sh $SERVER_NAME + : ${SERVER_NAME?} + ./Scripts/configure-available-site.sh $SERVER_NAME slogger -st $0 "${ck_args}" bash -c "${ck_args}" elif [ $(parse_arg_exists "update" $ck_args) >> $LOG 2>&1 ]; then diff --git a/common.env b/common.env index 36c29fd55..5b9838e17 100644 --- a/common.env +++ b/common.env @@ -4,3 +4,16 @@ PUID=1000 PGID=1000 TZ=Europe/Paris COLLECT_COVERAGE=false + +DATABASE_ENGINE=MysqlCms +DATABASE_SERVICE_NAME=MYSQL +MYSQL_ROOT_HOST=127.0.0.1 +MYSQL_TCP_PORT=3306 +MYSQL_HOST=127.0.0.1 +PHP_CMS_DIR=app/webroot/php_cms +DATABASE_USER=root +MYSQL_DATABASE=foo_db +MYSQL_ROOT_PASSWORD=foo_pass +TEST_DATABASE_NAME=test +MYSQL_USER=dummy_foo +MYSQL_PASSWORD=foo_pass_test diff --git a/composer.lock b/composer.lock index ae9d186d5..45e473dd0 100644 --- a/composer.lock +++ b/composer.lock @@ -260,6 +260,16 @@ "zend", "zikula" ], + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], "time": "2020-04-07T06:57:05+00:00" }, { diff --git a/configure.sh b/configure.sh index 304391a27..da16ca7a1 100755 --- a/configure.sh +++ b/configure.sh @@ -35,21 +35,23 @@ while [[ "$#" > 0 ]]; do case $1 in shell_prompt "./Scripts/config_etc_const.sh" "${cyan}Step 1. Overwrite constantes.properties\n${nc}" "-Y" ;; -[hH]*|--hash) - #; get hash password - shift - shell_prompt "./Scripts/config_etc_pass.sh $*" "${cyan}Step 2. Get a hashed password with encryption, PHP encrypts.\n${nc}" "-Y" + #; get hash password + shell_prompt "./Scripts/config_etc_pass.sh ${*:2}" "${cyan}Step 2. Get a hashed password with encryption, PHP encrypts.\n${nc}" "-Y" ;; -[dD]*|--mig-database) #; Know-How : In Openshift 3, configure a CakePhp-Mysql-persistent docker image. Set automatic deployment with _100%_ unavailability #; If it starts a build, it automatically scales deployments down to zero, and deploys and scales up when it's finished to build. #; Be sure that lib/Cake/Console/cake test app and Health checks should return gracefullly, or the pods get terminated after a short time. #; [[-d|--mig-database] [-u]] argument fixes up : Error: Database connection "Mysql" is missing, or could not be created. - shift - shell_prompt "./migrate-database.sh ${docker}${openshift}$@" "${cyan}Step 3. Migrate database\n${nc}" "-Y" + shell_prompt "./migrate-database.sh ${docker} ${openshift} ${*:2}" "${cyan}Step 3. Migrate database\n${nc}" "-Y" break;; -[sS]*|-[pP]*|-[fF]*|-[tT]*|--connection* ) #; void --hash password known args - [[ "$#" > 1 ]] && arg=$2 && [[ ${arg:0:1} != '-' ]] && shift + OPTIND=1 + if [[ "$#" > 1 ]]; then + arg=$2; [[ ${arg:0:1} != '-' ]] && OPTIND=2 + fi + shift $((OPTIND -1)) ;; -[mM]*|--submodule) git submodule update --init --recursive --force;; @@ -67,8 +69,8 @@ while [[ "$#" > 0 ]]; do case $1 in ;; -[vV]*|--verbose ) set -x - echo "Passed params : $0 ${saved}";; - *) echo "Unknown parameter passed: $0 $1"; exit 1;; + echo "Passed params : ${BASH_SOURCE[@]} ${saved[*]}";; + *) echo "Unknown parameter passed: ${BASH_SOURCE[0]} $1"; exit 1;; esac; shift; done show_password_status "${DATABASE_USER}" "${MYSQL_ROOT_PASSWORD}" "is configuring ${openshift} ${docker}..." echo -e "${green}Fixing some file permissions...${nc}" diff --git a/deployment/images/primary/Dockerfile.armhf b/deployment/images/primary/Dockerfile.armhf index e32c39f93..be843db1e 100644 --- a/deployment/images/primary/Dockerfile.armhf +++ b/deployment/images/primary/Dockerfile.armhf @@ -2,7 +2,7 @@ # Source DockerFile: https://github.com/ulsmith/rpi-raspbian-apache-php/blob/master/Dockerfile # FROM balenalib/raspberrypi3-debian:build -# RUN [ "cross-build-start" ] +RUN [ "cross-build-start" ] ARG PHP_LIB ENV PHP_LIB ${PHP_LIB:-7.2} @@ -48,7 +48,7 @@ RUN a2enmod php${PHP_LIB} && a2enmod rewrite COPY conf/000-default.conf /etc/apache2/conf-available/000-default.conf RUN chown -R www-data:www-data /var/www/html -# RUN [ "cross-build-end" ] +RUN [ "cross-build-end" ] EXPOSE 80 CMD [ "apache2 -D FOREGROUND" ] diff --git a/docker-compose.x86_64 b/docker-compose.x86_64 index cca94b4a6..f8d61079c 100644 --- a/docker-compose.x86_64 +++ b/docker-compose.x86_64 @@ -5,24 +5,24 @@ services: context: mysqldb dockerfile: Dockerfile.x86_64 args: - MYSQL_ROOT_HOST: "%" - # bind-address = "127.0.0.1" + # bind-address = "127.0.0.1" > conf.d/my.cnf MYSQL_HOST: "127.0.0.1" MYSQL_DATABASE: "foo_db" MYSQL_ROOT_PASSWORD: "foo_pass" MYSQL_USER: "dummy_foo" MYSQL_PASSWORD: "foo_pass_test" - image: betothreeprod/mariadb-raspberrypi3 + image: betothreeprod/mariadb-intel-nuc volumes: - db-data:/config - db-socket:/var/run/mysqld + ports: + - "3306:3306" restart: unless-stopped networks: - cake env_file: common.env labels: io.balena.features.dbus: "1" - privileged: true myphpcms: env_file: common.env build: @@ -30,15 +30,13 @@ services: dockerfile: Dockerfile.x86_64 args: DEBUG: "1" - MYSQL_ROOT_HOST: "%" # mysql -h "localhost" uses db-socket - MYSQL_HOST: "localhost" + MYSQL_HOST: "127.0.0.1" MYSQL_DATABASE: "foo_db" MYSQL_ROOT_PASSWORD: "foo_pass" MYSQL_USER: "dummy_foo" MYSQL_PASSWORD: "foo_pass_test" - image: betothreeprod/myphpcms-raspberrypi3 - privileged: true + image: betothreeprod/myphpcms-intel-nuc labels: io.balena.features.dbus: "1" volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 747313a8c..ce420d66b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,7 @@ services: context: mysqldb dockerfile: Dockerfile.template args: - MYSQL_ROOT_HOST: "%" - # bind-address = "127.0.0.1" + # bind-address = "127.0.0.1" > conf.d/my.cnf MYSQL_HOST: "127.0.0.1" MYSQL_DATABASE: "foo_db" MYSQL_ROOT_PASSWORD: "foo_pass" @@ -16,13 +15,14 @@ services: volumes: - db-data:/config - db-socket:/var/run/mysqld + ports: + - "3306:3306" restart: unless-stopped networks: - cake env_file: common.env labels: io.balena.features.dbus: "1" - privileged: true myphpcms: env_file: common.env build: @@ -30,15 +30,13 @@ services: dockerfile: Dockerfile.template args: DEBUG: "1" - MYSQL_ROOT_HOST: "%" # mysql -h "localhost" uses db-socket - MYSQL_HOST: "localhost" + MYSQL_HOST: "127.0.0.1" MYSQL_DATABASE: "foo_db" MYSQL_ROOT_PASSWORD: "foo_pass" MYSQL_USER: "dummy_foo" MYSQL_PASSWORD: "foo_pass_test" image: betothreeprod/myphpcms-%%BALENA_MACHINE_NAME%% - privileged: true labels: io.balena.features.dbus: "1" volumes: diff --git a/migrate-database.sh b/migrate-database.sh index 01cab765c..537c48cfa 100755 --- a/migrate-database.sh +++ b/migrate-database.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -eu source ./Scripts/lib/logging.sh source ./Scripts/lib/shell_prompt.sh source ./Scripts/lib/parsing.sh @@ -26,10 +26,12 @@ usage=("" \ " Exports MYSQL_ROOT_PASSWORD" \ " -t=" \ " Exports MYSQL_PASSWORD" \ -" -d,--database=" \ +" --database=" \ " Exports MYSQL_DATABASE" \ " --testunitbase=" \ " Exports TEST_DATABASE_NAME" \ +" --enable-authentication-plugin" \ +" Enables https://mariadb.com/kb/en/authentication-plugin-ed25519/" \ " -v, --verbose" \ " Outputs more debug information" \ " -h, --help Displays this help" \ @@ -47,23 +49,19 @@ identities=app/Config/database.sql new_pass="" new_test_pass="" saved=("$@") -mysql_connect_args=("-v") -test_mysql_connect_args=("-v") +authentication_plugin=0 mysql_host=${MYSQL_ROOT_HOST} test_mysql_host="%" ck_args="--connection=default" -echo "$@" while [[ "$#" > 0 ]]; do case "$1" in - --connect-expired-password ) - mysql_connect_args=("${mysql_connect_args[@]}" --connect-expired-password) - test_mysql_connect_args=("${test_mysql_connect_args[@]}" --connect-expired-password) - ;; + --enable-authentication-plugin*) + authentication_plugin=1;; --docker ) bash -c "./Scripts/start_daemon.sh ${docker}" - sql_connect="docker exec -i maria mysql" + sql_connect="docker exec maria mysql" sql_connect_host="" sql_connect_test_host="" - slogger -st $0 "${sql_connect} ... ";; + ;; -[uU]* ) update_checked=1 ;; @@ -92,7 +90,7 @@ while [[ "$#" > 0 ]]; do case "$1" in [ -f $identities ] && cat $identities # Reset passed args (shift reset) text=("" \ -"Passed params : $0 ${saved}" \ +"Passed params : $0 ${saved[*]}" \ "and environment VARIABLES:" \ $(export -p | grep "DATABASE\|MYSQL") \ "") @@ -103,25 +101,20 @@ $(export -p | grep "DATABASE\|MYSQL") \ exit 0;; -[oO]*|--openshift );; -[pP]* ) - OPTIND=1 parse_sql_password "MYSQL_ROOT_PASSWORD" "current ${DATABASE_USER} password" "$@" shift $((OPTIND -1)) - export set_DATABASE_PASSWORD=$MYSQL_ROOT_PASSWORD ;; -[tT]* ) test_checked=1 printf "Testing %s Unit..." $test_checked - OPTIND=1 parse_sql_password "MYSQL_PASSWORD" "current ${MYSQL_USER} password" "$@" shift $((OPTIND -1)) - export set_MYSQL_PASSWORD=$MYSQL_PASSWORD ck_args="--connection=test" ;; - -[dD]*|--database*) + --database*) # Transform long options to short ones arg=$1; shift; set -- $(echo "${arg}" \ | awk 'BEGIN{ FS="[ =]+" }{ print "-d " $2 }') "$@" - OPTIND=1 parse_and_export "d" "MYSQL_DATABASE" "${DATABASE_USER} database name" "$@" shift $((OPTIND -1)) ;; @@ -130,33 +123,38 @@ $(export -p | grep "DATABASE\|MYSQL") \ arg=$1; shift; set -- $(echo "${arg}" \ | awk 'BEGIN{ FS="[ =]+" }{ print "-u " $2 }') "$@" test_checked=1 - OPTIND=1 parse_and_export "u" "TEST_DATABASE_NAME" "${MYSQL_USER} database name" "$@" shift $((OPTIND -1)) ;; - *) echo "Invalid parameter: $0 $1" && exit 1;; + *) echo "Invalid parameter: ${BASH_SOURCE[0]} $1" && exit 1;; esac -shift; done +shift; #echo "$@"; +done #; check unbound variables, exits scripts and inform user on the standard output. : ${MYSQL_DATABASE?} ${DATABASE_USER?} ${MYSQL_ROOT_PASSWORD?} ${MYSQL_ROOT_HOST?} ${MYSQL_TCP_PORT?} : $TEST_DATABASE_NAME?} ${MYSQL_USER?} ${MYSQL_PASSWORD?} ${MYSQL_HOST?} ${MYSQL_TCP_PORT?} # configure user application database and eventually alter user database access -shell_prompt "./Scripts/config_app_database.sh ${dbfile} ${fix_socket} ${docker}" "${cyan}Setup ${dbfile} connection and socket\n${nc}" $config_app_checked +shell_prompt "./Scripts/config_app_database.sh ${dbfile} ${fix_socket} ${docker}" "${cyan}Setup ${dbfile} connection and socket\n${nc}" "$config_app_checked" if [[ $import_identities -eq 1 ]]; then #; $identities file contents export set_DATABASE_PASSWORD=${set_DATABASE_PASSWORD:-$MYSQL_ROOT_PASSWORD} slogger -st $0 "\r${red}WARNING: You will modify SQL ${DATABASE_USER} password !${nc}" - args=("${mysql_connect_args[@]}" \ -"-e use mysql;" \ -"-e create user if not exists '${DATABASE_USER}'@'${mysql_host}' identified by '${set_DATABASE_PASSWORD}';" \ -"-e alter user CURRENT_USER identified by '${set_DATABASE_PASSWORD}';" \ -"-e alter user '${DATABASE_USER}'@'${mysql_host}' identified by '${set_DATABASE_PASSWORD}';" \ -"-e grant all PRIVILEGES on *.* to CURRENT_USER WITH GRANT OPTION;" \ -"-e grant all PRIVILEGES on *.* to '${DATABASE_USER}'@'${mysql_host}' WITH GRANT OPTION;" \ -"-e select * from user where user='${DATABASE_USER}';" \ -"-e create database if not exists ${MYSQL_DATABASE} default character set='utf8' default collate='utf8_bin';" \ -# enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: -# "-e FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;" \ + if [ $authentication_plugin = 1 ]; then + identifiedby="IDENTIFIED VIA ed25519 USING PASSWORD('${set_DATABASE_PASSWORD}')" + else + identifiedby="identified by '${set_DATABASE_PASSWORD}'" + fi + args=(\ +"-e \"use mysql;\"" \ +"-e \"create user if not exists '${DATABASE_USER}'@'${mysql_host}' ${identifiedby};\"" \ +"-e \"alter user CURRENT_USER ${identifiedby};\"" \ +"-e \"alter user '${DATABASE_USER}'@'${mysql_host}' ${identifiedby};\"" \ +"-e \"grant all PRIVILEGES on *.* to CURRENT_USER WITH GRANT OPTION;\"" \ +"-e \"grant all PRIVILEGES on *.* to '${DATABASE_USER}'@'${mysql_host}' WITH GRANT OPTION;\"" \ +"-e \"select * from user where user='${DATABASE_USER}';\"" \ +"-e \"create database if not exists ${MYSQL_DATABASE} default character set='utf8' default collate='utf8_bin';\"" \ +# enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: \ +# "-e \"FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;\"" \ "") slogger -st $0 "Forked script to keep hidden table user secrets..." password=${MYSQL_ROOT_PASSWORD:-''} @@ -173,18 +171,22 @@ if [[ $import_identities -eq 1 ]]; then slogger -st $0 "\r${red}WARNING: You will modify SQL ${MYSQL_USER} password !${nc}" #; $identities file contents export set_MYSQL_PASSWORD=${set_MYSQL_PASSWORD:-$MYSQL_PASSWORD} - args=("${test_mysql_connect_args[@]}" \ -"-e use mysql;" \ -"-e create user if not exists '${MYSQL_USER}'@'${test_mysql_host}' identified by '${set_MYSQL_PASSWORD}';" \ -"-e alter user '${MYSQL_USER}'@'${test_mysql_host}' identified by '${set_MYSQL_PASSWORD}';" \ -"-e grant all PRIVILEGES on ${MYSQL_DATABASE}.* to '${MYSQL_USER}'@'${test_mysql_host}';" \ -"-e grant all PRIVILEGES on ${TEST_DATABASE_NAME}.* to '${MYSQL_USER}'@'${test_mysql_host}';" \ -"-e grant all PRIVILEGES on ${TEST_DATABASE_NAME}2.* to '${MYSQL_USER}'@'${test_mysql_host}';" \ -"-e grant all PRIVILEGES on ${TEST_DATABASE_NAME}3.* to '${MYSQL_USER}'@'${test_mysql_host}';" \ -"-e use ${MYSQL_DATABASE};" \ -"-e select * from mysql.user where user='${MYSQL_USER}';" \ -# enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: -# "-e FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;" \ + if [ $authentication_plugin = 1 ]; then + identifiedby="IDENTIFIED VIA ed25519 USING PASSWORD('${set_MYSQL_PASSWORD}')" + else + identifiedby="identified by '${set_MYSQL_PASSWORD}'" + fi + args=(\ +"-e \"use mysql;\"" \ +"-e \"create user if not exists '${MYSQL_USER}'@'${test_mysql_host}' ${identifiedby};\"" \ +"-e \"alter user '${MYSQL_USER}'@'${test_mysql_host}' ${identifiedby};\"" \ +"-e \"grant all PRIVILEGES on ${MYSQL_DATABASE}.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ +"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ +"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}2.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ +"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}3.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ +"-e \"select * from mysql.user where user='${MYSQL_USER}';\"" \ +# enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: \ +# "-e \"FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;\"" \ "") password=${MYSQL_ROOT_PASSWORD:-''} prompt="" @@ -222,10 +224,10 @@ if [[ $test_checked -eq 1 ]]; then "; : ${MYSQL_USER?} ${MYSQL_PASSWORD?} ${MYSQL_HOST?} ${DB?} slogger -st $0 "Database Unit Tests... DB=${DB} TEST_DATABASE_NAME=${TEST_DATABASE_NAME}" - args=("{test_mysql_connect_args[@]}" \ - "-e CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME};" \ - "-e CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME}2;" \ - "-e CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME}3;" \ + args=(\ + "-e \"CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME};\"" \ + "-e \"CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME}2;\"" \ + "-e \"CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME}3;\"" \ "") exec ${sql_connect} ${sql_connect_test_host} -u ${MYSQL_USER} --password=${MYSQL_PASSWORD} \ "${args[@]}" >> $LOG 2>&1 diff --git a/mysqldb/Dockerfile.armhf b/mysqldb/Dockerfile.armhf index 81ad49402..d6823947e 100644 --- a/mysqldb/Dockerfile.armhf +++ b/mysqldb/Dockerfile.armhf @@ -1,10 +1,17 @@ ARG SECONDARY_HUB FROM ${SECONDARY_HUB:-linuxserver/mariadb:arm32v7-latest} +# When using volumes (-v flags) permissions issues can arise +# between the host OS and the container, we avoid this issue +# by allowing you to specify the user PUID and group PGID. +# $ id $USER +ARG PUID +ENV PUID ${PUID:-0} +ARG PGID +ENV PGID ${PGID:-0} ARG MYSQL_ROOT_PASSWORD ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} -ARG MYSQL_ROOT_HOST -ENV MYSQL_ROOT_HOST ${MYSQL_ROOT_HOST:-%} +# bind-address = "127.0.0.1" > conf.d/my.cnf ARG MYSQL_HOST ENV MYSQL_HOST ${MYSQL_HOST:-127.0.0.1} ENV TZ ${TZ:-'Europe/Paris'} @@ -20,13 +27,16 @@ ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} # Optional ENV MYSQL_ALLOW_EMPTY_PASSWORD=false +COPY mariadb.ans . +RUN cat mariadb.ans + # The MariaDB/MySQL tools read configuration files in the following order: # 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, # 2. "/etc/mysql/conf.d/*.cnf" to set global options. # 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. # 4. "~/.my.cnf" to set user-specific options. COPY conf.d/my.cnf /etc/mysql/conf.d/my.cnf - +COPY mariadb.conf.d/my.cnf /etc/mysql/mariadb.conf.d/my.cnf RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_HOST}/" /etc/mysql/conf.d/my.cnf RUN apt update && apt install -y expect diff --git a/mysqldb/Dockerfile.template b/mysqldb/Dockerfile.template index fb8558d48..2e1646d60 100644 --- a/mysqldb/Dockerfile.template +++ b/mysqldb/Dockerfile.template @@ -1,10 +1,17 @@ ARG SECONDARY_HUB FROM ${SECONDARY_HUB:-linuxserver/mariadb} +# When using volumes (-v flags) permissions issues can arise +# between the host OS and the container, we avoid this issue +# by allowing you to specify the user PUID and group PGID. +# $ id $USER +ARG PUID +ENV PUID ${PUID:-0} +ARG PGID +ENV PGID ${PGID:-0} ARG MYSQL_ROOT_PASSWORD ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} -ARG MYSQL_ROOT_HOST -ENV MYSQL_ROOT_HOST ${MYSQL_ROOT_HOST:-%} +# bind-address = "127.0.0.1" > conf.d/my.cnf ARG MYSQL_HOST ENV MYSQL_HOST ${MYSQL_HOST:-127.0.0.1} ENV TZ ${TZ:-'Europe/Paris'} @@ -20,13 +27,16 @@ ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} # Optional ENV MYSQL_ALLOW_EMPTY_PASSWORD=false +COPY mariadb.ans . +RUN cat mariadb.ans + # The MariaDB/MySQL tools read configuration files in the following order: # 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, # 2. "/etc/mysql/conf.d/*.cnf" to set global options. # 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. # 4. "~/.my.cnf" to set user-specific options. COPY conf.d/my.cnf /etc/mysql/conf.d/my.cnf - +COPY mariadb.conf.d/my.cnf /etc/mysql/mariadb.conf.d/my.cnf RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_HOST}/" /etc/mysql/conf.d/my.cnf RUN apt update && apt install -y expect diff --git a/mysqldb/Dockerfile.x86_64 b/mysqldb/Dockerfile.x86_64 index af98e6dbd..a60ce1cbb 100644 --- a/mysqldb/Dockerfile.x86_64 +++ b/mysqldb/Dockerfile.x86_64 @@ -1,10 +1,17 @@ ARG SECONDARY_HUB FROM ${SECONDARY_HUB:-linuxserver/mariadb:amd64-latest} +# When using volumes (-v flags) permissions issues can arise +# between the host OS and the container, we avoid this issue +# by allowing you to specify the user PUID and group PGID. +# $ id $USER +ARG PUID +ENV PUID ${PUID:-0} +ARG PGID +ENV PGID ${PGID:-0} ARG MYSQL_ROOT_PASSWORD ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} -ARG MYSQL_ROOT_HOST -ENV MYSQL_ROOT_HOST ${MYSQL_ROOT_HOST:-%} +# bind-address = "127.0.0.1" > conf.d/my.cnf ARG MYSQL_HOST ENV MYSQL_HOST ${MYSQL_HOST:-127.0.0.1} ENV TZ ${TZ:-'Europe/Paris'} @@ -20,13 +27,16 @@ ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} # Optional ENV MYSQL_ALLOW_EMPTY_PASSWORD=false +COPY mariadb.ans . +RUN cat mariadb.ans + # The MariaDB/MySQL tools read configuration files in the following order: # 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, # 2. "/etc/mysql/conf.d/*.cnf" to set global options. # 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. # 4. "~/.my.cnf" to set user-specific options. COPY conf.d/my.cnf /etc/mysql/conf.d/my.cnf - +COPY mariadb.conf.d/my.cnf /etc/mysql/mariadb.conf.d/my.cnf RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_HOST}/" /etc/mysql/conf.d/my.cnf RUN apt update && apt install -y expect diff --git a/mysqldb/README.md b/mysqldb/README.md new file mode 100644 index 000000000..782bfbbf4 --- /dev/null +++ b/mysqldb/README.md @@ -0,0 +1,75 @@ +# [betothreeprod/mariadb](https://github.com/b23prodtm/myphpcms/tree/development/mysqldb) + +The architectures supported by this image are: + +| Architecture | repo | +| :----: | --- | +| x86-64 | [betothreeprod/mariadb-intel-nuc](https://hub.docker.com/r/betothreeprod/mariadb-intel-nuc) | +| arm64 | betothreeprod/mariadb-raspberrypi3-64 | +| armhf | [betothreeprod/mariadb-raspberrypi3](https://hub.docker.com/r/betothreeprod/mariadb-raspberrypi3) | + + +## Usage + +Here are some example snippets to help you get started creating a container. + +### docker + +``` +docker create \ + --name=mariadb \ + -e PUID=1000 \ + -e PGID=1000 \ + -e MYSQL_ROOT_PASSWORD=ROOT_ACCESS_PASSWORD \ + -e TZ=Europe/London \ + -e MYSQL_DATABASE=USER_DB_NAME `#optional` \ + -e MYSQL_USER=MYSQL_USER `#optional` \ + -e MYSQL_PASSWORD=DATABASE_PASSWORD `#optional` \ + -e REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql `#optional` \ + -p 3306:3306 \ + -v path_to_data:/config \ + --restart unless-stopped \ + linuxserver/mariadb +``` + + +### docker-compose + +Compatible with docker-compose v2 schemas. + +``` +--- +version: "2.1" +services: + mariadb: + image: betothreeprod/mariadb-%%BALENA_MACHINE_NAME%% + container_name: mariadb + environment: + - PUID=1000 + - PGID=1000 + - MYSQL_ROOT_PASSWORD=ROOT_ACCESS_PASSWORD + - TZ=Europe/London + - MYSQL_DATABASE=USER_DB_NAME #optional + - MYSQL_USER=MYSQL_USER #optional + - MYSQL_PASSWORD=DATABASE_PASSWORD #optional + - REMOTE_SQL=http://URL1/your.sql,https://URL2/your.sql #optional + volumes: + - path_to_data:/config + ports: + - 3306:3306 + restart: unless-stopped +``` + +> %%BALENA_MACHINE_NAME%% it's the template variable for the host system name from [Balena OS reference](https://www.balena.io/docs/reference/base-images/base-images-ref/). +## User / Group Identifiers + +When using volumes (`-v` flags) permissions issues can arise between the host OS and the container, we avoid this issue by allowing you to specify the user `PUID` and group `PGID`. + +Ensure any volume directories on the host are owned by the same user you specify and any permissions issues will vanish like magic. + +In this instance `PUID=1000` and `PGID=1000`, to find yours use `id user` as below: + +``` + $ id $USER + uid=1000(thedockeruser) gid=1000(thedockergroup) groups=1000(thedockergroup) +``` diff --git a/mysqldb/mariadb.ans b/mysqldb/mariadb.ans new file mode 100644 index 000000000..710e13963 --- /dev/null +++ b/mysqldb/mariadb.ans @@ -0,0 +1,23 @@ + + ********#**** + **@@@@((@@@@(@@@* + **@@@@@/*%@@/*&/@* + *@@@@@@@@@@@@@@** + **@@@@@@@@@@@@** + **@@@@@@@@@@@@@* + **@@@@@@@@@@@@@* + **@@@@@@@@@@@@@@@* + **&@@@@@@@@@@@@@@@@* + **%@@@@@@@@@@@@@@@@@@@(* + *****@@@@@@@@@@@@@@@@@@@@@@@@@@* + ***@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*. + ***@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@** + **@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@** + */@@@@@@@@@@@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@@@&*** + *@@@@@@@@@@@@@@@@@@@@@@@@@@@@@**@@@@@@@@*@@#*@@** + **@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@**@@@@@@@/****@@@@@** + *#@@@@@@@@@@@@@@@@** ******@@@@@@@** ********** + ,,**@@@@@@@@@@** **@@@@@@** + *@@@@@@@/*** *%@@@@*** + ****** + diff --git a/mysqldb/mariadb.conf.d/my.cnf b/mysqldb/mariadb.conf.d/my.cnf new file mode 100644 index 000000000..a43b1cdf8 --- /dev/null +++ b/mysqldb/mariadb.conf.d/my.cnf @@ -0,0 +1,4 @@ +[mariadb] +# authentication plugin +#CREATE USER username@hostname IDENTIFIED VIA ed25519 USING PASSWORD('secret'); +plugin_load_add = auth_ed25519 diff --git a/mysqldb/mysql_secure_shell b/mysqldb/mysql_secure_shell index b1addeedd..c89825850 100644 --- a/mysqldb/mysql_secure_shell +++ b/mysqldb/mysql_secure_shell @@ -12,7 +12,7 @@ spawn mysql_secure_installation expect \"Enter current password for root (enter for none): \" send \"\r\" expect \"Switch to unix_socket authentication \[Y/n\] \" -send \"n\r\" +send \"y\r\" expect \"Change the root password? \[Y/n\] \" send \"y\r\" expect \"New password: \" diff --git a/start-cake.sh b/start-cake.sh index 464734d28..82f3e41bd 100755 --- a/start-cake.sh +++ b/start-cake.sh @@ -2,7 +2,7 @@ set -e source ./Scripts/lib/parsing.sh source ./Scripts/lib/shell_prompt.sh -command="server -p 8000" +command="server -p 8000 -H 0.0.0.0" saved=("$@") export COLLECT_COVERAGE="false" usage=("" \ @@ -14,28 +14,28 @@ usage=("" \ " E.g. $0 -c server --help" \ " Default command is " \ " lib/Cake/Console/cake server -p 8000" \ +" --docker Startup Docker Image DATABASE" \ "") while [[ "$#" > 0 ]]; do case $1 in --help ) printf "%s\n" "${usage[@]}" exit 0;; - -[pP]*) - OPTIND=1 - parse_sql_password "MYSQL_ROOT_PASSWORD" "current ${DATABASE_USER}" "$@" + -[vV]*|--verbose ) + set -x + command="-v ${command}" + echo "Passed params : $0 ${saved[*]}";; + -[pP]* ) + parse_sql_password "MYSQL_ROOT_PASSWORD" "current ${DATABASE_USER} password" "$@" shift $((OPTIND -1)) ;; -[tT]*) - OPTIND=1 - parse_sql_password "MYSQL_PASSWORD" "current ${MYSQL_USER}" "$@" + parse_sql_password "MYSQL_PASSWORD" "current ${MYSQL_USER} password" "$@" shift $((OPTIND -1)) ;; -[cC]*) - command=$2 - shift; shift; command="${command} $*" - OPTIND=1 + command="${command} ${*:2}" parse_and_export "p" "CAKE_TCP_PORT" "specify -p " "$@" - shift $((OPTIND -1)) - ;; + break;; --docker ) command="--docker ${command}" ;; diff --git a/test-cake.sh b/test-cake.sh index b872f615f..d1c0c03d4 100755 --- a/test-cake.sh +++ b/test-cake.sh @@ -1,11 +1,12 @@ #!/usr/bin/env bash set -e source ./Scripts/lib/test/parsing.sh -test=("test_parse_and_export" "test_parse_sql_password") +test=("test_parse_and_export" "test_parse_sql_password" "test_arg_exists" "test_arg_trim") for t in "${test[@]}"; do printf "TEST CASES : %s\n" "$t" && eval "$t"; done; sleep 5 bootargs="" +migrate="-u -i --enable-authentication-plugin" saved=("$@") -config_args="-c -h -p=pass -s=word --development --connection=test" +config_args="-c -h -p pass -s word --development --connection=test" config_work_dir="" usage=("" \ "${cyan}Notice:${nc}The test script." \ @@ -15,6 +16,8 @@ usage=("" \ " --travis, --circle Travis or Circle CI Local Test Workflow" \ " --cov Coverage All Tests" \ " -o, --openshift [path to a file with a list of variables]" \ +" --socket Symlink socket /tmp/mysql.sock" \ +" --docker Startup Docker Image DATABASE" \ "Notice: Use environment variables from open container/pod and a file if it exists" \ "") while [[ "$#" > 0 ]]; do case $1 in @@ -36,19 +39,17 @@ while [[ "$#" > 0 ]]; do case $1 in printf "%s\n" "${usage[@]}" exit 0;; -[pP]*) - OPTIND=1 - parse_sql_password "MYSQL_ROOT_PASSWORD" "user ${DATABASE_USER}" "$@" + parse_sql_password "MYSQL_ROOT_PASSWORD" "user ${DATABASE_USER} password" "$@" shift $((OPTIND -1)) ;; -[tT]*) - OPTIND=1 - parse_sql_password "MYSQL_PASSWORD" "test user ${MYSQL_USER}" "$@" + parse_sql_password "MYSQL_PASSWORD" "test user ${MYSQL_USER} password" "$@" shift $((OPTIND -1)) ;; -[vV]*|--verbose ) set -x bootargs="-v ${bootargs}" - echo "Passed params : $0 ${saved}";; + echo "Passed params : $0 ${saved[*]}";; -[oO]*|--openshift ) bootargs="${bootargs} --openshift" config_args="--openshift ${config_args}" @@ -56,7 +57,9 @@ while [[ "$#" > 0 ]]; do case $1 in --docker ) config_args="--docker ${config_args}" bootargs="--docker ${bootargs}";; + --socket ) + migrate="-Y ${migrate}";; *) echo "Unknown parameter, passed $0: $1"; exit 1;; esac; shift; done source ./configure.sh ${config_args} -bash -c "./migrate-database.sh -u ${bootargs} -i" +bash -c "./migrate-database.sh ${migrate} ${bootargs}" From 74476fa9d1f61980ca0186dfece062d506f14189 Mon Sep 17 00:00:00 2001 From: Tiana Rakoto Arimanana <5566338+b23prodtm@users.noreply.github.com> Date: Sun, 3 May 2020 19:08:37 +0200 Subject: [PATCH 3/5] Fixes: test-cake.sh and libmariadbclient armhf pushed to balena.io Fixes: CREATE USER Failed 'username'@'%' Fixes: ./configure.sh: line 75: DATABASE_USER: unbound variable Fixes: No Root Password (FROM linxuserver/mariadb) Fixes: Error: Database connection "MysqlCms" is missing (no quotes !) Fixes: can't open '/e13/etc/constantes.properties' --- .circleci/build.sh | 10 ++--- .circleci/config.yml | 25 +++++------- .circleci/x86_64.env | 12 ------ .gitignore | 2 +- .travis.yml | 51 +++++++++++------------- Dockerfile.armhf | 16 ++++---- Dockerfile.template | 16 ++++---- Dockerfile.x86_64 | 16 ++++---- README.md | 10 +++-- Scripts/bootargs.sh | 4 ++ Scripts/bootstrap.sh | 1 + Scripts/config_app_database.sh | 4 +- Scripts/fooargs.sh | 47 +++++++++++----------- Scripts/lib/test/parsing.sh | 2 + Scripts/start_daemon.sh | 25 +++++++----- common.env | 18 ++------- configure.sh | 1 + docker-compose.x86_64 | 21 +++++----- docker-compose.yml | 21 +++++----- migrate-database.sh | 72 ++++++++++++++-------------------- mysqldb/Dockerfile.armhf | 53 +++++++++++++++---------- mysqldb/Dockerfile.template | 53 +++++++++++++++---------- mysqldb/Dockerfile.x86_64 | 53 +++++++++++++++---------- mysqldb/conf.d/my.cnf | 14 ++++--- mysqldb/mariadb.ans | 7 +++- mysqldb/mariadb.conf.d/my.cnf | 4 -- test-cake.sh | 15 +++---- 27 files changed, 286 insertions(+), 287 deletions(-) delete mode 100644 .circleci/x86_64.env create mode 100644 Scripts/bootargs.sh delete mode 100644 mysqldb/mariadb.conf.d/my.cnf diff --git a/.circleci/build.sh b/.circleci/build.sh index b04fa60b6..944965b1f 100755 --- a/.circleci/build.sh +++ b/.circleci/build.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -work_dir=$(echo $0 | awk 'BEGIN{FS="/";ORS="/"}{ for(i=1;i ${work_dir}config-compat.yml -circleci local execute -c ${work_dir}config-compat.yml || echo -e $usage +[ ! $(which circleci) > /dev/null ] && curl -fLSs https://circle.ci/cli | bash +source ./deploy.sh "$1" --docker +sed -e /custom_checkout:/s/"\"\""/"\"\/tmp\/_circleci_local_build_repo\""/g ${work_dir}/config.yml | circleci config process - > ${work_dir}/config-compat.yml +circleci local execute -c ${work_dir}/config-compat.yml || echo -e $usage diff --git a/.circleci/config.yml b/.circleci/config.yml index 7f69880a3..d29cdc133 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,23 +3,22 @@ jobs: build: docker: - image: betothreeprod/dind-php7 - - image: betothreeprod/mariadb-intel-nuc:dev + - image: betothreeprod/mariadb-intel-nuc environment: PUID: 0 PGID: 0 TZ: Europe/Paris - MYSQL_DATABASE: foo_db - MYSQL_ROOT_PASSWORD: foo_pass - MYSQL_USER: dummy_foo - MYSQL_PASSWORD: foo_pass_test + MYSQL_ROOT_PASSWORD: mariadb + MYSQL_HOST: localhost + MYSQL_DATABASE: aria_db + MYSQL_USER: maria + MYSQL_PASSWORD: maria-abc shell: /bin/bash -leo pipefail environment: - BASH_ENV: /etc/profile - DKR_ARCH: x86_64 - - MYSQL_DATABASE: foo_db - - MYSQL_ROOT_PASSWORD: foo_pass - - MYSQL_USER: dummy_foo - - MYSQL_PASSWORD: foo_pass_test + - MYSQL_HOST: 127.0.0.1 + - MYSQL_TCP_PORT: 3306 working_directory: /var/www/html/ steps: - checkout @@ -45,7 +44,6 @@ jobs: name: Set architecture and Setup Environment Variables command: | source ./deploy.sh $DKR_ARCH --nobuild - echo $(cat $DKR_ARCH.env common.env .circleci/$DKR_ARCH.env | awk 'BEGIN{ FS="$"; RS="$" }{ print "export " $1}') >> /etc/profile - run: name: Waiting for Mysql to be ready command: | @@ -62,7 +60,7 @@ jobs: set -x mkdir -p ./app/build/logs mkdir -p ~/phpunit - ./test-cake.sh --circle -o + source ./test-cake.sh --circle cat $PHP_CMS_DIR/e13/etc/constantes.properties | grep PASSWORD_ADMIN | head -c 18 when: always - save_cache: @@ -83,10 +81,6 @@ jobs: environment: - BASH_ENV: /etc/profile - DKR_ARCH: x86_64 - - MYSQL_DATABASE: foo_db - - MYSQL_ROOT_PASSWORD: foo_pass - - MYSQL_USER: dummy_foo - - MYSQL_PASSWORD: foo_pass_test steps: - checkout - run: @@ -101,7 +95,6 @@ jobs: name: Set architecture and Setup Environment Variables command: | source ./deploy.sh $DKR_ARCH --nobuild - echo $(cat $DKR_ARCH.env | awk 'BEGIN{ FS="$"; RS="$" }{ print "export " $1}') >> /etc/profile - run: command: | set -u diff --git a/.circleci/x86_64.env b/.circleci/x86_64.env deleted file mode 100644 index 8b127a5b1..000000000 --- a/.circleci/x86_64.env +++ /dev/null @@ -1,12 +0,0 @@ -DATABASE_ENGINE=MysqlCms -DATABASE_SERVICE_NAME=MYSQL -MYSQL_ROOT_HOST=127.0.0.1 -MYSQL_TCP_PORT=3306 -MYSQL_HOST=127.0.0.1 -PHP_CMS_DIR=app/webroot/php_cms -DATABASE_USER=root -MYSQL_DATABASE=foo_db -MYSQL_ROOT_PASSWORD=foo_pass -TEST_DATABASE_NAME=test -MYSQL_USER=dummy_foo -MYSQL_PASSWORD=foo_pass_test diff --git a/.gitignore b/.gitignore index 31a2ccbbb..43b947fc7 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,7 @@ myphpcms*.zip /tags *.mo **/composer*.phar - +mysqldb/config/ # IDE and editor specific files # ################################# diff --git a/.travis.yml b/.travis.yml index 042f4b2b4..eb5a52539 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,43 +15,37 @@ dist: trusty env: matrix: - - _PHP=latest _PKG=hhvm - - _PHP=7.1 _PKG=php - - _PHP=7.2 _PKG=php - - _PHP=7.3 _PKG=php + - _PHP=latest _PKG=hhvm PHPENV_ROOT=~/.phpenv # developed by facebook, trusty only + - _PHP=7.2 _PKG=php PHPENV_ROOT=~/.phpenv + - _PHP=7.3 _PKG=php PHPENV_ROOT=~/.phpenv + global: - - PHP_CMS_DIR=app/webroot/php_cms - - _SSL=openssl - - DB=Mysql - - PHPUNIT=4 - - PHPCS=3 - - COLLECT_COVERAGE=false - - PHPENV_ROOT=/usr/local/bin/phpenv - - DKR_ARCH=x86_64 - - WEBHOOK_URL=https://discordapp.com/api/webhooks/479745392880386058/YOO7Nnn1IFWUtXX0n0qAZYeMDeV-SLa0lSzjGpNnKGTzG-xA0T3dplVGzSM4ObKLeMWg - - secure: C39DQ1zYpSAOy33Sb8NP89o6k4HUnjHnQ+bQkgbo3WH7WtiN76dGeO9jm1DjMn5np6oKbDi41/fxonaTUIjb9YMksG2YB+NBDYXHyV1H7/xAeC6uTxwUObrLXh8aOUwiiuLPllMdtOLX8JSPxl1Ixc6KyeFywPiMvwuOe4QZW6sVG4sqhZC/UUycYKRSMaOthtuTDPYKjBLaDPiEzkUmdBIo9IhAsidEFAHj4jEmw9gBtac0B2x7GbvvoDivdH3KdNSoPt2SkD0RLX51Qf7AYeAV4fw65cuCp/Aat/uk55x3lN5g18Ww9khY/cFSwPC0JXGQnnJvdcDP2diZNkqE41Yc/Mw3xwfrvp3/v8js3VIBzsGINKiSdXZ/yXqI9iRzvzlfmXRHvd4sFXRzUpi8ZB4PXaboMndbNRoh4PcoRNFtXhyebQCEgZv2x3oiKXw38WT5cga03uMH4E5z5afS3n7NP1tsuiNWd499dJzAkW8OPeLDPqY3a/b5qLeZIK1bo23mvCjPtbm+B2g2QocKcd1oQ+XANCyuT3M/+AIypdMabGOSon2fDKrUUN+SqIX4FcYaHi1sG3qUp23870u9YcT4hK2LCKBcBPkFpxqEZLwdHbJmjHPo6uRyAKOD7r/k1DtIRqkcJ+5BpU4emo6rM9rdh5mWjLtK7vdY8Y/tvP8= + - COLLECT_COVERAGE=false + - PHPENV_ROOT=/usr/local/bin/phpenv + - _SSL=openssl + - PHP_CMS_DIR=app/webroot/php_cms + - DB=Mysql + - PHPUNIT=4 + - PHPCS=3 + - COLLECT_COVERAGE=false + - DKR_ARCH=x86_64 + - WEBHOOK_URL=https://discordapp.com/api/webhooks/479745392880386058/YOO7Nnn1IFWUtXX0n0qAZYeMDeV-SLa0lSzjGpNnKGTzG-xA0T3dplVGzSM4ObKLeMWg + - secure: C39DQ1zYpSAOy33Sb8NP89o6k4HUnjHnQ+bQkgbo3WH7WtiN76dGeO9jm1DjMn5np6oKbDi41/fxonaTUIjb9YMksG2YB+NBDYXHyV1H7/xAeC6uTxwUObrLXh8aOUwiiuLPllMdtOLX8JSPxl1Ixc6KyeFywPiMvwuOe4QZW6sVG4sqhZC/UUycYKRSMaOthtuTDPYKjBLaDPiEzkUmdBIo9IhAsidEFAHj4jEmw9gBtac0B2x7GbvvoDivdH3KdNSoPt2SkD0RLX51Qf7AYeAV4fw65cuCp/Aat/uk55x3lN5g18Ww9khY/cFSwPC0JXGQnnJvdcDP2diZNkqE41Yc/Mw3xwfrvp3/v8js3VIBzsGINKiSdXZ/yXqI9iRzvzlfmXRHvd4sFXRzUpi8ZB4PXaboMndbNRoh4PcoRNFtXhyebQCEgZv2x3oiKXw38WT5cga03uMH4E5z5afS3n7NP1tsuiNWd499dJzAkW8OPeLDPqY3a/b5qLeZIK1bo23mvCjPtbm+B2g2QocKcd1oQ+XANCyuT3M/+AIypdMabGOSon2fDKrUUN+SqIX4FcYaHi1sG3qUp23870u9YcT4hK2LCKBcBPkFpxqEZLwdHbJmjHPo6uRyAKOD7r/k1DtIRqkcJ+5BpU4emo6rM9rdh5mWjLtK7vdY8Y/tvP8= matrix: - fast_finish: true + #fast_finish: true + exclude: + - os: windows include: - os: linux - language: php - php: 7.1 - env: _PHP=7.1 _PKG=php PHPENV_ROOT=~/.phpenv - - os: linux - language: php - php: 'hhvm' - env: _PHP=latest _PKG=hhvm PHPENV_ROOT=~/.phpenv - os: osx - os: windows - env: _PHP=7.3 _PKG=php _SSL=openssl.light + env: _PHP=7.2 _PKG=php _SSL=openssl.light - os: windows - env: _PHP=latest _PKG=hhvm _SSL=openssl.light + env: _PHP=7.3 _PKG=php _SSL=openssl.light allow_failures: - - php: 'hhvm' - - env: _PHP=3.18 _PKG=hhvm - - env: _PHP=7.3 _PKG=php - os: windows + - os: linux - os: osx addons: @@ -83,10 +77,9 @@ before_install: - source ./deploy.sh "${DKR_ARCH}" --nobuild install: - cd .travis/TravisCI-OSX-PHP - - build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_SSL}"; /usr/local/opt/openssl/bin/c_rehash + - build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_SSL}" "latest"; [ $(which c_rehash) > /dev/null ] && c_rehash - build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}" "--with-openssl" - build/handle_${TRAVIS_OS_NAME}_pkg.sh "${_PKG}" "${_PHP}-xml" - - if [[ "${TRAVIS_OS_NAME}" != "linux" ]]; then build/handle_${TRAVIS_OS_NAME}_pkg.sh "composer"; bash -c 'composer install --dev --no-interaction'; fi - cd ../.. - if [[ "${TRAVIS_OS_NAME}" = "linux" ]]; then curl -s http://getcomposer.org/installer | php && php composer.phar install --dev --no-interaction; fi diff --git a/Dockerfile.armhf b/Dockerfile.armhf index 8b72fe35f..84da88710 100644 --- a/Dockerfile.armhf +++ b/Dockerfile.armhf @@ -7,8 +7,8 @@ ARG PRIMARY_HUB # Primary image is a Linux PHP with Apache 2 server pre-installed FROM ${PRIMARY_HUB:-betothreeprod/raspberrypi3-php}:${IMG_TAG:-latest} -ENV INITSYSTEM on -ENV UDEV on +ENV INITSYSTEM off +ENV UDEV off ARG DEBUG ENV DEBUG ${DEBUG:-0} @@ -23,8 +23,6 @@ ARG DATABASE_ENGINE ENV DATABASE_ENGINE ${DATABASE_ENGINE:-MysqlCms} ARG DATABASE_SERVICE_NAME ENV DATABASE_SERVICE_NAME ${DATABASE_SERVICE_NAME:-MYSQL} -ARG MYSQL_ROOT_HOST -ENV MYSQL_ROOT_HOST ${MYSQL_ROOT_HOST:-%} ARG MYSQL_HOST ENV MYSQL_HOST ${MYSQL_HOST:-db} ARG MYSQL_TCP_PORT @@ -36,15 +34,15 @@ ENV PHP_CMS_DIR ${PHP_CMS_DIR:-'app/webroot/php_cms'} ARG DATABASE_USER ENV DATABASE_USER ${DATABASE_USER:-'root'} ARG MYSQL_DATABASE -ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'foo_db'} +ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'aria_db'} ARG MYSQL_ROOT_PASSWORD -ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} +ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'mariadb'} ARG TEST_DATABASE_NAME ENV TEST_DATABASE_NAME ${TEST_DATABASE_NAME:-'test'} ARG MYSQL_USER -ENV MYSQL_USER ${MYSQL_USER:-'dummy_foo'} +ENV MYSQL_USER ${MYSQL_USER:-'maria'} ARG MYSQL_PASSWORD -ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} +ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'maria-abc'} ARG SERVER_NAME ENV SERVER_NAME ${SERVER_NAME:-'localhost.local'} @@ -154,5 +152,5 @@ WORKDIR /var/www/html/ RUN git submodule sync && git submodule update --init RUN ./configure.sh --openshift -c -h -p pass -s word --development RUN [ "cross-build-end" ] -ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD} --enable-authentication-plugin"] +ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD}"] CMD [ "apache2 -D FOREGROUND" ] diff --git a/Dockerfile.template b/Dockerfile.template index 50ce85ad2..f99930dc6 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -7,8 +7,8 @@ ARG PRIMARY_HUB # Primary image is a Linux PHP with Apache 2 server pre-installed FROM ${PRIMARY_HUB:-betothreeprod/%%BALENA_MACHINE_NAME%%-php}:${IMG_TAG:-latest} -ENV INITSYSTEM on -ENV UDEV on +ENV INITSYSTEM off +ENV UDEV off ARG DEBUG ENV DEBUG ${DEBUG:-0} @@ -23,8 +23,6 @@ ARG DATABASE_ENGINE ENV DATABASE_ENGINE ${DATABASE_ENGINE:-MysqlCms} ARG DATABASE_SERVICE_NAME ENV DATABASE_SERVICE_NAME ${DATABASE_SERVICE_NAME:-MYSQL} -ARG MYSQL_ROOT_HOST -ENV MYSQL_ROOT_HOST ${MYSQL_ROOT_HOST:-%} ARG MYSQL_HOST ENV MYSQL_HOST ${MYSQL_HOST:-db} ARG MYSQL_TCP_PORT @@ -36,15 +34,15 @@ ENV PHP_CMS_DIR ${PHP_CMS_DIR:-'app/webroot/php_cms'} ARG DATABASE_USER ENV DATABASE_USER ${DATABASE_USER:-'root'} ARG MYSQL_DATABASE -ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'foo_db'} +ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'aria_db'} ARG MYSQL_ROOT_PASSWORD -ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} +ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'mariadb'} ARG TEST_DATABASE_NAME ENV TEST_DATABASE_NAME ${TEST_DATABASE_NAME:-'test'} ARG MYSQL_USER -ENV MYSQL_USER ${MYSQL_USER:-'dummy_foo'} +ENV MYSQL_USER ${MYSQL_USER:-'maria'} ARG MYSQL_PASSWORD -ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} +ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'maria-abc'} ARG SERVER_NAME ENV SERVER_NAME ${SERVER_NAME:-'localhost.local'} @@ -154,5 +152,5 @@ WORKDIR /var/www/html/ RUN git submodule sync && git submodule update --init RUN ./configure.sh --openshift -c -h -p pass -s word --development # RUN [ "cross-build-end" ] -ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD} --enable-authentication-plugin"] +ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD}"] CMD [ "apache2 -D FOREGROUND" ] diff --git a/Dockerfile.x86_64 b/Dockerfile.x86_64 index d5bfd646b..99646e3a2 100644 --- a/Dockerfile.x86_64 +++ b/Dockerfile.x86_64 @@ -7,8 +7,8 @@ ARG PRIMARY_HUB # Primary image is a Linux PHP with Apache 2 server pre-installed FROM ${PRIMARY_HUB:-betothreeprod/intel-nuc-php}:${IMG_TAG:-latest} -ENV INITSYSTEM on -ENV UDEV on +ENV INITSYSTEM off +ENV UDEV off ARG DEBUG ENV DEBUG ${DEBUG:-0} @@ -23,8 +23,6 @@ ARG DATABASE_ENGINE ENV DATABASE_ENGINE ${DATABASE_ENGINE:-MysqlCms} ARG DATABASE_SERVICE_NAME ENV DATABASE_SERVICE_NAME ${DATABASE_SERVICE_NAME:-MYSQL} -ARG MYSQL_ROOT_HOST -ENV MYSQL_ROOT_HOST ${MYSQL_ROOT_HOST:-%} ARG MYSQL_HOST ENV MYSQL_HOST ${MYSQL_HOST:-db} ARG MYSQL_TCP_PORT @@ -36,15 +34,15 @@ ENV PHP_CMS_DIR ${PHP_CMS_DIR:-'app/webroot/php_cms'} ARG DATABASE_USER ENV DATABASE_USER ${DATABASE_USER:-'root'} ARG MYSQL_DATABASE -ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'foo_db'} +ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'aria_db'} ARG MYSQL_ROOT_PASSWORD -ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} +ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'mariadb'} ARG TEST_DATABASE_NAME ENV TEST_DATABASE_NAME ${TEST_DATABASE_NAME:-'test'} ARG MYSQL_USER -ENV MYSQL_USER ${MYSQL_USER:-'dummy_foo'} +ENV MYSQL_USER ${MYSQL_USER:-'maria'} ARG MYSQL_PASSWORD -ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} +ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'maria-abc'} ARG SERVER_NAME ENV SERVER_NAME ${SERVER_NAME:-'localhost.local'} @@ -154,5 +152,5 @@ WORKDIR /var/www/html/ RUN git submodule sync && git submodule update --init RUN ./configure.sh --openshift -c -h -p pass -s word --development # RUN [ "cross-build-end" ] -ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD} --enable-authentication-plugin"] +ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD}"] CMD [ "apache2 -D FOREGROUND" ] diff --git a/README.md b/README.md index 2df52ed4d..b0a482379 100644 --- a/README.md +++ b/README.md @@ -261,14 +261,18 @@ PHP mysql extensions must be installed. Log in with root privileges should work: - mysql -u root --password= cakephp_test + mysql -u root --password= + +If not, do a reset of your passwords: + + mysqladmin -uroot password If it isn't possible to login: + Check your environment variables (common.env and docker-compose.yml) settings). Use one or the other, and see which works for you: - MYSQL_ROOT_HOST=% (Unix/OSX platforms) + MYSQL_HOST=127.0.0.1 (Unix/OSX platforms) or if docker mysql service containers: - MYSQL_ROOT_HOST=127.0.0.1 + MYSQL_HOST=localhost .. MYSQL_TCP_PORT=3306 diff --git a/Scripts/bootargs.sh b/Scripts/bootargs.sh new file mode 100644 index 000000000..ed509d6f2 --- /dev/null +++ b/Scripts/bootargs.sh @@ -0,0 +1,4 @@ +incBOOT_ARGS=${incBOOT_ARGS:-0}; if [ $incBOOT_ARGS -eq 0 ]; then + export incBOOT_ARGS=1 + eval $(cat .env common.env | awk 'BEGIN{ FS="$" }{ print "export " $1 }') +fi diff --git a/Scripts/bootstrap.sh b/Scripts/bootstrap.sh index c5a84d0b0..95fcc575b 100755 --- a/Scripts/bootstrap.sh +++ b/Scripts/bootstrap.sh @@ -8,6 +8,7 @@ pargs=$(parse_arg_trim "-[oO]+|--openshift" $*) if [ $openshift 2> /dev/null ]; then slogger -st $0 "Bootargs...: ${pargs}" export CAKEPHP_DEBUG_LEVEL=1 + source ./Scripts/bootargs.sh $* else slogger -st $0 "Locally Testing values, bootargs...: ${pargs}" export CAKEPHP_DEBUG_LEVEL=2 diff --git a/Scripts/config_app_database.sh b/Scripts/config_app_database.sh index 40b4d7419..44f178db6 100755 --- a/Scripts/config_app_database.sh +++ b/Scripts/config_app_database.sh @@ -3,9 +3,9 @@ sqlversion="5.7" source ./Scripts/lib/logging.sh source ./Scripts/lib/parsing.sh docker=$(parse_arg_exists "--docker" $*) +MARIADB_SHORT_NAME=$(echo $SECONDARY_HUB | awk -F/ '{ print $2 }' | awk -F: '{ print $1 }') if [ $docker 2> /dev/null ]; then ./Scripts/start_daemon.sh ${docker} - docker exec -i maria ln -vsf /tmp/mysqld.sock /var/run/mysqld/mysqld.sock else if [ ! $(which brew) 2> /dev/null ]; then echo "Missing homebrew... aborted mysql check."; elif [ ! $(which mysql) 2> /dev/null ]; then slogger -st $0 "Missing MySQL ${sqlversion} database service." @@ -26,7 +26,7 @@ while [[ "$#" > 0 ]]; do case $1 in ;; -[yY]*) if [ $docker 2> /dev/null ]; then - docker exec maria ln -vsf /tmp/mysqld.sock /var/run/mysqld/mysqld.sock + docker exec ${MARIADB_SHORT_NAME} "mkdir -p /var/run/mysqld && ln -vs /tmp/mysqld.sock /var/run/mysqld/mysqld.sock" else if [ $(which mysql) 2> /dev/null ]; then mysql --version diff --git a/Scripts/fooargs.sh b/Scripts/fooargs.sh index a04127c73..93031f0c3 100755 --- a/Scripts/fooargs.sh +++ b/Scripts/fooargs.sh @@ -12,48 +12,51 @@ incFOO_ARGS=${incFOO_ARGS:-0}; if [ $incFOO_ARGS -eq 0 ]; then orange="\033[0;33m" cyan="\033[0;36m" slogger -st $0 "Loading ${orange}Test environment${nc} : $0..." + #; Common Environment profile + eval $(cat .env common.env | awk 'BEGIN{ FS="$" }{ print "export " $1 }') #; To change Model/Datasource/Database export DB=${DB:-Mysql} [ "${DB}" = "Mysql" ] && export DATABASE_ENGINE=MysqlCms && export DATABASE_SERVICE_NAME=MYSQL [ "${DB}" = "Pgsql" ] && export DATABASE_ENGINE=PostgresCms && export DATABASE_SERVICE_NAME=PGSQL [ "${DB}" = "Sqlite" ] && export DATABASE_ENGINE=SqliteCms && export DATABASE_SERVICE_NAME=SQLITE slogger -st $0 "DB : ${green}${DB}${nc}" - if [ $docker 2> /dev/null ]; then - export MYSQL_ROOT_HOST=127.0.0.1 - export PGSQL_SERVICE_HOST=127.0.0.1 - fi - export MYSQL_ROOT_HOST=${MYSQL_ROOT_HOST:-%} - export PGSQL_SERVICE_HOST=${PGSQL_SERVICE_HOST:-%} - export MYSQL_TCP_PORT=3306 - #; To override, use shell parameter -dbase= instead - export MYSQL_DATABASE=${MYSQL_DATABASE:-foo_db} - export DATABASE_USER=${DATABASE_USER:-root} - #; To override, shell parameter -p= instead - export MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-foo_pass} - #. Test configuration ?test=1, ./test_cake.sh + # Test units : + # - Web interface: + # URL: http://localhost:8000/index.php?test=1 + # - Built-in cake Console + # $ ./test_cake.sh + # - Continuous Integration + # $ .circleci/build.sh + # if [ $docker 2> /dev/null ]; then export MYSQL_HOST=127.0.0.1 export TEST_PGSQL_SERVICE_HOST=127.0.0.1 fi - export MYSQL_HOST=${MYSQL_HOST:-localhost} - export TEST_PGSQL_SERVICE_HOST=${TEST_PGSQL_SERVICE_HOST:-localhost} + export MYSQL_HOST=${MYSQL_HOST:-'localhost'} + export MYSQL_TCP_PORT=${MYSQL_TCP_PORT:-'3306'} + #; To override, use shell parameter -dbase= instead + export MYSQL_DATABASE=${MYSQL_DATABASE:-'aria_db'} + export DATABASE_USER=${DATABASE_USER:-'root'} + #; To override, shell parameter -p= instead + export MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-'mariadb'} + export TEST_PGSQL_SERVICE_HOST=${TEST_PGSQL_SERVICE_HOST:-'localhost'} #; To override, use shell parameter -tbase= instead - export TEST_DATABASE_NAME=${TEST_DATABASE_NAME:-test} - export MYSQL_USER=${MYSQL_USER:-dummy_foo} + export TEST_DATABASE_NAME=${TEST_DATABASE_NAME:-'test'} + export MYSQL_USER=${MYSQL_USER:-'maria'} #; To override, use shell parameter -t instead - export MYSQL_PASSWORD=${MYSQL_PASSWORD:-foo_pass_test} + export MYSQL_PASSWORD=${MYSQL_PASSWORD:-'maria-abc'} export FTP_SERVICE_HOST=localhost export FTP_SERVICE_USER=test export FTP_SERVICE_PASSWORD=mypassword #; More about default environment app/Config/core.php #; Openshift Online secure keys (default_keys) - export CAKEPHP_SECURITY_SALT=${CAKEPHP_SECURITY_SALT:-Word} - export CAKEPHP_SECURITY_CIPHER_SEED=${CAKEPHP_SECURITY_CIPHER_SEED:-01234} + export CAKEPHP_SECURITY_SALT=${CAKEPHP_SECURITY_SALT:-'Word'} + export CAKEPHP_SECURITY_CIPHER_SEED=${CAKEPHP_SECURITY_CIPHER_SEED:-'01234'} #; 0, 1, 2 the higher the more debug data - export CAKEPHP_DEBUG_LEVEL=${CAKEPHP_DEBUG_LEVEL:-2} + export CAKEPHP_DEBUG_LEVEL=${CAKEPHP_DEBUG_LEVEL:-'2'} #; Shell parameters -h -p password -s salt #; export GET_HASH_PASSWORD=wokUd0mcc - export PHP_CMS_DIR=${PHP_CMS_DIR:-app/webroot/php_cms} + export PHP_CMS_DIR=${PHP_CMS_DIR:-'app/webroot/php_cms'} if [[ $(parse_arg_exists "-[vV]+|--verbose" $*) ]]; then echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" echo "MYSQL_PASSWORD=${MYSQL_PASSWORD}" diff --git a/Scripts/lib/test/parsing.sh b/Scripts/lib/test/parsing.sh index e7ff5a508..c8be5b800 100644 --- a/Scripts/lib/test/parsing.sh +++ b/Scripts/lib/test/parsing.sh @@ -15,6 +15,7 @@ function test_parse_and_export() { parse_and_export "${args[@]}" [ "$P" = "pass_two" ] \ && printf "$Z" "OK" "2° export" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "2° export" $FUNCNAME $OPTIND + unset P T } function test_parse_sql_password() { @@ -27,6 +28,7 @@ function test_parse_sql_password() { parse_sql_password "${args[@]}" [ "$S" = "pass_two" ] \ && printf "$Z" "OK" "2° password" $FUNCNAME $OPTIND || printf "$Z" "FAILED" "2° password" $FUNCNAME $OPTIND + unset P S } function test_arg_exists() { diff --git a/Scripts/start_daemon.sh b/Scripts/start_daemon.sh index dc7da9013..9bd7de66c 100755 --- a/Scripts/start_daemon.sh +++ b/Scripts/start_daemon.sh @@ -1,10 +1,13 @@ #!/usr/bin/env bash +TOPDIR=$(cd `dirname $BASH_SOURCE`/.. && pwd) source ./Scripts/lib/logging.sh source ./Scripts/lib/shell_prompt.sh source ./Scripts/lib/parsing.sh docker=$(parse_arg_exists "--docker" $*) ck_args=$(parse_arg_trim "-[oO]+|--openshift|--docker" $*) LOG=$(new_log) && slogger -st $0 $LOG +MARIADB_SHORT_NAME=$(echo $SECONDARY_HUB | awk -F/ '{ print $2 }' | awk -F: '{ print $1 }') +MARIADB_CONT_NAME=betothreeprod/${MARIADB_SHORT_NAME}-${BALENA_MACHINE_NAME:-intel-nuc} wait_for_host() { [ "$#" -lt 2 ] && printf "Usage: $FUNCNAME " && exit 1 for i in `seq 1 10`; do @@ -15,24 +18,28 @@ wait_for_host() { return 1 } if [ $docker 2> /dev/null ]; then - container="betothreeprod/mariadb-${BALENA_MACHINE_NAME:-intel-nuc}" - slogger -st $0 "Docker list maria containers ($container)" + slogger -st $0 "Docker list ${MARIADB_SHORT_NAME} containers" #docker quits shell ?? - maria=$(docker ps -q -a -f "name=maria") + maria=$(docker ps -q -a -f "name=${MARIADB_SHORT_NAME}") if [ ! -z $maria ]; then - slogger -st $0 "Container $container already running, was stopped." + slogger -st $0 "Container $MARIADB_SHORT_NAME already running, was stopped." docker kill $maria >> $LOG 2>&1 || true fi docker rm -f $maria >> $LOG 2>&1 || true - slogger -st $0 "Container $container 's started up..." - docker run --name maria -id -h $MYSQL_HOST --publish $MYSQL_TCP_PORT:$MYSQL_TCP_PORT \ - --env-file common.env --env-file .env ${container} >> $LOG 2>&1 + slogger -st $0 "Container $MARIADB_SHORT_NAME 's started up..." + docker run --name $MARIADB_SHORT_NAME -id \ + --env-file common.env --env-file .env \ + -e PUID=$(id -u $USER) -e PGID=$(id -g $USER) \ + -h $MYSQL_HOST --publish $MYSQL_TCP_PORT:$MYSQL_TCP_PORT \ + -v $TOPDIR/mysqldb/config:/config \ + -v $TOPDIR/mysqldb/mysqld:/var/run/mysqld \ + ${MARIADB_CONT_NAME} >> $LOG 2>&1 if [ $? = 0 ]; then - slogger -st $0 "Started docker container --name maria ref: $(docker ps -q -a -f "name=maria") host: $MYSQL_HOST}" + slogger -st $0 "Started docker --name=${MARIADB_SHORT_NAME} ref: $(docker ps -q -a -f "name=maria") host: $MYSQL_HOST}" wait_for_host $MYSQL_HOST ${MYSQL_TCP_PORT:-3306} [ $? = 1 ] && slogger -st $0 "${red}Failed waiting for Mysql${nc}" fi - slogger -st $0 "Connect to docker exec -it maria .." + slogger -st $0 "Connect to docker exec -it ${MARIADB_SHORT_NAME} .." check_log $LOG fi if [ $(parse_arg_exists "server" $ck_args) >> $LOG 2>&1 ]; then diff --git a/common.env b/common.env index 5b9838e17..39f207245 100644 --- a/common.env +++ b/common.env @@ -1,19 +1,7 @@ BALENA_PROJECTS=("mysqldb" "." "deployment/images/primary" "deployment/images/primary.dind") BALENA_PROJECTS_FLAGS=(IMG_TAG PRIMARY_HUB SECONDARY_HUB) -PUID=1000 -PGID=1000 -TZ=Europe/Paris COLLECT_COVERAGE=false - -DATABASE_ENGINE=MysqlCms -DATABASE_SERVICE_NAME=MYSQL -MYSQL_ROOT_HOST=127.0.0.1 -MYSQL_TCP_PORT=3306 -MYSQL_HOST=127.0.0.1 -PHP_CMS_DIR=app/webroot/php_cms DATABASE_USER=root -MYSQL_DATABASE=foo_db -MYSQL_ROOT_PASSWORD=foo_pass -TEST_DATABASE_NAME=test -MYSQL_USER=dummy_foo -MYSQL_PASSWORD=foo_pass_test +PUID=0 +PGID=0 +TZ=Europe/Paris diff --git a/configure.sh b/configure.sh index da16ca7a1..6ab9969fd 100755 --- a/configure.sh +++ b/configure.sh @@ -8,6 +8,7 @@ docker=$(parse_arg_exists "--docker" $*) pargs=$(parse_arg_trim "--docker|-[oO]+|--openshift" $*) if [ $openshift 2> /dev/null ]; then slogger -st $0 "Bootargs...: ${pargs}" + source ./Scripts/bootargs.sh $* else slogger -st $0 "Locally Testing values, bootargs...: ${pargs}" source ./Scripts/fooargs.sh $* diff --git a/docker-compose.x86_64 b/docker-compose.x86_64 index f8d61079c..bfe18f434 100644 --- a/docker-compose.x86_64 +++ b/docker-compose.x86_64 @@ -5,12 +5,14 @@ services: context: mysqldb dockerfile: Dockerfile.x86_64 args: - # bind-address = "127.0.0.1" > conf.d/my.cnf - MYSQL_HOST: "127.0.0.1" - MYSQL_DATABASE: "foo_db" - MYSQL_ROOT_PASSWORD: "foo_pass" - MYSQL_USER: "dummy_foo" - MYSQL_PASSWORD: "foo_pass_test" + PUID: 0 + PGID: 0 + TZ: Europe/Paris + MYSQL_ROOT_PASSWORD: mariadb + MYSQL_HOST: localhost + MYSQL_DATABASE: aria_db + MYSQL_USER: abc + MYSQL_PASSWORD: maria-abc image: betothreeprod/mariadb-intel-nuc volumes: - db-data:/config @@ -30,12 +32,7 @@ services: dockerfile: Dockerfile.x86_64 args: DEBUG: "1" - # mysql -h "localhost" uses db-socket - MYSQL_HOST: "127.0.0.1" - MYSQL_DATABASE: "foo_db" - MYSQL_ROOT_PASSWORD: "foo_pass" - MYSQL_USER: "dummy_foo" - MYSQL_PASSWORD: "foo_pass_test" + DATABASE_USER: "root" image: betothreeprod/myphpcms-intel-nuc labels: io.balena.features.dbus: "1" diff --git a/docker-compose.yml b/docker-compose.yml index ce420d66b..1dd428c3b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,12 +5,14 @@ services: context: mysqldb dockerfile: Dockerfile.template args: - # bind-address = "127.0.0.1" > conf.d/my.cnf - MYSQL_HOST: "127.0.0.1" - MYSQL_DATABASE: "foo_db" - MYSQL_ROOT_PASSWORD: "foo_pass" - MYSQL_USER: "dummy_foo" - MYSQL_PASSWORD: "foo_pass_test" + PUID: 0 + PGID: 0 + TZ: Europe/Paris + MYSQL_ROOT_PASSWORD: mariadb + MYSQL_HOST: localhost + MYSQL_DATABASE: aria_db + MYSQL_USER: abc + MYSQL_PASSWORD: maria-abc image: betothreeprod/mariadb-%%BALENA_MACHINE_NAME%% volumes: - db-data:/config @@ -30,12 +32,7 @@ services: dockerfile: Dockerfile.template args: DEBUG: "1" - # mysql -h "localhost" uses db-socket - MYSQL_HOST: "127.0.0.1" - MYSQL_DATABASE: "foo_db" - MYSQL_ROOT_PASSWORD: "foo_pass" - MYSQL_USER: "dummy_foo" - MYSQL_PASSWORD: "foo_pass_test" + DATABASE_USER: "root" image: betothreeprod/myphpcms-%%BALENA_MACHINE_NAME%% labels: io.balena.features.dbus: "1" diff --git a/migrate-database.sh b/migrate-database.sh index 537c48cfa..1c2307f01 100755 --- a/migrate-database.sh +++ b/migrate-database.sh @@ -8,9 +8,10 @@ docker=$(parse_arg_exists "--docker" "$@") pargs=$(parse_arg_trim "-[oO]+|--openshift|--docker" "$@") if [ $openshift 2> /dev/null ]; then slogger -st $0 "Bootargs...: ${pargs}" + source ./Scripts/bootargs.sh $* else slogger -st $0 "Locally Testing values, bootargs...: ${pargs}" - source ./Scripts/fooargs.sh "$@" + source ./Scripts/fooargs.sh $* fi LOG=$(new_log) && slogger -st $0 $LOG usage=("" \ @@ -46,19 +47,17 @@ test_checked=0 update_checked=0 import_identities=0 identities=app/Config/database.sql -new_pass="" -new_test_pass="" saved=("$@") authentication_plugin=0 -mysql_host=${MYSQL_ROOT_HOST} -test_mysql_host="%" +mysql_host="%" ck_args="--connection=default" +MARIADB_SHORT_NAME=$(echo $SECONDARY_HUB | awk -F/ '{ print $2 }' | awk -F: '{ print $1 }') while [[ "$#" > 0 ]]; do case "$1" in --enable-authentication-plugin*) authentication_plugin=1;; --docker ) bash -c "./Scripts/start_daemon.sh ${docker}" - sql_connect="docker exec maria mysql" + sql_connect="docker exec $MARIADB_SHORT_NAME mysql" sql_connect_host="" sql_connect_test_host="" ;; @@ -131,14 +130,19 @@ $(export -p | grep "DATABASE\|MYSQL") \ shift; #echo "$@"; done #; check unbound variables, exits scripts and inform user on the standard output. -: ${MYSQL_DATABASE?} ${DATABASE_USER?} ${MYSQL_ROOT_PASSWORD?} ${MYSQL_ROOT_HOST?} ${MYSQL_TCP_PORT?} +: ${MYSQL_DATABASE?} ${DATABASE_USER?} ${MYSQL_ROOT_PASSWORD?} ${MYSQL_TCP_PORT?} : $TEST_DATABASE_NAME?} ${MYSQL_USER?} ${MYSQL_PASSWORD?} ${MYSQL_HOST?} ${MYSQL_TCP_PORT?} # configure user application database and eventually alter user database access shell_prompt "./Scripts/config_app_database.sh ${dbfile} ${fix_socket} ${docker}" "${cyan}Setup ${dbfile} connection and socket\n${nc}" "$config_app_checked" if [[ $import_identities -eq 1 ]]; then - #; $identities file contents + #; ---------------------------------- set MYSQL_ROOT_PASSWORD export set_DATABASE_PASSWORD=${set_DATABASE_PASSWORD:-$MYSQL_ROOT_PASSWORD} slogger -st $0 "\r${red}WARNING: You will modify SQL ${DATABASE_USER} password !${nc}" + prompt="-Y" + if [ -z ${set_DATABASE_PASSWORD} ]; then + slogger -st $0 "\r${orange}WARNING: Using blank password for ${DATABASE_USER} !!${nc}" + prompt="" + fi if [ $authentication_plugin = 1 ]; then identifiedby="IDENTIFIED VIA ed25519 USING PASSWORD('${set_DATABASE_PASSWORD}')" else @@ -146,31 +150,27 @@ if [[ $import_identities -eq 1 ]]; then fi args=(\ "-e \"use mysql;\"" \ -"-e \"create user if not exists '${DATABASE_USER}'@'${mysql_host}' ${identifiedby};\"" \ -"-e \"alter user CURRENT_USER ${identifiedby};\"" \ "-e \"alter user '${DATABASE_USER}'@'${mysql_host}' ${identifiedby};\"" \ -"-e \"grant all PRIVILEGES on *.* to CURRENT_USER WITH GRANT OPTION;\"" \ "-e \"grant all PRIVILEGES on *.* to '${DATABASE_USER}'@'${mysql_host}' WITH GRANT OPTION;\"" \ -"-e \"select * from user where user='${DATABASE_USER}';\"" \ "-e \"create database if not exists ${MYSQL_DATABASE} default character set='utf8' default collate='utf8_bin';\"" \ # enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: \ # "-e \"FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;\"" \ +"-e \"select * from user where user='${DATABASE_USER}';\"" \ "") slogger -st $0 "Forked script to keep hidden table user secrets..." - password=${MYSQL_ROOT_PASSWORD:-''} - prompt="" - if [ $password = '' ]; then - slogger -st $0 "\r${orange}WARNING: Using blank password for ${DATABASE_USER} !!${nc}" - else - prompt="-Y" - password="--password=${password}" + if [ ! -z ${MYSQL_ROOT_PASSWORD:-''} ]; then + password="--password=${MYSQL_ROOT_PASSWORD}" fi shell_prompt "exec ${sql_connect} ${sql_connect_host} -u ${DATABASE_USER} ${password} \ ${args[*]} >> $LOG 2>&1" "Import default identities" "$prompt"\ && export MYSQL_ROOT_PASSWORD=${set_DATABASE_PASSWORD} + #; ---------------------------------- set MYSQL_PASSWORD slogger -st $0 "\r${red}WARNING: You will modify SQL ${MYSQL_USER} password !${nc}" - #; $identities file contents export set_MYSQL_PASSWORD=${set_MYSQL_PASSWORD:-$MYSQL_PASSWORD} + if [ -z ${set_MYSQL_PASSWORD} ]; then + slogger -st $0 "\r${orange}WARNING: Using blank password for ${MYSQL_USER} !!${nc}" + prompt="" + fi if [ $authentication_plugin = 1 ]; then identifiedby="IDENTIFIED VIA ed25519 USING PASSWORD('${set_MYSQL_PASSWORD}')" else @@ -178,24 +178,19 @@ if [[ $import_identities -eq 1 ]]; then fi args=(\ "-e \"use mysql;\"" \ -"-e \"create user if not exists '${MYSQL_USER}'@'${test_mysql_host}' ${identifiedby};\"" \ -"-e \"alter user '${MYSQL_USER}'@'${test_mysql_host}' ${identifiedby};\"" \ -"-e \"grant all PRIVILEGES on ${MYSQL_DATABASE}.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ -"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ -"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}2.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ -"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}3.* to '${MYSQL_USER}'@'${test_mysql_host}';\"" \ -"-e \"select * from mysql.user where user='${MYSQL_USER}';\"" \ +"-e \"create user if not exists '${MYSQL_USER}'@'${mysql_host}' ${identifiedby};\"" \ +"-e \"alter user '${MYSQL_USER}'@'${mysql_host}' ${identifiedby};\"" \ +"-e \"grant all PRIVILEGES on ${MYSQL_DATABASE}.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ +"-e \"create database if not exists ${TEST_DATABASE_NAME};\"" \ +"-e \"create database if not exists ${TEST_DATABASE_NAME}2;\"" \ +"-e \"create database if not exists ${TEST_DATABASE_NAME}3;\"" \ +"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ +"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}2.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ +"-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}3.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ # enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: \ # "-e \"FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;\"" \ +"-e \"select * from user where user='${MYSQL_USER}';\"" \ "") - password=${MYSQL_ROOT_PASSWORD:-''} - prompt="" - if [ $password = '' ]; then - slogger -st $0 "\r${orange}WARNING: Using blank password for ${MYSQL_USER} !!${nc}" - else - prompt="-Y" - password="--password=${password}" - fi shell_prompt "exec ${sql_connect} ${sql_connect_test_host} -u ${DATABASE_USER} ${password} \ ${args[*]} >> $LOG 2>&1" "Import test identities" "$prompt" \ && export MYSQL_PASSWORD=${set_MYSQL_PASSWORD} @@ -224,13 +219,6 @@ if [[ $test_checked -eq 1 ]]; then "; : ${MYSQL_USER?} ${MYSQL_PASSWORD?} ${MYSQL_HOST?} ${DB?} slogger -st $0 "Database Unit Tests... DB=${DB} TEST_DATABASE_NAME=${TEST_DATABASE_NAME}" - args=(\ - "-e \"CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME};\"" \ - "-e \"CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME}2;\"" \ - "-e \"CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE_NAME}3;\"" \ - "") - exec ${sql_connect} ${sql_connect_test_host} -u ${MYSQL_USER} --password=${MYSQL_PASSWORD} \ -"${args[@]}" >> $LOG 2>&1 check_log $LOG cat < conf.d/my.cnf +ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'mariadb'} +# bind-address = '127.0.0.1' > conf.d/my.cnf ARG MYSQL_HOST -ENV MYSQL_HOST ${MYSQL_HOST:-127.0.0.1} +ENV MYSQL_HOST ${MYSQL_HOST:-'localhost'} ENV TZ ${TZ:-'Europe/Paris'} # Optional ARG MYSQL_DATABASE -ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'foo_db'} +ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'aria_db'} # Optional ARG MYSQL_USER -ENV MYSQL_USER ${MYSQL_USER:-'dummy_foo'} +ENV MYSQL_USER ${MYSQL_USER:-'maria'} # Optional ARG MYSQL_PASSWORD -ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} +ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'maria-abc'} # Optional -ENV MYSQL_ALLOW_EMPTY_PASSWORD=false - -COPY mariadb.ans . -RUN cat mariadb.ans +ARG MYSQL_BIND_ADDRESS +ENV MYSQL_BIND_ADDRESS ${MYSQL_BIND_ADDRESS:-0.0.0.0} # The MariaDB/MySQL tools read configuration files in the following order: -# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, -# 2. "/etc/mysql/conf.d/*.cnf" to set global options. -# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. -# 4. "~/.my.cnf" to set user-specific options. +# 1. "/etc/mysql/my.cnf" to set global defaults, +# 2. "/etc/mysql/conf.d/my.cnf" to set server options. +# 3. "~/.my.cnf" User COPY conf.d/my.cnf /etc/mysql/conf.d/my.cnf -COPY mariadb.conf.d/my.cnf /etc/mysql/mariadb.conf.d/my.cnf -RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_HOST}/" /etc/mysql/conf.d/my.cnf +RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_BIND_ADDRESS}/" /etc/mysql/conf.d/my.cnf + +RUN apt update && apt install -y \ + expect \ + # auth_ed25519 support package + libmariadbclient18 \ + \ + && echo "**** cleanup ****" && \ + rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* -RUN apt update && apt install -y expect +COPY mysql_secure_shell . +RUN chmod 1755 mysql_secure_shell +RUN ./mysql_secure_shell -COPY mysql_secure_shell /usr/local/bin -RUN chmod 1755 /usr/local/bin/mysql_secure_shell -RUN mysql_secure_shell +RUN echo "***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}..." \ + && echo "GRANT ALL PRIVILEGES ON *.* TO CURRENT USER WITH GRANT OPTION;" | tee -a p.sql \ + && echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" | tee -a p.sql \ + && mkdir -p /config/initdb.d/ && mv p.sql /config/initdb.d/patch.sql + +COPY mariadb.ans . +RUN cat mariadb.ans diff --git a/mysqldb/Dockerfile.template b/mysqldb/Dockerfile.template index 2e1646d60..8e7c4ca6d 100644 --- a/mysqldb/Dockerfile.template +++ b/mysqldb/Dockerfile.template @@ -10,37 +10,50 @@ ENV PUID ${PUID:-0} ARG PGID ENV PGID ${PGID:-0} ARG MYSQL_ROOT_PASSWORD -ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} -# bind-address = "127.0.0.1" > conf.d/my.cnf +ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'mariadb'} +# bind-address = '127.0.0.1' > conf.d/my.cnf ARG MYSQL_HOST -ENV MYSQL_HOST ${MYSQL_HOST:-127.0.0.1} +ENV MYSQL_HOST ${MYSQL_HOST:-'localhost'} ENV TZ ${TZ:-'Europe/Paris'} # Optional ARG MYSQL_DATABASE -ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'foo_db'} +ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'aria_db'} # Optional ARG MYSQL_USER -ENV MYSQL_USER ${MYSQL_USER:-'dummy_foo'} +ENV MYSQL_USER ${MYSQL_USER:-'maria'} # Optional ARG MYSQL_PASSWORD -ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} +ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'maria-abc'} # Optional -ENV MYSQL_ALLOW_EMPTY_PASSWORD=false - -COPY mariadb.ans . -RUN cat mariadb.ans +ARG MYSQL_BIND_ADDRESS +ENV MYSQL_BIND_ADDRESS ${MYSQL_BIND_ADDRESS:-0.0.0.0} # The MariaDB/MySQL tools read configuration files in the following order: -# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, -# 2. "/etc/mysql/conf.d/*.cnf" to set global options. -# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. -# 4. "~/.my.cnf" to set user-specific options. +# 1. "/etc/mysql/my.cnf" to set global defaults, +# 2. "/etc/mysql/conf.d/my.cnf" to set server options. +# 3. "~/.my.cnf" User COPY conf.d/my.cnf /etc/mysql/conf.d/my.cnf -COPY mariadb.conf.d/my.cnf /etc/mysql/mariadb.conf.d/my.cnf -RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_HOST}/" /etc/mysql/conf.d/my.cnf +RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_BIND_ADDRESS}/" /etc/mysql/conf.d/my.cnf + +RUN apt update && apt install -y \ + expect \ + # auth_ed25519 support package + libmariadbclient18 \ + \ + && echo "**** cleanup ****" && \ + rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* -RUN apt update && apt install -y expect +COPY mysql_secure_shell . +RUN chmod 1755 mysql_secure_shell +RUN ./mysql_secure_shell -COPY mysql_secure_shell /usr/local/bin -RUN chmod 1755 /usr/local/bin/mysql_secure_shell -RUN mysql_secure_shell +RUN echo "***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}..." \ + && echo "GRANT ALL PRIVILEGES ON *.* TO CURRENT USER WITH GRANT OPTION;" | tee -a p.sql \ + && echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" | tee -a p.sql \ + && mkdir -p /config/initdb.d/ && mv p.sql /config/initdb.d/patch.sql + +COPY mariadb.ans . +RUN cat mariadb.ans diff --git a/mysqldb/Dockerfile.x86_64 b/mysqldb/Dockerfile.x86_64 index a60ce1cbb..fcb5d1df2 100644 --- a/mysqldb/Dockerfile.x86_64 +++ b/mysqldb/Dockerfile.x86_64 @@ -10,37 +10,50 @@ ENV PUID ${PUID:-0} ARG PGID ENV PGID ${PGID:-0} ARG MYSQL_ROOT_PASSWORD -ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'foo_pass'} -# bind-address = "127.0.0.1" > conf.d/my.cnf +ENV MYSQL_ROOT_PASSWORD ${MYSQL_ROOT_PASSWORD:-'mariadb'} +# bind-address = '127.0.0.1' > conf.d/my.cnf ARG MYSQL_HOST -ENV MYSQL_HOST ${MYSQL_HOST:-127.0.0.1} +ENV MYSQL_HOST ${MYSQL_HOST:-'localhost'} ENV TZ ${TZ:-'Europe/Paris'} # Optional ARG MYSQL_DATABASE -ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'foo_db'} +ENV MYSQL_DATABASE ${MYSQL_DATABASE:-'aria_db'} # Optional ARG MYSQL_USER -ENV MYSQL_USER ${MYSQL_USER:-'dummy_foo'} +ENV MYSQL_USER ${MYSQL_USER:-'maria'} # Optional ARG MYSQL_PASSWORD -ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'foo_pass_test'} +ENV MYSQL_PASSWORD ${MYSQL_PASSWORD:-'maria-abc'} # Optional -ENV MYSQL_ALLOW_EMPTY_PASSWORD=false - -COPY mariadb.ans . -RUN cat mariadb.ans +ARG MYSQL_BIND_ADDRESS +ENV MYSQL_BIND_ADDRESS ${MYSQL_BIND_ADDRESS:-0.0.0.0} # The MariaDB/MySQL tools read configuration files in the following order: -# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults, -# 2. "/etc/mysql/conf.d/*.cnf" to set global options. -# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options. -# 4. "~/.my.cnf" to set user-specific options. +# 1. "/etc/mysql/my.cnf" to set global defaults, +# 2. "/etc/mysql/conf.d/my.cnf" to set server options. +# 3. "~/.my.cnf" User COPY conf.d/my.cnf /etc/mysql/conf.d/my.cnf -COPY mariadb.conf.d/my.cnf /etc/mysql/mariadb.conf.d/my.cnf -RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_HOST}/" /etc/mysql/conf.d/my.cnf +RUN sed -i.bind "/bind-address/s/=.*$/= ${MYSQL_BIND_ADDRESS}/" /etc/mysql/conf.d/my.cnf + +RUN apt update && apt install -y \ + expect \ + # auth_ed25519 support package + libmariadbclient18 \ + \ + && echo "**** cleanup ****" && \ + rm -rf \ + /tmp/* \ + /var/lib/apt/lists/* \ + /var/tmp/* -RUN apt update && apt install -y expect +COPY mysql_secure_shell . +RUN chmod 1755 mysql_secure_shell +RUN ./mysql_secure_shell -COPY mysql_secure_shell /usr/local/bin -RUN chmod 1755 /usr/local/bin/mysql_secure_shell -RUN mysql_secure_shell +RUN echo "***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}..." \ + && echo "GRANT ALL PRIVILEGES ON *.* TO CURRENT USER WITH GRANT OPTION;" | tee -a p.sql \ + && echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" | tee -a p.sql \ + && mkdir -p /config/initdb.d/ && mv p.sql /config/initdb.d/patch.sql + +COPY mariadb.ans . +RUN cat mariadb.ans diff --git a/mysqldb/conf.d/my.cnf b/mysqldb/conf.d/my.cnf index e5705ba73..987f5d0f6 100644 --- a/mysqldb/conf.d/my.cnf +++ b/mysqldb/conf.d/my.cnf @@ -2,14 +2,16 @@ collation-server = utf8_unicode_ci init-connect="SET NAMES utf8" character-set-server = utf8 -innodb_flush_log_at_trx_commit=2 -sync_binlog=0 -innodb_use_native_aio=0 +# TCP Socket settings (making 127.0.0.1 work) +port = 3306 +bind-address = 127.0.0.1 # Unix socket settings (making localhost work) user = root pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock -# TCP Socket settings (making 127.0.0.1 work) -port = 3306 -bind-address = 127.0.0.1 +[mariadb] +### Optional migrate-database.sh --enable-authentication-plugin +### CREATE USER username@hostname IDENTIFIED VIA ed25519 USING PASSWORD('secret'); +# plugin_load_add = auth_ed25519 +unix_socket = ON diff --git a/mysqldb/mariadb.ans b/mysqldb/mariadb.ans index 710e13963..3325e595d 100644 --- a/mysqldb/mariadb.ans +++ b/mysqldb/mariadb.ans @@ -1,4 +1,9 @@ - + *---------------------------* + | MariaDB `mysqld --version`| + *-----------------------\ /-* + V + +[38;5;46;48;5;235m ********#**** **@@@@((@@@@(@@@* **@@@@@/*%@@/*&/@* diff --git a/mysqldb/mariadb.conf.d/my.cnf b/mysqldb/mariadb.conf.d/my.cnf deleted file mode 100644 index a43b1cdf8..000000000 --- a/mysqldb/mariadb.conf.d/my.cnf +++ /dev/null @@ -1,4 +0,0 @@ -[mariadb] -# authentication plugin -#CREATE USER username@hostname IDENTIFIED VIA ed25519 USING PASSWORD('secret'); -plugin_load_add = auth_ed25519 diff --git a/test-cake.sh b/test-cake.sh index d1c0c03d4..7b92c708a 100755 --- a/test-cake.sh +++ b/test-cake.sh @@ -4,9 +4,9 @@ source ./Scripts/lib/test/parsing.sh test=("test_parse_and_export" "test_parse_sql_password" "test_arg_exists" "test_arg_trim") for t in "${test[@]}"; do printf "TEST CASES : %s\n" "$t" && eval "$t"; done; sleep 5 bootargs="" -migrate="-u -i --enable-authentication-plugin" +migrate="-i -u --connection=test" saved=("$@") -config_args="-c -h -p pass -s word --development --connection=test" +config_args="-c -h -p pass -s word" config_work_dir="" usage=("" \ "${cyan}Notice:${nc}The test script." \ @@ -23,16 +23,12 @@ usage=("" \ while [[ "$#" > 0 ]]; do case $1 in --travis ) #; Test values - export DB="Mysql" - export COLLECT_COVERAGE="false" export TRAVIS_OS_NAME="osx" export TRAVIS_PHP_VERSION=$(php -v | grep -E "[5-7]\.\\d+\.\\d+" | cut -d " " -f 2 | cut -c 1-3) # Abort tests - exit 0;; + ;; --circle ) - #; Test values - export DB="Mysql" - export COLLECT_COVERAGE="false";; + ;; --cov ) export COLLECT_COVERAGE=true;; -[hH]*|--help ) @@ -56,7 +52,8 @@ while [[ "$#" > 0 ]]; do case $1 in ;; --docker ) config_args="--docker ${config_args}" - bootargs="--docker ${bootargs}";; + bootargs="--docker ${bootargs}" + ;; --socket ) migrate="-Y ${migrate}";; *) echo "Unknown parameter, passed $0: $1"; exit 1;; From 101eaedc27b787a6ad17f31a58e52e98046d1a3a Mon Sep 17 00:00:00 2001 From: Tiana Rakoto Arimanana <5566338+b23prodtm@users.noreply.github.com> Date: Wed, 6 May 2020 18:27:29 +0200 Subject: [PATCH 4/5] Fixes: ***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}... --- mysqldb/Dockerfile.armhf | 2 +- mysqldb/Dockerfile.template | 2 +- mysqldb/Dockerfile.x86_64 | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mysqldb/Dockerfile.armhf b/mysqldb/Dockerfile.armhf index f0701ff56..a82a3dead 100644 --- a/mysqldb/Dockerfile.armhf +++ b/mysqldb/Dockerfile.armhf @@ -51,7 +51,7 @@ RUN chmod 1755 mysql_secure_shell RUN ./mysql_secure_shell RUN echo "***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}..." \ - && echo "GRANT ALL PRIVILEGES ON *.* TO CURRENT USER WITH GRANT OPTION;" | tee -a p.sql \ + && echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'% WITH GRANT OPTION;" | tee -a p.sql \ && echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" | tee -a p.sql \ && mkdir -p /config/initdb.d/ && mv p.sql /config/initdb.d/patch.sql diff --git a/mysqldb/Dockerfile.template b/mysqldb/Dockerfile.template index 8e7c4ca6d..0228abc0c 100644 --- a/mysqldb/Dockerfile.template +++ b/mysqldb/Dockerfile.template @@ -51,7 +51,7 @@ RUN chmod 1755 mysql_secure_shell RUN ./mysql_secure_shell RUN echo "***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}..." \ - && echo "GRANT ALL PRIVILEGES ON *.* TO CURRENT USER WITH GRANT OPTION;" | tee -a p.sql \ + && echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'% WITH GRANT OPTION;" | tee -a p.sql \ && echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" | tee -a p.sql \ && mkdir -p /config/initdb.d/ && mv p.sql /config/initdb.d/patch.sql diff --git a/mysqldb/Dockerfile.x86_64 b/mysqldb/Dockerfile.x86_64 index fcb5d1df2..2d0a034bb 100644 --- a/mysqldb/Dockerfile.x86_64 +++ b/mysqldb/Dockerfile.x86_64 @@ -51,9 +51,9 @@ RUN chmod 1755 mysql_secure_shell RUN ./mysql_secure_shell RUN echo "***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}..." \ - && echo "GRANT ALL PRIVILEGES ON *.* TO CURRENT USER WITH GRANT OPTION;" | tee -a p.sql \ + && echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'% WITH GRANT OPTION;" | tee -a p.sql \ && echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" | tee -a p.sql \ && mkdir -p /config/initdb.d/ && mv p.sql /config/initdb.d/patch.sql - + COPY mariadb.ans . RUN cat mariadb.ans From 4eb179191893ef3aa2f57b953d26ce1d5723981b Mon Sep 17 00:00:00 2001 From: Tiana Rakoto Arimanana <5566338+b23prodtm@users.noreply.github.com> Date: Wed, 6 May 2020 22:19:33 +0200 Subject: [PATCH 5/5] Fixes: Mysql Connection Error: 1 Fixes: Docker socket test (WIP) --- .circleci/config.yml | 1 + Dockerfile.armhf | 4 ++-- Scripts/config_app_database.sh | 25 +++++++++------------- Scripts/fooargs.sh | 4 ++-- Scripts/start_daemon.sh | 6 ++++-- configure.sh | 2 +- deployment/images/primary/Dockerfile.armhf | 4 ++-- migrate-database.sh | 21 +++++++++++------- mysqldb/Dockerfile.x86_64 | 2 +- mysqldb/conf.d/my.cnf | 2 +- start-cake.sh | 10 ++++----- test-cake.sh | 6 ++++-- 12 files changed, 46 insertions(+), 41 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d29cdc133..111a83f21 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,6 +38,7 @@ jobs: apk update \ && apk add \ php7-session \ + mariadb-connector-c \ && apk del build-base \ && rm -rf /var/cache/apk/* - run: diff --git a/Dockerfile.armhf b/Dockerfile.armhf index 84da88710..9d43ff8d0 100644 --- a/Dockerfile.armhf +++ b/Dockerfile.armhf @@ -48,7 +48,7 @@ ENV SERVER_NAME ${SERVER_NAME:-'localhost.local'} # Use the default production configuration #COPY $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini -RUN [ "cross-build-start" ] +# RUN [ "cross-build-start" ] RUN install_packages \ git \ ssh \ @@ -151,6 +151,6 @@ WORKDIR /var/www/html/ RUN git submodule sync && git submodule update --init RUN ./configure.sh --openshift -c -h -p pass -s word --development -RUN [ "cross-build-end" ] +# RUN [ "cross-build-end" ] ENTRYPOINT [ "/bin/bash", "-c", "./migrate-database.sh -u -o -i --test-sql-password=${MYSQL_PASSWORD}"] CMD [ "apache2 -D FOREGROUND" ] diff --git a/Scripts/config_app_database.sh b/Scripts/config_app_database.sh index 44f178db6..a4afc8960 100755 --- a/Scripts/config_app_database.sh +++ b/Scripts/config_app_database.sh @@ -25,20 +25,16 @@ while [[ "$#" > 0 ]]; do case $1 in source ./Scripts/cp_bkp_old.sh $wd $dbfile "database.php" ;; -[yY]*) - if [ $docker 2> /dev/null ]; then - docker exec ${MARIADB_SHORT_NAME} "mkdir -p /var/run/mysqld && ln -vs /tmp/mysqld.sock /var/run/mysqld/mysqld.sock" - else - if [ $(which mysql) 2> /dev/null ]; then - mysql --version - #; symlink mysql socket with php - echo "Please allow the super-user to link mysql socket to php ..." - mkdir -p /var/run/mysqld - if [ -h /var/run/mysqld/mysqld.sock ]; then - ls -al /var/run/mysqld/mysqld.sock - else - ln -vs /tmp/mysqld.sock /var/run/mysqld/mysqld.sock - fi - fi + if [ $(which mysql) 2> /dev/null ]; then + mysql --version + fi + #; symlink mysql socket with php + echo "Please allow the super-user to link mysql socket to php ..." + mkdir -p /var/run/mysqld + if [ -h /var/run/mysqld/mysqld.sock ]; then + ls -al /var/run/mysqld/mysqld.sock + else + ln -vsf /tmp/mysqld.sock /var/run/mysqld/mysqld.sock fi;; *) ;; @@ -46,7 +42,6 @@ esac; shift; done if [ ! $docker 2> /dev/null ]; then if [ $(which mysql) 2> /dev/null ] && [ ! -h /var/run/mysqld/mysqld.sock ]; then slogger -st $0 "${orange}Warning:${nc}/var/run/mysqld/mysqld.sock symlink not found." - export -p | grep MYSQL_ & else slogger -st $0 "${green}Notice: mysqld.sock symlink was found.${nc}" fi diff --git a/Scripts/fooargs.sh b/Scripts/fooargs.sh index 93031f0c3..681a2be28 100755 --- a/Scripts/fooargs.sh +++ b/Scripts/fooargs.sh @@ -29,8 +29,8 @@ incFOO_ARGS=${incFOO_ARGS:-0}; if [ $incFOO_ARGS -eq 0 ]; then # $ .circleci/build.sh # if [ $docker 2> /dev/null ]; then - export MYSQL_HOST=127.0.0.1 - export TEST_PGSQL_SERVICE_HOST=127.0.0.1 + export MYSQL_HOST=${MYSQL_HOST:-'127.0.0.1'} + export TEST_PGSQL_SERVICE_HOST=${MYSQL_HOST:-'127.0.0.1'} fi export MYSQL_HOST=${MYSQL_HOST:-'localhost'} export MYSQL_TCP_PORT=${MYSQL_TCP_PORT:-'3306'} diff --git a/Scripts/start_daemon.sh b/Scripts/start_daemon.sh index 9bd7de66c..f5314325e 100755 --- a/Scripts/start_daemon.sh +++ b/Scripts/start_daemon.sh @@ -27,12 +27,14 @@ if [ $docker 2> /dev/null ]; then fi docker rm -f $maria >> $LOG 2>&1 || true slogger -st $0 "Container $MARIADB_SHORT_NAME 's started up..." + socket=$TOPDIR/mysqldb/config/mysqld && [ -h /var/run/mysqld/mysqld.sock ] \ + && ln -vsf /var/run/mysqld/mysqld.sock $socket/mysqld.sock docker run --name $MARIADB_SHORT_NAME -id \ --env-file common.env --env-file .env \ -e PUID=$(id -u $USER) -e PGID=$(id -g $USER) \ - -h $MYSQL_HOST --publish $MYSQL_TCP_PORT:$MYSQL_TCP_PORT \ + -h ${MYSQL_HOST} --publish $MYSQL_TCP_PORT:$MYSQL_TCP_PORT \ -v $TOPDIR/mysqldb/config:/config \ - -v $TOPDIR/mysqldb/mysqld:/var/run/mysqld \ + -v $socket:/var/run/mysqld/ \ ${MARIADB_CONT_NAME} >> $LOG 2>&1 if [ $? = 0 ]; then slogger -st $0 "Started docker --name=${MARIADB_SHORT_NAME} ref: $(docker ps -q -a -f "name=maria") host: $MYSQL_HOST}" diff --git a/configure.sh b/configure.sh index 6ab9969fd..00d4e78a7 100755 --- a/configure.sh +++ b/configure.sh @@ -46,7 +46,7 @@ while [[ "$#" > 0 ]]; do case $1 in #; [[-d|--mig-database] [-u]] argument fixes up : Error: Database connection "Mysql" is missing, or could not be created. shell_prompt "./migrate-database.sh ${docker} ${openshift} ${*:2}" "${cyan}Step 3. Migrate database\n${nc}" "-Y" break;; - -[sS]*|-[pP]*|-[fF]*|-[tT]*|--connection* ) + -[sS]*|-[pP]*|-[fF]*) #; void --hash password known args OPTIND=1 if [[ "$#" > 1 ]]; then diff --git a/deployment/images/primary/Dockerfile.armhf b/deployment/images/primary/Dockerfile.armhf index be843db1e..e32c39f93 100644 --- a/deployment/images/primary/Dockerfile.armhf +++ b/deployment/images/primary/Dockerfile.armhf @@ -2,7 +2,7 @@ # Source DockerFile: https://github.com/ulsmith/rpi-raspbian-apache-php/blob/master/Dockerfile # FROM balenalib/raspberrypi3-debian:build -RUN [ "cross-build-start" ] +# RUN [ "cross-build-start" ] ARG PHP_LIB ENV PHP_LIB ${PHP_LIB:-7.2} @@ -48,7 +48,7 @@ RUN a2enmod php${PHP_LIB} && a2enmod rewrite COPY conf/000-default.conf /etc/apache2/conf-available/000-default.conf RUN chown -R www-data:www-data /var/www/html -RUN [ "cross-build-end" ] +# RUN [ "cross-build-end" ] EXPOSE 80 CMD [ "apache2 -D FOREGROUND" ] diff --git a/migrate-database.sh b/migrate-database.sh index 1c2307f01..98c7dd043 100755 --- a/migrate-database.sh +++ b/migrate-database.sh @@ -32,7 +32,7 @@ usage=("" \ " --testunitbase=" \ " Exports TEST_DATABASE_NAME" \ " --enable-authentication-plugin" \ -" Enables https://mariadb.com/kb/en/authentication-plugin-ed25519/" \ +" Disables https://mariadb.com/kb/en/authentication-plugin-ed25519/" \ " -v, --verbose" \ " Outputs more debug information" \ " -h, --help Displays this help" \ @@ -46,7 +46,6 @@ config_app_checked="-Y" test_checked=0 update_checked=0 import_identities=0 -identities=app/Config/database.sql saved=("$@") authentication_plugin=0 mysql_host="%" @@ -54,6 +53,7 @@ ck_args="--connection=default" MARIADB_SHORT_NAME=$(echo $SECONDARY_HUB | awk -F/ '{ print $2 }' | awk -F: '{ print $1 }') while [[ "$#" > 0 ]]; do case "$1" in --enable-authentication-plugin*) + slogger -st $0 "Enabled auth_ed25519 plugin..." authentication_plugin=1;; --docker ) bash -c "./Scripts/start_daemon.sh ${docker}" @@ -86,7 +86,6 @@ while [[ "$#" > 0 ]]; do case "$1" in shift $((OPTIND -1)) ;; -[vV]*|--verbose ) - [ -f $identities ] && cat $identities # Reset passed args (shift reset) text=("" \ "Passed params : $0 ${saved[*]}" \ @@ -153,11 +152,16 @@ if [[ $import_identities -eq 1 ]]; then "-e \"alter user '${DATABASE_USER}'@'${mysql_host}' ${identifiedby};\"" \ "-e \"grant all PRIVILEGES on *.* to '${DATABASE_USER}'@'${mysql_host}' WITH GRANT OPTION;\"" \ "-e \"create database if not exists ${MYSQL_DATABASE} default character set='utf8' default collate='utf8_bin';\"" \ +"-e \"create database if not exists ${TEST_DATABASE_NAME};\"" \ +"-e \"create database if not exists ${TEST_DATABASE_NAME}2;\"" \ +"-e \"create database if not exists ${TEST_DATABASE_NAME}3;\"" \ # enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: \ # "-e \"FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;\"" \ -"-e \"select * from user where user='${DATABASE_USER}';\"" \ +"-e \"select plugin from user where user='${DATABASE_USER}';\"" \ +"-e \"show databases;\"" \ "") slogger -st $0 "Forked script to keep hidden table user secrets..." + password="" if [ ! -z ${MYSQL_ROOT_PASSWORD:-''} ]; then password="--password=${MYSQL_ROOT_PASSWORD}" fi @@ -181,16 +185,17 @@ if [[ $import_identities -eq 1 ]]; then "-e \"create user if not exists '${MYSQL_USER}'@'${mysql_host}' ${identifiedby};\"" \ "-e \"alter user '${MYSQL_USER}'@'${mysql_host}' ${identifiedby};\"" \ "-e \"grant all PRIVILEGES on ${MYSQL_DATABASE}.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ -"-e \"create database if not exists ${TEST_DATABASE_NAME};\"" \ -"-e \"create database if not exists ${TEST_DATABASE_NAME}2;\"" \ -"-e \"create database if not exists ${TEST_DATABASE_NAME}3;\"" \ "-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ "-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}2.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ "-e \"grant all PRIVILEGES on ${TEST_DATABASE_NAME}3.* to '${MYSQL_USER}'@'${mysql_host}';\"" \ # enable failed-login tracking, such that three consecutive incorrect passwords cause temporary account locking for two days: \ # "-e \"FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;\"" \ -"-e \"select * from user where user='${MYSQL_USER}';\"" \ +"-e \"select plugin from user where user='${MYSQL_USER}';\"" \ "") + password="" + if [ ! -z ${MYSQL_ROOT_PASSWORD:-''} ]; then + password="--password=${MYSQL_ROOT_PASSWORD}" + fi shell_prompt "exec ${sql_connect} ${sql_connect_test_host} -u ${DATABASE_USER} ${password} \ ${args[*]} >> $LOG 2>&1" "Import test identities" "$prompt" \ && export MYSQL_PASSWORD=${set_MYSQL_PASSWORD} diff --git a/mysqldb/Dockerfile.x86_64 b/mysqldb/Dockerfile.x86_64 index 2d0a034bb..265790fce 100644 --- a/mysqldb/Dockerfile.x86_64 +++ b/mysqldb/Dockerfile.x86_64 @@ -54,6 +54,6 @@ RUN echo "***** Fix PASSWORD, PRIVILEGES and CREATE ${MYSQL_USER}..." \ && echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'% WITH GRANT OPTION;" | tee -a p.sql \ && echo "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';" | tee -a p.sql \ && mkdir -p /config/initdb.d/ && mv p.sql /config/initdb.d/patch.sql - + COPY mariadb.ans . RUN cat mariadb.ans diff --git a/mysqldb/conf.d/my.cnf b/mysqldb/conf.d/my.cnf index 987f5d0f6..a2cfeab53 100644 --- a/mysqldb/conf.d/my.cnf +++ b/mysqldb/conf.d/my.cnf @@ -13,5 +13,5 @@ socket = /var/run/mysqld/mysqld.sock [mariadb] ### Optional migrate-database.sh --enable-authentication-plugin ### CREATE USER username@hostname IDENTIFIED VIA ed25519 USING PASSWORD('secret'); -# plugin_load_add = auth_ed25519 +plugin_load_add = auth_ed25519 unix_socket = ON diff --git a/start-cake.sh b/start-cake.sh index 82f3e41bd..25b0b2a49 100755 --- a/start-cake.sh +++ b/start-cake.sh @@ -2,7 +2,7 @@ set -e source ./Scripts/lib/parsing.sh source ./Scripts/lib/shell_prompt.sh -command="server -p 8000 -H 0.0.0.0" +command="--docker server -p 8000 -H 0.0.0.0" saved=("$@") export COLLECT_COVERAGE="false" usage=("" \ @@ -14,7 +14,7 @@ usage=("" \ " E.g. $0 -c server --help" \ " Default command is " \ " lib/Cake/Console/cake server -p 8000" \ -" --docker Startup Docker Image DATABASE" \ +" --disable-docker Don't start Docker Image DATABASE" \ "") while [[ "$#" > 0 ]]; do case $1 in --help ) @@ -33,11 +33,11 @@ while [[ "$#" > 0 ]]; do case $1 in shift $((OPTIND -1)) ;; -[cC]*) - command="${command} ${*:2}" + command="${*:2}" parse_and_export "p" "CAKE_TCP_PORT" "specify -p " "$@" break;; - --docker ) - command="--docker ${command}" + --disable-docker ) + command=$(parse_arg_trim "--docker" $command) ;; *);; esac; shift; done diff --git a/test-cake.sh b/test-cake.sh index 7b92c708a..010acc8ca 100755 --- a/test-cake.sh +++ b/test-cake.sh @@ -3,10 +3,10 @@ set -e source ./Scripts/lib/test/parsing.sh test=("test_parse_and_export" "test_parse_sql_password" "test_arg_exists" "test_arg_trim") for t in "${test[@]}"; do printf "TEST CASES : %s\n" "$t" && eval "$t"; done; sleep 5 -bootargs="" +bootargs="--docker" migrate="-i -u --connection=test" saved=("$@") -config_args="-c -h -p pass -s word" +config_args="-c -h -p pass -s word --development" config_work_dir="" usage=("" \ "${cyan}Notice:${nc}The test script." \ @@ -28,6 +28,7 @@ while [[ "$#" > 0 ]]; do case $1 in # Abort tests ;; --circle ) + bootargs=$(parse_arg_trim "--docker" $bootargs) ;; --cov ) export COLLECT_COVERAGE=true;; @@ -47,6 +48,7 @@ while [[ "$#" > 0 ]]; do case $1 in bootargs="-v ${bootargs}" echo "Passed params : $0 ${saved[*]}";; -[oO]*|--openshift ) + bootargs=$(parse_arg_trim "--docker" $bootargs) bootargs="${bootargs} --openshift" config_args="--openshift ${config_args}" ;;