From e98a25c94f5a8c8d7b5ae61df8592fe9b65780d1 Mon Sep 17 00:00:00 2001 From: Diogo Monica Date: Thu, 18 Jun 2015 14:07:02 -0700 Subject: [PATCH] Fixed Dockerfile and compose --- cmd/vetinari-server/main.go | 2 +- docker-compose.yml | 6 +- mysql | 1 - vetinarimysql/Dockerfile | 14 ++++ vetinarimysql/LICENSE | 21 ++++++ vetinarimysql/start | 127 ++++++++++++++++++++++++++++++++++++ 6 files changed, 166 insertions(+), 5 deletions(-) delete mode 160000 mysql create mode 100644 vetinarimysql/Dockerfile create mode 100644 vetinarimysql/LICENSE create mode 100755 vetinarimysql/start diff --git a/cmd/vetinari-server/main.go b/cmd/vetinari-server/main.go index 161dbb41e8..47d07233ba 100644 --- a/cmd/vetinari-server/main.go +++ b/cmd/vetinari-server/main.go @@ -72,7 +72,7 @@ func main() { trust = signed.NewEd25519() } - db, err := sql.Open("mysql", "dockercondemo:dockercondemo@tcp(mysql:3306)/dockercondemo") + db, err := sql.Open("mysql", "dockercondemo:dockercondemo@tcp(vetinarimysql:3306)/dockercondemo") if err != nil { logrus.Fatal("Error starting DB driver: ", err.Error()) return // not strictly needed but let's be explicit diff --git a/docker-compose.yml b/docker-compose.yml index c531473591..79cb703176 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ vetinari: build: . links: - - mysql + - vetinarimysql ports: - "8080:8080" - "4443:4443" @@ -10,7 +10,7 @@ vetinari: # - /dev/bus/usb/003/010:/dev/bus/usb/002/010 # - /var/run/pcscd/pcscd.comm:/var/run/pcscd/pcscd.comm # build: ../rufus -mysql: - build: ./mysql/ +vetinarimysql: + build: ./vetinarimysql/ ports: - "3306:3306" diff --git a/mysql b/mysql deleted file mode 160000 index 3234be9a89..0000000000 --- a/mysql +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3234be9a899bbb86cbf724901d4cfe3b72789285 diff --git a/vetinarimysql/Dockerfile b/vetinarimysql/Dockerfile new file mode 100644 index 0000000000..cbebc7cca6 --- /dev/null +++ b/vetinarimysql/Dockerfile @@ -0,0 +1,14 @@ +FROM sameersbn/ubuntu:14.04.20150613 +MAINTAINER diogo@docker.com + +RUN apt-get update \ + && apt-get install -y mysql-server \ + && rm -rf /var/lib/mysql/mysql \ + && rm -rf /var/lib/apt/lists/* + +ADD start /start +RUN chmod 755 /start + +EXPOSE 3306 + +CMD ["/start"] diff --git a/vetinarimysql/LICENSE b/vetinarimysql/LICENSE new file mode 100644 index 0000000000..c8476ac066 --- /dev/null +++ b/vetinarimysql/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Sameer Naik + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vetinarimysql/start b/vetinarimysql/start new file mode 100755 index 0000000000..87a0a6abe5 --- /dev/null +++ b/vetinarimysql/start @@ -0,0 +1,127 @@ +#!/bin/bash +set -e + +DB_NAME='dockercondemo' +DB_TABLE='tuf_files' +DB_USER='dockercondemo' +DB_PASS='dockercondemo' + +DB_REMOTE_ROOT_NAME='dockercondemo' +DB_REMOTE_ROOT_PASS='dockercondemo' +DB_REMOTE_ROOT_HOST='' + +# disable error log +sed 's/^log_error/# log_error/' -i /etc/mysql/my.cnf + +# Fixing StartUp Porblems with some DNS Situations and Speeds up the stuff +# http://www.percona.com/blog/2008/05/31/dns-achilles-heel-mysql-installation/ +cat > /etc/mysql/conf.d/mysql-skip-name-resolv.cnf </dev/null 2>&1 + + # start mysql server + echo "Starting MySQL server..." + /usr/bin/mysqld_safe >/dev/null 2>&1 & + + # wait for mysql server to start (max 30 seconds) + timeout=30 + echo -n "Waiting for database server to accept connections" + 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 + + ## create a localhost only, debian-sys-maint user + ## the debian-sys-maint is used while creating users and database + ## as well as to shut down or starting up the mysql server via mysqladmin + echo "Creating debian-sys-maint user..." + mysql -uroot -e "GRANT ALL PRIVILEGES on *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '' WITH GRANT OPTION;" + + if [ -n "${DB_REMOTE_ROOT_NAME}" -a -n "${DB_REMOTE_ROOT_HOST}" ]; then + echo "Creating remote user \"${DB_REMOTE_ROOT_NAME}\" with root privileges..." + mysql -uroot \ + -e "GRANT ALL PRIVILEGES ON *.* TO '${DB_REMOTE_ROOT_NAME}'@'${DB_REMOTE_ROOT_HOST}' IDENTIFIED BY '${DB_REMOTE_ROOT_PASS}' WITH GRANT OPTION; FLUSH PRIVILEGES;" + fi + + /usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf shutdown +fi + +# create new user / database +if [ -n "${DB_USER}" -o -n "${DB_NAME}" ]; then + /usr/bin/mysqld_safe >/dev/null 2>&1 & + + # wait for mysql server to start (max 30 seconds) + timeout=30 + while ! /usr/bin/mysqladmin -u root status >/dev/null 2>&1 + do + timeout=$(($timeout - 1)) + if [ $timeout -eq 0 ]; then + echo "Could not connect to mysql server. Aborting..." + exit 1 + fi + sleep 1 + done + + if [ -n "${DB_NAME}" ]; then + for db in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do + echo "Creating database \"$db\"..." + mysql --defaults-file=/etc/mysql/debian.cnf \ + -e "CREATE DATABASE IF NOT EXISTS \`$db\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;" + if [ -n "${DB_USER}" ]; then + echo "Granting access to database \"$db\" for user \"${DB_USER}\"..." + mysql --defaults-file=/etc/mysql/debian.cnf \ + -e "GRANT ALL PRIVILEGES ON \`$db\`.* TO '${DB_USER}' IDENTIFIED BY '${DB_PASS}';" + fi + # Create our Database: + mysql -uroot -e "USE \`$db\`; DROP TABLE IF EXISTS \`$DB_TABLE\`;" + mysql -uroot -e "USE \`$db\`; CREATE TABLE \`$DB_TABLE\` ( + \`id\` int(11) NOT NULL AUTO_INCREMENT, + \`qdn\` varchar(255) NOT NULL, + \`role\` varchar(255) NOT NULL, + \`version\` int(11) NOT NULL, + \`data\` longblob NOT NULL, + PRIMARY KEY (\`id\`), + UNIQUE KEY \`qdn\` (\`qdn\`,\`role\`,\`version\`) + ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;" + done + fi + /usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf shutdown +fi + +# listen on all interfaces +cat > /etc/mysql/conf.d/mysql-listen.cnf <