Skip to content

Commit

Permalink
Update Docker to be modular and use docker-compose
Browse files Browse the repository at this point in the history
This commit updates the Dockerfile to separate out redis and mysql, and
adds a docker-compose.yml file for use with docker-compose to build the
containers as a group. Refer to docker-compose documentation for info.

This is not intended for production - to simplify handling of email, all
mail is being sunk to http://127.0.0.1:8001/ via a web UI. This makes it
easier to test where you don't have a valid email server.

Configuration can be adjusted in config/config_docker.json.

Known issues at present:

- Attachments/uploads should be put into a data volume for portability
- The installation thinks the hostname is 0.0, and the redirect after
setup appears to be incorrect.

There are likely other issues - this is more intended as a proof-of-concept.
The (reduced) Dockerfile can likely be further simplified and improved.
  • Loading branch information
greigdp committed Jun 24, 2015
1 parent 5bc0a19 commit 445d213
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 147 deletions.
55 changes: 2 additions & 53 deletions Dockerfile
Expand Up @@ -2,17 +2,14 @@
# See License.txt for license information.
FROM ubuntu:14.04

# Install Dependancies
# Install Dependencies
RUN apt-get update && apt-get install -y build-essential
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup | bash -
RUN apt-get install -y nodejs
RUN apt-get install -y ruby-full
RUN gem install compass

# Postfix
RUN apt-get install -y postfix

#
# Install GO
#
Expand All @@ -21,6 +18,7 @@ RUN apt-get update && apt-get install -y \
gcc libc6-dev make git mercurial \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get clean

ENV GOLANG_VERSION 1.4.2

Expand All @@ -36,57 +34,9 @@ ENV GOPATH /go
ENV PATH /go/bin:$PATH
WORKDIR /go

# ---------------------------------------------------------------------------------------------------------------------

#
# Install SQL
#

ENV MYSQL_ROOT_PASSWORD=mostest
ENV MYSQL_USER=mmuser
ENV MYSQL_PASSWORD=mostest
ENV MYSQL_DATABASE=mattermost_test

RUN groupadd -r mysql && useradd -r -g mysql mysql

RUN apt-get update && apt-get install -y perl --no-install-recommends && rm -rf /var/lib/apt/lists/*

RUN apt-key adv --keyserver pool.sks-keyservers.net --recv-keys A4A9406876FCBD3C456770C88C718D3B5072E1F5

ENV MYSQL_MAJOR 5.6
ENV MYSQL_VERSION 5.6.25

RUN echo "deb http://repo.mysql.com/apt/debian/ wheezy mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list

RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install mysql-server \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql

RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf

VOLUME /var/lib/mysql
# ---------------------------------------------------------------------------------------------------------------------

#
# Install Redis
#

RUN apt-get update && apt-get install -y wget
RUN wget http://download.redis.io/redis-stable.tar.gz; \
tar xvzf redis-stable.tar.gz; \
cd redis-stable; \
make install

# ---------------------------------------------------------------------------------------------------------------------

# Copy over files
ADD . /go/src/github.com/mattermost/platform

# Insert postfix config
ADD ./docker/main.cf /etc/postfix/

RUN go get github.com/tools/godep
RUN cd /go/src/github.com/mattermost/platform; godep restore
RUN go install github.com/mattermost/platform
Expand All @@ -95,5 +45,4 @@ RUN cd /go/src/github.com/mattermost/platform/web/react; npm install
RUN chmod +x /go/src/github.com/mattermost/platform/docker/docker-entry.sh
ENTRYPOINT /go/src/github.com/mattermost/platform/docker/docker-entry.sh

# Ports
EXPOSE 80
10 changes: 5 additions & 5 deletions config/config_docker.json
Expand Up @@ -9,7 +9,7 @@
},
"ServiceSettings": {
"SiteName": "Mattermost",
"Domain": "",
"Domain": "127.0.0.1",
"Mode" : "prod",
"AllowTesting" : false,
"UseSSL": false,
Expand All @@ -24,15 +24,15 @@
},
"SqlSettings": {
"DriverName": "mysql",
"DataSource": "mmuser:mostest@tcp(localhost:3306)/mattermost_test",
"DataSourceReplicas": ["mmuser:mostest@tcp(localhost:3306)/mattermost_test"],
"DataSource": "mmuser:mostest@tcp(mysql:3306)/mattermost_test",
"DataSourceReplicas": ["mmuser:mostest@tcp(mysql:3306)/mattermost_test"],
"MaxIdleConns": 10,
"MaxOpenConns": 10,
"Trace": false,
"AtRestEncryptKey": "Ya0xMrybACJ3sZZVWQC7e31h5nSDWZFS"
},
"RedisSettings": {
"DataSource": "localhost:6379",
"DataSource": "redis:6379",
"MaxOpenConns": 1000
},
"AWSSettings": {
Expand All @@ -56,7 +56,7 @@
"EmailSettings": {
"SMTPUsername": "",
"SMTPPassword": "",
"SMTPServer": "localhost:25",
"SMTPServer": "mail:25",
"UseTLS": false,
"FeedbackEmail": "",
"FeedbackName": "",
Expand Down
31 changes: 31 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,31 @@
mysql:
image: mysql:5.6
environment:
- MYSQL_ROOT_PASSWORD=secretmysqlrootuserpassword
- MYSQL_USER=mmuser
- MYSQL_PASSWORD=mostest
- MYSQL_DATABASE=mattermost_test
volumes_from:
- dbdata

redis:
image: redis:3.0

dbdata:
image: cogniteev/echo
volumes:
- /var/lib/mysql

app:
build: .
links:
- mysql
- redis
- mail
ports:
- "8000:80"

mail:
image: weave/rest-smtp-sink
ports:
- "8001:80"
95 changes: 6 additions & 89 deletions docker/docker-entry.sh
Expand Up @@ -4,8 +4,8 @@

mkdir -p web/static/js

echo "127.0.0.1 dockerhost" >> /etc/hosts
/etc/init.d/networking restart
#echo "127.0.0.1 dockerhost" >> /etc/hosts
#/etc/init.d/networking restart

echo configuring mysql

Expand All @@ -21,96 +21,13 @@ get_option () {
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 postfix
/etc/init.d/postfix restart
#echo starting postfix
#/etc/init.d/postfix restart

echo starting redis
redis-server &
#echo starting redis
#redis-server &

echo starting react processor
cd /go/src/github.com/mattermost/platform/web/react && npm start &
Expand Down

0 comments on commit 445d213

Please sign in to comment.