Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions 5.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ EXPOSE 3306
# to make sure of that.
RUN rpmkeys --import file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 && \
yum -y --setopt=tsflags=nodocs install https://www.softwarecollections.org/en/scls/rhscl/mysql55/epel-7-x86_64/download/rhscl-mysql55-epel-7-x86_64.noarch.rpm && \
yum -y --setopt=tsflags=nodocs install hostname mysql55 && \
yum -y --setopt=tsflags=nodocs install gettext hostname mysql55 && \
yum clean all && \
mkdir -p /var/lib/mysql/data && chown mysql.mysql /var/lib/mysql/data && \
test "$(id mysql)" = "uid=27(mysql) gid=27(mysql) groups=27(mysql)"

COPY run-mysqld.sh /usr/local/bin/
COPY contrib/.bashrc /var/lib/mysql/
COPY contrib/etc /opt/openshift/etc/
COPY contrib /var/lib/mysql/

VOLUME ["/var/lib/mysql/data"]

Expand Down
5 changes: 2 additions & 3 deletions 5.5/Dockerfile.rhel7
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ EXPOSE 3306
# This image must forever use UID 27 for mysql user so our volumes are
# safe in the future. This should *never* change, the last test is there
# to make sure of that.
RUN yum install -y yum-utils hostname && \
RUN yum install -y yum-utils gettext hostname && \
yum-config-manager --enable rhel-server-rhscl-7-rpms && \
yum-config-manager --enable rhel-7-server-optional-rpms && \
yum install -y --setopt=tsflags=nodocs mysql55 && \
Expand All @@ -31,8 +31,7 @@ RUN yum install -y yum-utils hostname && \
test "$(id mysql)" = "uid=27(mysql) gid=27(mysql) groups=27(mysql)"

COPY run-mysqld.sh /usr/local/bin/
COPY contrib/.bashrc /var/lib/mysql/
COPY contrib/etc /opt/openshift/etc/
COPY contrib /var/lib/mysql/

VOLUME ["/var/lib/mysql/data"]

Expand Down
17 changes: 0 additions & 17 deletions 5.5/contrib/etc/my.cnf

This file was deleted.

37 changes: 37 additions & 0 deletions 5.5/contrib/my.cnf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[mysqld]
user = mysql

datadir = ${MYSQL_DATADIR}
basedir = /opt/rh/mysql55/root/usr
plugin-dir = /opt/rh/mysql55/root/usr/lib64/mysql/plugin

general_log = ON

# Disable unix socket
socket =

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links = 0

# http://www.percona.com/blog/2008/05/31/dns-achilles-heel-mysql-installation/
skip_name_resolve

#
# Settings configured by the user
#

# Sets how the table names are stored and compared. Default: 0
lower_case_table_names = ${MYSQL_LOWER_CASE_TABLE_NAMES}

# The maximum permitted number of simultaneous client connections. Default: 151
max_connections = ${MYSQL_MAX_CONNECTIONS}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${MYSQL_MAX_CONNECTIONS:-123} doesn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

envsubst doesn't handle defaulting unfortunately. otherwise this whole thing could be much cleaner.


# The minimum length of the word to be included in a FULLTEXT index. Default: 4
ft_min_word_len = ${MYSQL_FT_MIN_WORD_LEN}

# The maximum length of the word to be included in a FULLTEXT index. Default: 20
ft_max_word_len = ${MYSQL_FT_MAX_WORD_LEN}

# In case the native AIO is broken. Default: 1
# See http://help.directadmin.com/item.php?id=529
innodb_use_native_aio = ${MYSQL_AIO}
41 changes: 34 additions & 7 deletions 5.5/run-mysqld.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ source $HOME/.bashrc
set -eu

# Data directory where MySQL database files live. The data subdirectory is here
# because .bashrc lives in /var/lib/mysql/ and we don't want a volume to
# override it.
MYSQL_DATADIR=/var/lib/mysql/data
MYSQL_DEFAULTS_FILE=/opt/openshift/etc/my.cnf
# because .bashrc and my.cnf both live in /var/lib/mysql/ and we don't want a
# volume to override it.
export MYSQL_DATADIR=/var/lib/mysql/data

# Configuration settings.
export MYSQL_DEFAULTS_FILE=$HOME/my.cnf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the intent here? you later assume the file is really named my.cnf.template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the template has the .template suffix. But the generated file is $MYSQL_DEFAULTS_FILE and the variable is used multiple times as argument to different commands later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it's just not named well... it's the mysql config file, right? it's not the default or template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a defaults file (or option file) in MySQL nomenclature: https://dev.mysql.com/doc/refman/5.5/en/option-file-options.html#option_general_defaults-file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, ok, looks good then! :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bparees yeah, I was also a bit confused about the naming

export MYSQL_LOWER_CASE_TABLE_NAMES=${MYSQL_LOWER_CASE_TABLE_NAMES:-0}
export MYSQL_MAX_CONNECTIONS=${MYSQL_MAX_CONNECTIONS:-151}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than doing this, why not just default the values in the template file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nm, i see envsubst doesn't support defaults.

