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

Commit

Permalink
Merge pull request #22 from tutumcloud/staging
Browse files Browse the repository at this point in the history
refactored tags, created tests
  • Loading branch information
fermayo committed Aug 16, 2014
2 parents 780d306 + ebfadd1 commit edf77b0
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 6 deletions.
6 changes: 4 additions & 2 deletions Dockerfile → 5.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ FROM ubuntu:trusty
MAINTAINER Fernando Mayo <[email protected]>, Feng Honglin <[email protected]>

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

# Remove pre-installed database
RUN rm -rf /var/lib/mysql/*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions run.sh → 5.5/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ VOLUME_HOME="/var/lib/mysql"
if [[ ! -d $VOLUME_HOME/mysql ]]; then
echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
echo "=> Installing MySQL ..."
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then
cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
fi
mysql_install_db > /dev/null 2>&1
echo "=> Done!"
/create_mysql_admin_user.sh
Expand Down
31 changes: 31 additions & 0 deletions 5.6/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM ubuntu:trusty
MAINTAINER Fernando Mayo <[email protected]>, Feng Honglin <[email protected]>

# Install packages
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get -yq install mysql-server-5.6 pwgen && \
rm -rf /var/lib/apt/lists/*

# Remove pre-installed database
RUN rm -rf /var/lib/mysql/*

# Add MySQL configuration
ADD my.cnf /etc/mysql/conf.d/my.cnf
ADD mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf

# Add MySQL scripts
ADD create_mysql_admin_user.sh /create_mysql_admin_user.sh
ADD import_sql.sh /import_sql.sh
ADD run.sh /run.sh
RUN chmod 755 /*.sh

# Exposed ENV
ENV MYSQL_USER admin
ENV MYSQL_PASS **Random**

# Add VOLUMEs to allow backup of config and databases
VOLUME ["/etc/mysql", "/var/lib/mysql"]

EXPOSE 3306
CMD ["/run.sh"]
20 changes: 20 additions & 0 deletions 5.6/create_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

if [[ $# -eq 0 ]]; then
echo "Usage: $0 <db_name>"
exit 1
fi

/usr/bin/mysqld_safe > /dev/null 2>&1 &

echo "=> Creating database $1"
RET=1
while [[ RET -ne 0 ]]; do
sleep 5
mysql -uroot -e "CREATE DATABASE $1"
RET=$?
done

mysqladmin -uroot shutdown

echo "=> Done!"
36 changes: 36 additions & 0 deletions 5.6/create_mysql_admin_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

/usr/bin/mysqld_safe > /dev/null 2>&1 &

RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MySQL service startup"
sleep 5
mysql -uroot -e "status" > /dev/null 2>&1
RET=$?
done

if [ "$MYSQL_PASS" = "**Random**" ]; then
unset MYSQL_PASS
fi

PASS=${MYSQL_PASS:-$(pwgen -s 12 1)}
_word=$( [ ${MYSQL_PASS} ] && echo "preset" || echo "random" )
echo "=> Creating MySQL user ${MYSQL_USER} with ${_word} password"

mysql -uroot -e "CREATE USER '${MYSQL_USER}'@'%' IDENTIFIED BY '$PASS'"
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_USER}'@'%' WITH GRANT OPTION"


echo "=> Done!"

echo "========================================================================"
echo "You can now connect to this MySQL Server using:"
echo ""
echo " mysql -u$MYSQL_USER -p$PASS -h<host> -P<port>"
echo ""
echo "Please remember to change the above password as soon as possible!"
echo "MySQL user 'root' has no password but only allows local connections"
echo "========================================================================"

mysqladmin -uroot shutdown
19 changes: 19 additions & 0 deletions 5.6/import_sql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <password> </path/to/sql_file.sql>"
exit 1
fi

echo "=> Starting MySQL Server"
/usr/bin/mysqld_safe > /dev/null 2>&1 &
sleep 5
echo " Started with PID $!"

echo "=> Importing SQL file"
mysql -uadmin -p"$1" < "$2"

echo "=> Stopping MySQL Server"
mysqladmin -uadmin -p"$1" shutdown

echo "=> Done!"
2 changes: 2 additions & 0 deletions 5.6/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mysqld]
bind-address=0.0.0.0
7 changes: 7 additions & 0 deletions 5.6/mysqld_charset.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[mysqld]
character_set_server=utf8
character_set_filesystem=utf8
collation-server=utf8_general_ci
init-connect='SET NAMES utf8'
init_connect='SET collation_connection = utf8_general_ci'
skip-character-set-client-handshake
18 changes: 18 additions & 0 deletions 5.6/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

VOLUME_HOME="/var/lib/mysql"

if [[ ! -d $VOLUME_HOME/mysql ]]; then
echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
echo "=> Installing MySQL ..."
if [ ! -f /usr/share/mysql/my-default.cnf ] ; then
cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
fi
mysql_install_db > /dev/null 2>&1
echo "=> Done!"
/create_mysql_admin_user.sh
else
echo "=> Using an existing volume of MySQL"
fi

exec mysqld_safe
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ Base docker image to run a MySQL database server
MySQL version
-------------

`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.

If you want to use MariaDB, please check our `tutum/mariadb` image: https://github.com/tutumcloud/tutum-docker-mariadb
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


Usage
-----

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

docker build -t tutum/mysql .
docker build -t tutum/mysql 5.5/

To run the image and bind to port 3306:

Expand Down
13 changes: 13 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
machine:
services:
- docker
dependencies:
override:
- docker build -t mysql-5.5 5.5/
- docker build -t mysql-5.6 5.6/
test:
override:
- docker run -d -p 13306:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.5; sleep 20
- mysqladmin -uuser -ptest ping -h127.0.0.1 -P13306 | grep -c "mysqld is alive"
- docker run -d -p 13307:3306 -e MYSQL_USER="user" -e MYSQL_PASS="test" mysql-5.6; sleep 20
- mysqladmin -uuser -ptest ping -h127.0.0.1 -P13307 | grep -c "mysqld is alive"

0 comments on commit edf77b0

Please sign in to comment.