Skip to content

Commit

Permalink
Fixes: SQL connection
Browse files Browse the repository at this point in the history
  • Loading branch information
b23prodtm committed Apr 30, 2020
1 parent f06aeef commit 736285c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Scripts/start_daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ if [ $docker 2> /dev/null ]; then
else
slogger -st $0 "Container $container 's started up..."
maria=$(docker rm -f $maria >> $LOG 2>&1)
maria=$(docker run --name maria -d -h db --env-file common.env ${container} >> $LOG 2>&1)
maria=$(docker run --name maria -d --publish $MYSQL_TCP_PORT:$MYSQL_TCP_PORT --env-file common.env ${container} 2>> $LOG)
fi
if [ $? = 0 ]; then
slogger -st $0 "Started docker container --name maria, ref: ${maria}"
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}
[ $? = 1 ] && slogger -st $0 "${red}Failed waiting for Mysql${nc}"
fi
Expand Down
4 changes: 2 additions & 2 deletions app/Config/database.cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ public function __construct() {
$datasource = getenv('DATABASE_ENGINE') ? 'Database/' . ucfirst(getenv('DATABASE_ENGINE')) : FALSE;
$test = array(
'host' => getenv(strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_HOST"),
'port' => getenv(strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_PORT"),
'port' => getenv(strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_TCP_PORT"),
'login' => getenv('MYSQL_USER'),
'password' => getenv('MYSQL_PASSWORD'),
'database' => getenv('TEST_DATABASE_NAME'),
'datasource' => $datasource ? $this->test['datasource'] : $datasource
);
$default = array(
'host' => getenv(strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_HOST"),
'port' => getenv(strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_PORT"),
'port' => getenv(strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_TCP_PORT"),
'login' => getenv("DATABASE_USER"),
'password' => getenv("MYSQL_ROOT_PASSWORD"),
'database' => getenv("MYSQL_DATABASE"),
Expand Down
2 changes: 1 addition & 1 deletion app/webroot/php_cms
Submodule php_cms updated from 9502a7 to a71eb8
4 changes: 2 additions & 2 deletions docker-compose.x86_64
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
MYSQL_ROOT_PASSWORD: "foo_pass"
MYSQL_USER: "dummy_foo"
MYSQL_PASSWORD: "foo_pass_test"
image: betothreeprod/mariadb-intel-nuc
image: betothreeprod/mariadb-raspberrypi3
volumes:
- db-data:/config
- db-socket:/var/run/mysqld
Expand All @@ -37,7 +37,7 @@ services:
MYSQL_ROOT_PASSWORD: "foo_pass"
MYSQL_USER: "dummy_foo"
MYSQL_PASSWORD: "foo_pass_test"
image: betothreeprod/myphpcms-intel-nuc
image: betothreeprod/myphpcms-raspberrypi3
privileged: true
labels:
io.balena.features.dbus: "1"
Expand Down
36 changes: 23 additions & 13 deletions migrate-database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ while [[ "$#" > 0 ]]; do case "$1" in
;;
--docker )
bash -c "./Scripts/start_daemon.sh ${docker}"
sql_connect="docker exec maria mysql"
sql_connect="docker exec -i maria mysql"
sql_connect_host=""
sql_connect_test_host=""
slogger -st $0 "${sql_connect} ... ";;
Expand All @@ -79,10 +79,14 @@ while [[ "$#" > 0 ]]; do case "$1" in
import_identities=1
;;
--sql-password*)
OPTIND=1
parse_sql_password "set_DATABASE_PASSWORD" "Altering ${DATABASE_USER} password" "$@"
shift $((OPTIND -1))
;;
--test-sql-password*)
OPTIND=1
parse_sql_password "set_MYSQL_PASSWORD" "Altering ${MYSQL_USER} password" "$@"
shift $((OPTIND -1))
;;
-[vV]*|--verbose )
[ -f $identities ] && cat $identities
Expand All @@ -99,30 +103,36 @@ $(export -p | grep "DATABASE\|MYSQL") \
exit 0;;
-[oO]*|--openshift );;
-[pP]* )
OPTIND=1
parse_sql_password "MYSQL_ROOT_PASSWORD" "current ${DATABASE_USER} password" "$@"
shift
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
shift $((OPTIND -1))
export set_MYSQL_PASSWORD=$MYSQL_PASSWORD
ck_args="--connection=test"
;;
-[dD]*|--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))
;;
--testunitbase*)
# Transform long options to short ones
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;;
esac
Expand Down Expand Up @@ -150,15 +160,15 @@ if [[ $import_identities -eq 1 ]]; then
"")
slogger -st $0 "Forked script to keep hidden table user secrets..."
password=${MYSQL_ROOT_PASSWORD:-''}
if [ $password != '' ]; then
prompt=""
prompt=""
if [ $password = '' ]; then
slogger -st $0 "\r${orange}WARNING: Using blank password for ${DATABASE_USER} !!${nc}"
else
prompt="-Y"
password="--password=${password}"
fi
shell_prompt "exec ${sql_connect} ${sql_connect_host} ${args[@]} \
-u ${DATABASE_USER} ${password} >> $LOG 2>&1" "Import default identities" "$prompt"\
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}
slogger -st $0 "\r${red}WARNING: You will modify SQL ${MYSQL_USER} password !${nc}"
#; $identities file contents
Expand All @@ -177,15 +187,15 @@ if [[ $import_identities -eq 1 ]]; then
# "-e FAILED_LOGIN_ATTEMPTS 3 PASSWORD_LOCK_TIME 2;" \
"")
password=${MYSQL_ROOT_PASSWORD:-''}
if [ $password != '' ]; then
prompt=""
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} ${args[@]} \
-u ${DATABASE_USER} ${password} >> $LOG 2>&1" "Import test identities" "$prompt" \
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}
check_log $LOG
fi
Expand Down Expand Up @@ -217,8 +227,8 @@ if [[ $test_checked -eq 1 ]]; then
"-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} \
"${args[@]}" -u ${MYSQL_USER} --password=${MYSQL_PASSWORD} -v >> $LOG 2>&1
exec ${sql_connect} ${sql_connect_test_host} -u ${MYSQL_USER} --password=${MYSQL_PASSWORD} \
"${args[@]}" >> $LOG 2>&1
check_log $LOG
cat <<EOF | tee app/Config/database.php
<?php
Expand Down
9 changes: 6 additions & 3 deletions start-cake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ while [[ "$#" > 0 ]]; do case $1 in
printf "%s\n" "${usage[@]}"
exit 0;;
-[pP]*)
OPTIND=1
parse_sql_password "MYSQL_ROOT_PASSWORD" "current ${DATABASE_USER}" "$@"
shift
shift $((OPTIND -1))
;;
-[tT]*)
OPTIND=1
parse_sql_password "MYSQL_PASSWORD" "current ${MYSQL_USER}" "$@"
shift
shift $((OPTIND -1))
;;
-[cC]*)
command=$2
shift; shift; command="${command} $*"
OPTIND=1
parse_and_export "p" "CAKE_TCP_PORT" "specify -p <port>" "$@"
shift
shift $((OPTIND -1))
;;
--docker )
command="--docker ${command}"
Expand Down
6 changes: 4 additions & 2 deletions test-cake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ while [[ "$#" > 0 ]]; do case $1 in
printf "%s\n" "${usage[@]}"
exit 0;;
-[pP]*)
OPTIND=1
parse_sql_password "MYSQL_ROOT_PASSWORD" "user ${DATABASE_USER}" "$@"
shift
shift $((OPTIND -1))
;;
-[tT]*)
OPTIND=1
parse_sql_password "MYSQL_PASSWORD" "test user ${MYSQL_USER}" "$@"
shift
shift $((OPTIND -1))
;;
-[vV]*|--verbose )
set -x
Expand Down

0 comments on commit 736285c

Please sign in to comment.