export MYSQL_FT_MIN_WORD_LEN=${MYSQL_FT_MIN_WORD_LEN:-4}
export MYSQL_FT_MAX_WORD_LEN=${MYSQL_FT_MAX_WORD_LEN:-20}
export MYSQL_AIO=${MYSQL_AIO:-1}

# Be paranoid and stricter than we should be.
# https://dev.mysql.com/doc/refman/5.5/en/identifiers.html
Expand All @@ -26,10 +33,20 @@ function usage() {
echo " \$MYSQL_DATABASE (regex: '$mysql_identifier_regex')"
echo "Optional:"
echo " \$MYSQL_ROOT_PASSWORD (regex: '$mysql_password_regex')"
echo "Settings:"
echo " \$MYSQL_LOWER_CASE_TABLE_NAMES (default: 0)"
echo " \$MYSQL_MAX_CONNECTIONS (default: 151)"
echo " \$MYSQL_FT_MIN_WORD_LEN (default: 4)"
echo " \$MYSQL_FT_MAX_WORD_LEN (default: 20)"
echo " \$MYSQL_AIO (default: 1)"
exit 1
}

function check_env_vars() {
if ! [[ -v MYSQL_USER && -v MYSQL_PASSWORD && -v MYSQL_DATABASE ]]; then
usage
fi

[[ "$MYSQL_USER" =~ $mysql_identifier_regex ]] || usage "Invalid MySQL username"
[ ${#MYSQL_USER} -le 16 ] || usage "MySQL username too long (maximum 16 characters)"
[[ "$MYSQL_PASSWORD" =~ $mysql_password_regex ]] || usage "Invalid password"
Expand Down Expand Up @@ -60,9 +77,7 @@ function wait_for_mysql() {
done
}

if [ "$1" = "mysqld" -a ! -d "$MYSQL_DATADIR/mysql" ]; then

shift
function initialize_database() {
check_env_vars

echo 'Running mysql_install_db'
Expand Down Expand Up @@ -94,6 +109,18 @@ if [ "$1" = "mysqld" -a ! -d "$MYSQL_DATADIR/mysql" ]; then
EOSQL
fi
mysqladmin $admin_flags flush-privileges shutdown
}

# New config is generated every time a container is created.
envsubst < ${MYSQL_DEFAULTS_FILE}.template > $MYSQL_DEFAULTS_FILE

if [ "$1" = "mysqld" ]; then

shift

if [ ! -d "$MYSQL_DATADIR/mysql" ]; then
initialize_database
fi

unset_env_vars

Expand Down
20 changes: 20 additions & 0 deletions 5.5/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ function run_container_creation_tests() {
echo " Success!"
}

function test_config_option() {
local env_var=$1 ; shift
local setting=$1 ; shift
local value=$1 ; shift

# If $value is a string, it needs to be in simple quotes ''.
# If nothing is found, grep returns 1 and test fails.
docker run --rm -e $env_var=${value//\'/} $IMAGE_NAME cat /var/lib/mysql/my.cnf | grep -q "$setting = $value"
}

function run_configuration_tests() {
echo " Testing image configuration settings"
test_config_option MYSQL_LOWER_CASE_TABLE_NAMES lower_case_table_names 1
test_config_option MYSQL_MAX_CONNECTIONS max_connections 1337
test_config_option MYSQL_FT_MIN_WORD_LEN ft_min_word_len 8
test_config_option MYSQL_FT_MAX_WORD_LEN ft_max_word_len 15
echo " Success!"
}

function run_tests() {
local name=$1 ; shift
envs="-e MYSQL_USER=$USER -e MYSQL_PASSWORD=$PASS -e MYSQL_DATABASE=db"
Expand All @@ -165,5 +184,6 @@ function run_tests() {
# Tests.

run_container_creation_tests
run_configuration_tests
USER=user PASS=pass run_tests no_root
USER=user1 PASS=pass1 ROOT_PASS=r00t run_tests root
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ The image recognizes following environment variables that you can set during ini
| `MYSQL_DATABASE` | Database name |
| `MYSQL_ROOT_PASSWORD` | Password for the root user (optional) |

Following environment variables influence MySQL configuration file. They are all optional.

| Variable name | Description | Default
| :------------------------------ | ----------------------------------------------------------------- | -------------------------------
| `MYSQL_LOWER_CASE_TABLE_NAMES` | Sets how the table names are stored and compared | 0
| `MYSQL_MAX_CONNECTIONS` | The maximum permitted number of simultaneous client connections | 151
| `MYSQL_FT_MIN_WORD_LEN` | The minimum length of the word to be included in a FULLTEXT index | 4
| `MYSQL_FT_MAX_WORD_LEN` | The maximum length of the word to be included in a FULLTEXT index | 20
| `MYSQL_AIO` | Controls the `innodb_use_native_aio` setting value in case the native AIO is broken. See http://help.directadmin.com/item.php?id=529 | 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest reviewing v2 mysql cart for variables that might be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I did that, but I'm not sure that's supposed to be part of this effort. I understood we only needed a system in place, we can add variables we'll want later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah actually adding the config settings/env variables to the various DB carts should be part of this effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add all of them?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be a good start... they all exist in the v2 cart because users asked for them over time, so it's likely the popular set.

You can also set following mount points by passing `-v /host:/container` flag to docker.

| Volume mount point | Description |
Expand Down