Skip to content
This repository was archived by the owner on Nov 29, 2020. It is now read-only.

Commit edf77b0

Browse files
committed
Merge pull request #22 from tutumcloud/staging
refactored tags, created tests
2 parents 780d306 + ebfadd1 commit edf77b0

16 files changed

+155
-6
lines changed

Dockerfile renamed to 5.5/Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ FROM ubuntu:trusty
22
MAINTAINER Fernando Mayo <[email protected]>, Feng Honglin <[email protected]>
33

44
# Install packages
5-
RUN apt-get update
6-
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server pwgen
5+
ENV DEBIAN_FRONTEND noninteractive
6+
RUN apt-get update && \
7+
apt-get -yq install mysql-server-5.5 pwgen && \
8+
rm -rf /var/lib/apt/lists/*
79

810
# Remove pre-installed database
911
RUN rm -rf /var/lib/mysql/*
File renamed without changes.
File renamed without changes.
File renamed without changes.

my.cnf renamed to 5.5/my.cnf

File renamed without changes.
File renamed without changes.

run.sh renamed to 5.5/run.sh

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ VOLUME_HOME="/var/lib/mysql"
55
if [[ ! -d $VOLUME_HOME/mysql ]]; then
66
echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
77
echo "=> Installing MySQL ..."
8+
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then
9+
cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
10+
fi
811
mysql_install_db > /dev/null 2>&1
912
echo "=> Done!"
1013
/create_mysql_admin_user.sh

5.6/Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM ubuntu:trusty
2+
MAINTAINER Fernando Mayo <[email protected]>, Feng Honglin <[email protected]>
3+
4+
# Install packages
5+
ENV DEBIAN_FRONTEND noninteractive
6+
RUN apt-get update && \
7+
apt-get -yq install mysql-server-5.6 pwgen && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
# Remove pre-installed database
11+
RUN rm -rf /var/lib/mysql/*
12+
13+
# Add MySQL configuration
14+
ADD my.cnf /etc/mysql/conf.d/my.cnf
15+
ADD mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf
16+
17+
# Add MySQL scripts
18+
ADD create_mysql_admin_user.sh /create_mysql_admin_user.sh
19+
ADD import_sql.sh /import_sql.sh
20+
ADD run.sh /run.sh
21+
RUN chmod 755 /*.sh
22+
23+
# Exposed ENV
24+
ENV MYSQL_USER admin
25+
ENV MYSQL_PASS **Random**
26+
27+
# Add VOLUMEs to allow backup of config and databases
28+
VOLUME ["/etc/mysql", "/var/lib/mysql"]
29+
30+
EXPOSE 3306
31+
CMD ["/run.sh"]

5.6/create_db.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
if [[ $# -eq 0 ]]; then
4+
echo "Usage: $0 <db_name>"
5+
exit 1
6+
fi
7+
8+
/usr/bin/mysqld_safe > /dev/null 2>&1 &
9+
10+
echo "=> Creating database $1"
11+
RET=1
12+
while [[ RET -ne 0 ]]; do
13+
sleep 5
14+
mysql -uroot -e "CREATE DATABASE $1"
15+
RET=$?
16+
done
17+
18+
mysqladmin -uroot shutdown
19+
20+
echo "=> Done!"

5.6/create_mysql_admin_user.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
/usr/bin/mysqld_safe > /dev/null 2>&1 &
4+
5+
RET=1
6+
while [[ RET -ne 0 ]]; do
7+
echo "=> Waiting for confirmation of MySQL service startup"
8+
sleep 5
9+
mysql -uroot -e "status" > /dev/null 2>&1
10+
RET=$?
11+
done
12+
13+
if [ "$MYSQL_PASS" = "**Random**" ]; then
14+
unset MYSQL_PASS
15+
fi
16+
17+
PASS=${MYSQL_PASS:-$(pwgen -s 12 1)}
18+
_word=$( [ ${MYSQL_PASS} ] && echo "preset" || echo "random" )
19+
echo "=> Creating MySQL user ${MYSQL_USER} with ${_word} password"
20+
21+
mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '$PASS'"
22+
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION"
23+
24+
25+
echo "=> Done!"
26+
27+
echo "========================================================================"
28+
echo "You can now connect to this MySQL Server using:"
29+
echo ""
30+
echo " mysql -u$MYSQL_USER -p$PASS -h<host> -P<port>"
31+
echo ""
32+
echo "Please remember to change the above password as soon as possible!"
33+
echo "MySQL user 'root' has no password but only allows local connections"
34+
echo "========================================================================"
35+
36+
mysqladmin -uroot shutdown

5.6/import_sql.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
if [[ $# -ne 2 ]]; then
4+
echo "Usage: $0 <password> </path/to/sql_file.sql>"
5+
exit 1
6+
fi
7+
8+
echo "=> Starting MySQL Server"
9+
/usr/bin/mysqld_safe > /dev/null 2>&1 &
10+
sleep 5
11+
echo " Started with PID $!"
12+
13+
echo "=> Importing SQL file"
14+
mysql -uadmin -p"$1" < "$2"
15+
16+
echo "=> Stopping MySQL Server"
17+
mysqladmin -uadmin -p"$1" shutdown
18+
19+
echo "=> Done!"

5.6/my.cnf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mysqld]
2+
bind-address=0.0.0.0

5.6/mysqld_charset.cnf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[mysqld]
2+
character_set_server=utf8
3+
character_set_filesystem=utf8
4+
collation-server=utf8_general_ci
5+
init-connect='SET NAMES utf8'
6+
init_connect='SET collation_connection = utf8_general_ci'
7+
skip-character-set-client-handshake

5.6/run.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
VOLUME_HOME="/var/lib/mysql"
4+
5+
if [[ ! -d $VOLUME_HOME/mysql ]]; then
6+
echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
7+
echo "=> Installing MySQL ..."
8+
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then
9+
cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
10+
fi
11+
mysql_install_db > /dev/null 2>&1
12+
echo "=> Done!"
13+
/create_mysql_admin_user.sh
14+
else
15+
echo "=> Using an existing volume of MySQL"
16+
fi
17+
18+
exec mysqld_safe

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ Base docker image to run a MySQL database server
77
MySQL version
88
-------------
99

10-
`master` branch maintains MySQL from Ubuntu trusty official source. If you want to get different version of MySQL, please checkout `5.5` branch and `5.6` branch.
11-
12-
If you want to use MariaDB, please check our `tutum/mariadb` image: https://github.com/tutumcloud/tutum-docker-mariadb
10+
Different versions are built from different folders. If you want to use MariaDB, please check our `tutum/mariadb` image: https://github.com/tutumcloud/tutum-docker-mariadb
1311

1412

1513
Usage
1614
-----
1715

1816
To create the image `tutum/mysql`, execute the following command on the tutum-mysql folder:
1917

20-
docker build -t tutum/mysql .
18+
docker build -t tutum/mysql 5.5/
2119

2220
To run the image and bind to port 3306:
2321

circle.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
machine:
2+
services:
3+
- docker
4+
dependencies:
5+
override:
6+
- docker build -t mysql-5.5 5.5/
7+
- docker build -t mysql-5.6 5.6/
8+
test:
9+
override:
10+
- docker run -d -p 13306:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.5; sleep 20
11+
- mysqladmin -uuser -ptest ping -h127.0.0.1 -P13306 | grep -c "mysqld is alive"
12+
- docker run -d -p 13307:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.6; sleep 20
13+
- mysqladmin -uuser -ptest ping -h127.0.0.1 -P13307 | grep -c "mysqld is alive"

0 commit comments

Comments
 (0)