From 96edb4c56d964b73663c663b7b237e718ca3d4da Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Fri, 3 Nov 2017 10:27:25 +0800 Subject: Add compass-db Database for Compass Change-Id: I5f624c5b8ed59683b5b72b771607ea74a4a4fd7e Signed-off-by: Harry Huang --- compass-db/Dockerfile | 12 ++++++++++++ compass-db/README.md | 2 ++ compass-db/entrypoint.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 compass-db/Dockerfile create mode 100644 compass-db/README.md create mode 100644 compass-db/entrypoint.sh diff --git a/compass-db/Dockerfile b/compass-db/Dockerfile new file mode 100644 index 0000000..a7208a9 --- /dev/null +++ b/compass-db/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:trusty + +EXPOSE 3306 + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server && \ + rm -rf /var/lib/apt/lists/* + +COPY entrypoint.sh /sbin/entrypoint.sh +RUN chmod 755 /sbin/entrypoint.sh + +CMD ["/sbin/entrypoint.sh"] diff --git a/compass-db/README.md b/compass-db/README.md new file mode 100644 index 0000000..7c0d926 --- /dev/null +++ b/compass-db/README.md @@ -0,0 +1,2 @@ +# compass-db +Database for Compass diff --git a/compass-db/entrypoint.sh b/compass-db/entrypoint.sh new file mode 100644 index 0000000..e01d29c --- /dev/null +++ b/compass-db/entrypoint.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -x + +create_users_and_dbs() { + /usr/bin/mysqld_safe > /dev/null 2>&1 & + + timeout=30 + # wait up to 30 secs... + while ! /usr/bin/mysqladmin -u root status > /dev/null 2>&1 + do + timeout=$(($timeout - 1)) + if [ $timeout -eq 0 ]; then + echo -e "\nCould not connect to database server. Aborting..." + exit 1 + fi + echo -n "." + sleep 1 + done + + echo "Creating user..." + mysqladmin -h127.0.0.1 --port=3306 -u root password root + mysql -h127.0.0.1 --port=3306 -uroot -proot -e "create database compass" + mysql -h127.0.0.1 --port=3306 -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root'" + mysqladmin -uroot -proot shutdown +} + +listen_on_all_interfaces() { + cat > /etc/mysql/conf.d/mysql-listen.cnf <