Skip to content

Commit

Permalink
Add 5.5 and 5.6 to entrypoint templating
Browse files Browse the repository at this point in the history
This requires adding some variables that are replaced when
generating the entrypoint scripts
  • Loading branch information
ltangvald authored and yosifkit committed Sep 18, 2019
1 parent a9e8576 commit 03bdbad
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
37 changes: 29 additions & 8 deletions .template.Debian/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,25 @@ _get_config() {
_start_server() {
local socket=$1; shift
result=0
"$@" --daemonize --skip-networking --socket="${socket}" || result=$?
%%SERVERSTARTUP%%
if [ ! "$result" = "0" ];then
_error "Unable to start server. Status code $result."
fi
}

_wait_for_server() {
local mysql=( "$@" )
for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
break
fi
sleep 1
done
if [ "$i" = 0 ]; then
_error "Unable to start server."
fi
}

_stop_server() {
local passfile=$1
local socket=$2
Expand Down Expand Up @@ -132,7 +145,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
mkdir -p "$DATADIR"

_note "Initializing database"
"$@" --initialize-insecure
%%DATABASEINIT%%
_note "Database initialized"

if command -v mysql_ssl_rsa_setup > /dev/null && [ ! -e "$DATADIR/server-key.pem" ]; then
Expand All @@ -143,11 +156,15 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
fi

SOCKET="$(_get_config 'socket' "$@")"
mysql=( mysql --no-defaults --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
_note "Starting server"
_start_server "${SOCKET}" "$@"
_note "Server started with."
if [ "${MYSQL_MAJOR}" = "5.5" ] || [ "${MYSQL_MAJOR}" = "5.6" ]; then
_note "Waiting for server startup"
_wait_for_server "${mysql[@]}"
fi
_note "Server started."

mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )

if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
# sed is for https://bugs.mysql.com/bug.php?id=20545
Expand Down Expand Up @@ -176,7 +193,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
-- or products like mysql-fabric won't work
SET @@SESSION.SQL_LOG_BIN=0;
ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
%%PASSWORDSET%%
GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION ;
${rootCreate}
DROP DATABASE IF EXISTS test ;
Expand Down Expand Up @@ -219,9 +236,13 @@ EOF
done

if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
"${mysql[@]}" <<-EOSQL
ALTER USER 'root'@'%' PASSWORD EXPIRE;
EOSQL
if [ "${MYSQL_MAJOR}" = "5.5" ]; then
_warn "MySQL 5.5 does not support PASSWORD EXPIRE (required for MYSQL_ONETIME_PASSWORD)"
else
"${mysql[@]}" <<-EOSQL
ALTER USER 'root'@'%' PASSWORD EXPIRE;
EOSQL
fi
fi
_note "Stopping server"
_stop_server "${PASSFILE}" "${SOCKET}"
Expand Down
23 changes: 21 additions & 2 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ declare -A debianVariants=(
#[5.5]='jessie'
)

# Copy entrypoint template
templateVersions=( "5.7 8.0" )
# Templaing
templateVersions=( "5.5 5.6 5.7 8.0" )
declare -A passwordset
passwordset["5.5"]="SET PASSWORD FOR 'root'@'localhost'=PASSWORD('\${MYSQL_ROOT_PASSWORD}');"
passwordset["5.6"]="SET PASSWORD FOR 'root'@'localhost'=PASSWORD('\${MYSQL_ROOT_PASSWORD}');"
passwordset["5.7"]="ALTER USER 'root'@'localhost' IDENTIFIED BY '\${MYSQL_ROOT_PASSWORD}';"
passwordset["8.0"]="ALTER USER 'root'@'localhost' IDENTIFIED BY '\${MYSQL_ROOT_PASSWORD}';"
declare -A database_init
database_init["5.5"]="mysql_install_db --datadir=\"\$DATADIR\" --rpm --basedir=\/usr\/local\/mysql \"\${@:2}\""
database_init["5.6"]="mysql_install_db --user=mysql --datadir=\"\$DATADIR\" --rpm --keep-my-cnf"
database_init["5.7"]="\"\$@\" --initialize-insecure"
database_init["8.0"]="\"\$@\" --initialize-insecure"
declare -A server_startup
server_startup["5.5"]="\"\$@\" --skip-networking --basedir=\/usr\/local\/mysql --socket=\"\${socket}\" \&"
server_startup["5.6"]="\"\$@\" --skip-networking --socket=\"\${socket}\" \&"
server_startup["5.7"]="\"\$@\" --daemonize --skip-networking --socket=\"\${socket}\" || result=$?"
server_startup["8.0"]="\"\$@\" --daemonize --skip-networking --socket=\"\${socket}\" || result=$?"
for version in ${templateVersions}; do
cp ".template.Debian/docker-entrypoint.sh" "${version}/"
sed -e 's/%%PASSWORDSET%%/'"${passwordset["$version"]}"'/g' \
-e 's/%%DATABASEINIT%%/'"${database_init["$version"]}"'/g' \
-e 's/%%SERVERSTARTUP%%/'"${server_startup["$version"]}"'/g' \
.template.Debian/docker-entrypoint.sh > "$version/docker-entrypoint.sh"
done

for version in "${versions[@]}"; do
Expand Down

0 comments on commit 03bdbad

Please sign in to comment.