Skip to content

Commit 00fe6e7

Browse files
committed
Add MySQL 8.0
1 parent a03bccc commit 00fe6e7

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ language: bash
22
services: docker
33

44
env:
5+
- VERSION=8.0
56
- VERSION=5.7
67
- VERSION=5.6
78
- VERSION=5.5

8.0/Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
FROM debian:jessie
2+
3+
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
4+
RUN groupadd -r mysql && useradd -r -g mysql mysql
5+
6+
# add gosu for easy step-down from root
7+
ENV GOSU_VERSION 1.7
8+
RUN set -x \
9+
&& apt-get update && apt-get install -y --no-install-recommends ca-certificates wget && rm -rf /var/lib/apt/lists/* \
10+
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
11+
&& wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
12+
&& export GNUPGHOME="$(mktemp -d)" \
13+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
14+
&& gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
15+
&& rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
16+
&& chmod +x /usr/local/bin/gosu \
17+
&& gosu nobody true \
18+
&& apt-get purge -y --auto-remove ca-certificates wget
19+
20+
RUN mkdir /docker-entrypoint-initdb.d
21+
22+
# FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
23+
# File::Basename
24+
# File::Copy
25+
# Sys::Hostname
26+
# Data::Dumper
27+
RUN apt-get update && apt-get install -y perl pwgen --no-install-recommends && rm -rf /var/lib/apt/lists/*
28+
29+
# gpg: key 5072E1F5: public key "MySQL Release Engineering <[email protected]>" imported
30+
RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5
31+
32+
ENV MYSQL_MAJOR 8.0
33+
ENV MYSQL_VERSION 8.0.0-dmr-1debian8
34+
35+
RUN echo "deb http://repo.mysql.com/apt/debian/ jessie mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list
36+
37+
# the "/var/lib/mysql" stuff here is because the mysql-server postinst doesn't have an explicit way to disable the mysql_install_db codepath besides having a database already "configured" (ie, stuff in /var/lib/mysql/mysql)
38+
# also, we set debconf keys to make APT a little quieter
39+
RUN { \
40+
echo mysql-community-server mysql-community-server/data-dir select ''; \
41+
echo mysql-community-server mysql-community-server/root-pass password ''; \
42+
echo mysql-community-server mysql-community-server/re-root-pass password ''; \
43+
echo mysql-community-server mysql-community-server/remove-test-db select false; \
44+
} | debconf-set-selections \
45+
&& apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}" && rm -rf /var/lib/apt/lists/* \
46+
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \
47+
&& chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \
48+
# ensure that /var/run/mysqld (used for socket and lock files) is writable regardless of the UID our mysqld instance ends up having at runtime
49+
&& chmod 777 /var/run/mysqld
50+
51+
# comment out a few problematic configuration values
52+
# don't reverse lookup hostnames, they are usually another container
53+
RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/mysql.conf.d/mysqld.cnf \
54+
&& echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/mysql.conf.d/mysqld.cnf > /tmp/mysqld.cnf \
55+
&& mv /tmp/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf
56+
57+
VOLUME /var/lib/mysql
58+
59+
COPY docker-entrypoint.sh /usr/local/bin/
60+
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
61+
ENTRYPOINT ["docker-entrypoint.sh"]
62+
63+
EXPOSE 3306
64+
CMD ["mysqld"]

8.0/docker-entrypoint.sh

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
shopt -s nullglob
4+
5+
# if command starts with an option, prepend mysqld
6+
if [ "${1:0:1}" = '-' ]; then
7+
set -- mysqld "$@"
8+
fi
9+
10+
# skip setup if they want an option that stops mysqld
11+
wantHelp=
12+
for arg; do
13+
case "$arg" in
14+
-'?'|--help|--print-defaults|-V|--version)
15+
wantHelp=1
16+
break
17+
;;
18+
esac
19+
done
20+
21+
_check_config() {
22+
toRun=( "$@" --verbose --help )
23+
if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then
24+
cat >&2 <<-EOM
25+
26+
ERROR: mysqld failed while attempting to check config
27+
command was: "${toRun[*]}"
28+
29+
$errors
30+
EOM
31+
exit 1
32+
fi
33+
}
34+
35+
_datadir() {
36+
"$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
37+
}
38+
39+
# allow the container to be started with `--user`
40+
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
41+
_check_config "$@"
42+
DATADIR="$(_datadir "$@")"
43+
mkdir -p "$DATADIR"
44+
chown -R mysql:mysql "$DATADIR"
45+
exec gosu mysql "$BASH_SOURCE" "$@"
46+
fi
47+
48+
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
49+
# still need to check config, container may have started with --user
50+
_check_config "$@"
51+
# Get config
52+
DATADIR="$(_datadir "$@")"
53+
54+
if [ ! -d "$DATADIR/mysql" ]; then
55+
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
56+
echo >&2 'error: database is uninitialized and password option is not specified '
57+
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
58+
exit 1
59+
fi
60+
61+
mkdir -p "$DATADIR"
62+
63+
echo 'Initializing database'
64+
"$@" --initialize-insecure
65+
echo 'Database initialized'
66+
67+
"$@" --skip-networking &
68+
pid="$!"
69+
70+
mysql=( mysql --protocol=socket -uroot )
71+
72+
for i in {30..0}; do
73+
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
74+
break
75+
fi
76+
echo 'MySQL init process in progress...'
77+
sleep 1
78+
done
79+
if [ "$i" = 0 ]; then
80+
echo >&2 'MySQL init process failed.'
81+
exit 1
82+
fi
83+
84+
if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then
85+
# sed is for https://bugs.mysql.com/bug.php?id=20545
86+
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql
87+
fi
88+
89+
if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then
90+
MYSQL_ROOT_PASSWORD="$(pwgen -1 32)"
91+
echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
92+
fi
93+
"${mysql[@]}" <<-EOSQL
94+
-- What's done in this file shouldn't be replicated
95+
-- or products like mysql-fabric won't work
96+
SET @@SESSION.SQL_LOG_BIN=0;
97+
98+
DELETE FROM mysql.user ;
99+
CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
100+
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
101+
DROP DATABASE IF EXISTS test ;
102+
FLUSH PRIVILEGES ;
103+
EOSQL
104+
105+
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then
106+
mysql+=( -p"${MYSQL_ROOT_PASSWORD}" )
107+
fi
108+
109+
if [ "$MYSQL_DATABASE" ]; then
110+
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}"
111+
mysql+=( "$MYSQL_DATABASE" )
112+
fi
113+
114+
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
115+
echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}"
116+
117+
if [ "$MYSQL_DATABASE" ]; then
118+
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}"
119+
fi
120+
121+
echo 'FLUSH PRIVILEGES ;' | "${mysql[@]}"
122+
fi
123+
124+
echo
125+
for f in /docker-entrypoint-initdb.d/*; do
126+
case "$f" in
127+
*.sh) echo "$0: running $f"; . "$f" ;;
128+
*.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;;
129+
*.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;;
130+
*) echo "$0: ignoring $f" ;;
131+
esac
132+
echo
133+
done
134+
135+
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then
136+
"${mysql[@]}" <<-EOSQL
137+
ALTER USER 'root'@'%' PASSWORD EXPIRE;
138+
EOSQL
139+
fi
140+
if ! kill -s TERM "$pid" || ! wait "$pid"; then
141+
echo >&2 'MySQL init process failed.'
142+
exit 1
143+
fi
144+
145+
echo
146+
echo 'MySQL init process done. Ready for start up.'
147+
echo
148+
fi
149+
fi
150+
151+
exec "$@"

generate-stackbrew-library.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -eu
33

44
declare -A aliases=(
55
[5.7]='5 latest'
6+
[8.0]='8'
67
)
78

89
self="$(basename "$BASH_SOURCE")"

0 commit comments

Comments
 (0)