From bc7d9f5b5e4dd3ff87d0486eaba628bb8d205e6e Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 15 Jun 2015 10:38:01 -0400 Subject: Adding Dockerfile and releated configs --- docker-entry.sh | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 docker-entry.sh (limited to 'docker-entry.sh') diff --git a/docker-entry.sh b/docker-entry.sh new file mode 100755 index 000000000..10809fc1d --- /dev/null +++ b/docker-entry.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +mkdir -p web/static/js + +echo configuring mysql + +# SQL!!! +set -e + +get_option () { + local section=$1 + local option=$2 + local default=$3 + ret=$(my_print_defaults $section | grep '^--'${option}'=' | cut -d= -f2-) + [ -z $ret ] && ret=$default + echo $ret +} + + +# Get config +DATADIR="$("mysqld" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }')" +SOCKET=$(get_option mysqld socket "$DATADIR/mysql.sock") +PIDFILE=$(get_option mysqld pid-file "/var/run/mysqld/mysqld.pid") + +if [ ! -d "$DATADIR/mysql" ]; then + if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" ]; then + echo >&2 'error: database is uninitialized and MYSQL_ROOT_PASSWORD not set' + echo >&2 ' Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?' + exit 1 + fi + + mkdir -p "$DATADIR" + chown -R mysql:mysql "$DATADIR" + + echo 'Running mysql_install_db' + mysql_install_db --user=mysql --datadir="$DATADIR" --rpm --keep-my-cnf + echo 'Finished mysql_install_db' + + mysqld --user=mysql --datadir="$DATADIR" --skip-networking & + for i in $(seq 30 -1 0); do + [ -S "$SOCKET" ] && break + echo 'MySQL init process in progress...' + sleep 1 + done + if [ $i = 0 ]; then + echo >&2 'MySQL init process failed.' + exit 1 + fi + + # These statements _must_ be on individual lines, and _must_ end with + # semicolons (no line breaks or comments are permitted). + # TODO proper SQL escaping on ALL the things D: + + tempSqlFile=$(mktemp /tmp/mysql-first-time.XXXXXX.sql) + cat > "$tempSqlFile" <<-EOSQL + -- What's done in this file shouldn't be replicated + -- or products like mysql-fabric won't work + SET @@SESSION.SQL_LOG_BIN=0; + + DELETE FROM mysql.user ; + CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; + GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ; + DROP DATABASE IF EXISTS test ; + EOSQL + + if [ "$MYSQL_DATABASE" ]; then + echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" >> "$tempSqlFile" + fi + + if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then + echo "CREATE USER '"$MYSQL_USER"'@'%' IDENTIFIED BY '"$MYSQL_PASSWORD"' ;" >> "$tempSqlFile" + + if [ "$MYSQL_DATABASE" ]; then + echo "GRANT ALL ON \`"$MYSQL_DATABASE"\`.* TO '"$MYSQL_USER"'@'%' ;" >> "$tempSqlFile" + fi + fi + + echo 'FLUSH PRIVILEGES ;' >> "$tempSqlFile" + + mysql -uroot < "$tempSqlFile" + + rm -f "$tempSqlFile" + kill $(cat $PIDFILE) + for i in $(seq 30 -1 0); do + [ -f "$PIDFILE" ] || break + echo 'MySQL init process in progress...' + sleep 1 + done + if [ $i = 0 ]; then + echo >&2 'MySQL hangs during init process.' + exit 1 + fi + echo 'MySQL init process done. Ready for start up.' +fi + +chown -R mysql:mysql "$DATADIR" + +mysqld & + +sleep 5 + +# ------------------------ + +echo starting redis +redis-server & + +echo starting react processor +cd /go/src/github.com/mattermost/platform/web/react && npm start & + +echo starting go web server +cd /go/src/github.com/mattermost/platform/; go run mattermost.go -config=config_docker.json & + +echo starting compass watch +cd /go/src/github.com/mattermost/platform/web/sass-files && compass watch -- cgit v1.2.3-1-g7c22 From 76a0e0fea4ad2901716eae4b638a73befa1e49f8 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 16 Jun 2015 14:15:55 -0400 Subject: Modifications for sending local mail --- docker-entry.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docker-entry.sh') diff --git a/docker-entry.sh b/docker-entry.sh index 10809fc1d..3a273e365 100755 --- a/docker-entry.sh +++ b/docker-entry.sh @@ -101,6 +101,9 @@ sleep 5 # ------------------------ +echo starting postfix +/etc/init.d/postfix restart + echo starting redis redis-server & -- cgit v1.2.3-1-g7c22 From 4cd28a520cec04ac880ef112c0f8858e039e1f2b Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 16 Jun 2015 19:46:56 -0400 Subject: Using config.json instead of config_docker.json for docker. Note, this will break local dev builds. --- docker-entry.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'docker-entry.sh') diff --git a/docker-entry.sh b/docker-entry.sh index 3a273e365..db6ccaa18 100755 --- a/docker-entry.sh +++ b/docker-entry.sh @@ -2,6 +2,9 @@ mkdir -p web/static/js +echo "127.0.0.1 dockerhost" >> /etc/hosts +/etc/init.d/networking restart + echo configuring mysql # SQL!!! @@ -111,7 +114,7 @@ echo starting react processor cd /go/src/github.com/mattermost/platform/web/react && npm start & echo starting go web server -cd /go/src/github.com/mattermost/platform/; go run mattermost.go -config=config_docker.json & +cd /go/src/github.com/mattermost/platform/; go run mattermost.go -config=config.json & echo starting compass watch cd /go/src/github.com/mattermost/platform/web/sass-files && compass watch -- cgit v1.2.3-1-g7c22