Skip to content

Commit 67f3e12

Browse files
committed
Merge branch 'mysql-server' into mysql-labs
Conflicts: 5.5/Dockerfile 5.5/docker-entrypoint.sh 5.6/Dockerfile 5.6/docker-entrypoint.sh 5.7/Dockerfile 5.7/docker-entrypoint.sh
2 parents aec07a7 + 23c46e2 commit 67f3e12

File tree

5 files changed

+131
-43
lines changed

5 files changed

+131
-43
lines changed

5.7/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
FROM oraclelinux:latest
2-
## -- The environment variables set using ENV will persist when a container
3-
## -- is run from the resulting image. -- ##
42

53
ENV MYSQL_VERSION mysql-5.7.7-labs-json-linux-el6-x86_64
64
ENV PATH $PATH:/mysql/bin
@@ -15,7 +13,6 @@ RUN yum install -y libaio wget tar \
1513
&& rm -f /mysql/lib/* || true \
1614
&& strip /mysql/bin/* || true
1715

18-
1916
VOLUME /var/lib/mysql
2017
VOLUME /var/lib/mysql-files
2118

5.7/docker-entrypoint.sh

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
#!/bin/bash
22
set -e
33

4-
get_option () {
5-
local section=$1
6-
local option=$2
7-
local default=$3
8-
ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-)
9-
[ -z $ret ] && ret=$default
10-
echo $ret
11-
}
12-
4+
# if command starts with an option, prepend mysqld
135
if [ "${1:0:1}" = '-' ]; then
146
set -- mysqld "$@"
157
fi
168

179
if [ "$1" = 'mysqld' ]; then
1810
# Get config
19-
DATADIR="$("$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
20-
SOCKET=$(get_option mysqld socket "$DATADIR/mysql.sock")
21-
PIDFILE=$(get_option mysqld pid-file "/var/lib/mysql/mysqld.pid")
11+
DATADIR="$("$@" --verbose --help --innodb-read-only 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')"
2212

2313
if [ ! -d "$DATADIR/mysql" ]; then
2414
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" ]; then
@@ -27,69 +17,82 @@ if [ "$1" = 'mysqld' ]; then
2717
exit 1
2818
fi
2919
mkdir -p /var/lib/mysql-files
30-
if [ ! -d "$DATADIR" ]; then
31-
mkdir -p $DATADIR
32-
fi
20+
mkdir -p "$DATADIR"
3321
chown -R mysql:mysql "$DATADIR"
3422

3523
echo 'Initializing database'
36-
mysqld --initialize-insecure=on --datadir=$DATADIR
24+
mysqld --initialize-insecure=on --user=mysql --datadir="$DATADIR"
3725
echo 'Database initialized'
3826

39-
mysqld --user=mysql --datadir=$DATADIR --skip-networking &
40-
for i in $(seq 30 -1 0); do
41-
[ -S $SOCKET ] && break
27+
mysqld --user=mysql --datadir="$DATADIR" --skip-networking &
28+
pid="$!"
29+
30+
mysql=( mysql --protocol=socket -uroot )
31+
32+
for i in {30..0}; do
33+
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
34+
break
35+
fi
4236
echo 'MySQL init process in progress...'
4337
sleep 1
4438
done
45-
if [ $i = 0 ]; then
39+
if [ "$i" = 0 ]; then
4640
echo >&2 'MySQL init process failed.'
4741
exit 1
4842
fi
4943

50-
# These statements _must_ be on individual lines, and _must_ end with
51-
# semicolons (no line breaks or comments are permitted).
52-
# TODO proper SQL escaping on ALL the things D:
44+
mysql_tzinfo_to_sql /usr/share/zoneinfo | "${mysql[@]}" mysql
5345

54-
tempSqlFile=$(mktemp /tmp/mysql-first-time.XXXXXX.sql)
55-
cat > "$tempSqlFile" <<-EOSQL
46+
"${mysql[@]}" <<-EOSQL
5647
-- What's done in this file shouldn't be replicated
48+
-- or products like mysql-fabric won't work
5749
SET @@SESSION.SQL_LOG_BIN=0;
5850
DELETE FROM mysql.user ;
5951
CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
6052
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
6153
DROP DATABASE IF EXISTS test ;
54+
FLUSH PRIVILEGES ;
6255
EOSQL
56+
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
57+
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
58+
fi
6359

6460
if [ "$MYSQL_DATABASE" ]; then
65-
echo "CREATE DATABASE IF NOT EXISTS \`"$MYSQL_DATABASE"\` ;" >> "$tempSqlFile"
61+
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
62+
mysql+=( "$MYSQL_DATABASE" )
6663
fi
6764

6865
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
69-
echo "CREATE USER '"$MYSQL_USER"'@'%' IDENTIFIED BY '"$MYSQL_PASSWORD"' ;" >> "$tempSqlFile"
66+
echo "CREATE USER '"$MYSQL_USER"'@'%' IDENTIFIED BY '"$MYSQL_PASSWORD"' ;" | "${mysql[@]}"
7067

7168
if [ "$MYSQL_DATABASE" ]; then
72-
echo "GRANT ALL ON \`"$MYSQL_DATABASE"\`.* TO '"$MYSQL_USER"'@'%' ;" >> "$tempSqlFile"
69+
echo "GRANT ALL ON \`"$MYSQL_DATABASE"\`.* TO '"$MYSQL_USER"'@'%' ;" | "${mysql[@]}"
7370
fi
74-
fi
7571

76-
echo 'FLUSH PRIVILEGES ;' >> "$tempSqlFile"
77-
echo "Running init sql script."
78-
mysql -uroot < $tempSqlFile
72+
echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
73+
fi
7974

80-
rm -f $tempSqlFile
81-
kill $(cat $PIDFILE)
82-
for i in $(seq 30 -1 0); do
83-
[ -f "$PIDFILE" ] || break
84-
echo 'MySQL shutdown in progress...'
85-
sleep 1
75+
echo
76+
for f in /docker-entrypoint-initdb.d/*; do
77+
case "$f" in
78+
*.sh) echo "$0: running $f"; . "$f" ;;
79+
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f" && echo ;;
80+
*) echo "$0: ignoring $f" ;;
81+
esac
82+
echo
8683
done
87-
if [ $i = 0 ]; then
88-
echo >&2 'MySQL hangs during init process.'
84+
85+
if ! kill -s TERM "$pid" || ! wait "$pid"; then
86+
echo >&2 'MySQL init process failed.'
8987
exit 1
9088
fi
89+
90+
echo
9191
echo 'MySQL init process done. Ready for start up.'
92+
echo
9293
fi
94+
95+
chown -R mysql:mysql "$DATADIR"
9396
fi
9497

9598
exec "$@"

test/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Some simple test scripts to check the image is built and running the correct version. Used during release
2+
Run from the project root directory

test/testbuild.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
VERSION=$1
4+
DIRECTORY=$2
5+
6+
echo "Building image mysql/mysql-server:$VERSION"
7+
docker build -t mysql/mysql-server:$VERSION $DIRECTORY
8+
RES=$?
9+
if [ $RES -eq 0 ];
10+
then
11+
echo "Image built"
12+
else
13+
echo "Image build failed"
14+
exit 0
15+
fi
16+
17+
18+
IMAGELIST=$(docker images | grep $VERSION)
19+
docker rmi "mysql/mysql-server:$VERSION" || :
20+
versionregex="mysql/mysql-server $VERSION"
21+
if [[ $IMAGELIST =~ $versionregex ]];
22+
then
23+
echo "Test passed"
24+
exit 0
25+
else
26+
echo "Test failed. Image not in list"
27+
exit 1
28+
fi
29+
30+

test/testserver.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
VERSION="$1"
4+
SERVERSTART=0
5+
SERVERCONNECT=0
6+
SUCCESS=false
7+
echo "Starting image with MySQL version $VERSION"
8+
docker run -e MYSQL_ROOT_PASSWORD=rot --name=testserver -p 3306:3306 -d mysql/mysql-server:$VERSION
9+
RES=$?
10+
if [ ! $RES = 0 ]; then
11+
echo "Server start failed with error code $RES"
12+
else
13+
SERVERSTART=1
14+
fi
15+
echo "Connecting to server..."
16+
if [ $SERVERSTART ];
17+
then
18+
for i in $(seq 30 -1 0); do
19+
OUTPUT="$(mysql -uroot -prot -h127.0.0.1 -P3306 < 'test/sql_version.sql')"
20+
RES=$?
21+
if [ $RES -eq 0 ]; then
22+
SERVERCONNECT=1
23+
break
24+
fi
25+
sleep 1
26+
done
27+
if [ $i = 0 ]; then
28+
echo >&2 "Unable to connect to server."
29+
fi
30+
fi
31+
32+
if [ $SERVERCONNECT ];
33+
then
34+
versionregex="version $VERSION"
35+
if [[ $OUTPUT =~ $versionregex ]];
36+
then
37+
echo "Version check ok"
38+
SUCCESS=true
39+
else
40+
echo "Expected to see version $VERSION. Actual output: $OUTPUT"
41+
fi
42+
fi
43+
44+
echo "Running cleanup."
45+
docker kill testserver
46+
docker rm testserver
47+
echo "Cleanup complete."
48+
if [ $SUCCESS == true ];
49+
then
50+
echo "Test passed"
51+
exit 0
52+
else
53+
echo "Test failed"
54+
exit 1
55+
fi
56+

0 commit comments

Comments
 (0)