Fixes the Mistral Docker image

Refactored to make the docker stuff self contained and removed the
unnecessary files from the root directory. Also created a readme file to
concretize how this feature works.

Also added an example script to set up Mistral with MySQL.

Closes-Bug: #1585911

Change-Id: I7fbcccb9d7ad168c5391e71326b205d074ab01ab
Signed-off-by: Andras Kovi <akovi@nokia.com>
This commit is contained in:
Andras Kovi 2016-05-26 09:25:06 +02:00
parent a50dcfce4e
commit 7b6d76659a
7 changed files with 184 additions and 50 deletions

View File

@ -1,38 +0,0 @@
FROM ubuntu:14.04
MAINTAINER hardik.parekh@nectechnologies.in
#Set Up RabbitMQ.
RUN sudo apt-get update && apt-get install -y rabbitmq-server
#Mistral Installation.
RUN sudo apt-get update && apt-get install -y python-dev python-setuptools libffi-dev libxslt1-dev libxml2-dev libyaml-dev libssl-dev git python-pip
RUN sudo pip install tox==1.6.1
RUN mkdir -p /opt/stack/mistral
ADD . /opt/stack/mistral
WORKDIR /opt/stack/mistral
RUN pip install -r requirements.txt
RUN pip install .
RUN mkdir /etc/mistral
RUN oslo-config-generator --config-file tools/config/config-generator.mistral.conf --output-file /etc/mistral/mistral.conf
RUN python tools/sync_db.py --config-file /etc/mistral/mistral.conf
#python-mistralclient Installation.
RUN pip install python-mistralclient
#Configure Mistral.
RUN sed -ri '/\[oslo_messaging_rabbit\]\//rabbit_userid/a rabbit_userid = $RABBIT_USERID' /etc/mistral/mistral.conf
RUN sed -ri '/\[oslo_messaging_rabbit\]\//rabbit_password/a rabbit_password = $RABBIT_PASSWORD' /etc/mistral/mistral.conf
RUN sed -ri '$a\auth_enable = false' /etc/mistral/mistral.conf
VOLUME ["/home/mistral"]
WORKDIR /home/mistral
#Configure post launch script.
RUN sudo apt-get install -y screen
RUN echo "#!/bin/bash" > /root/postlaunch.sh
RUN echo "sudo cp -n /etc/mistral/mistral.conf /home/mistral/" >> /root/postlaunch.sh
RUN echo "sudo cp -n /opt/stack/mistral/mistral.sqlite /home/mistral" >> /root/postlaunch.sh
RUN echo "sudo service rabbitmq-server start" >> /root/postlaunch.sh
RUN echo "screen -d -m mistral-server --server all --config-file /home/mistral/mistral.conf" >> /root/postlaunch.sh
RUN chmod 755 /root/postlaunch.sh
RUN echo "/root/postlaunch.sh" >>~/.bashrc
ENTRYPOINT /bin/bash

View File

@ -1,12 +1,16 @@
#!/bin/bash -xe
if [ -x "/usr/bin/apt-get" ]; then
sudo -E apt-get update
sudo -E apt-get install -y docker.io apparmor cgroup-lite
elif [ -x "/usr/bin/yum" ]; then
sudo -E yum install -y docker-io gpg
else
echo "No supported package manager installed on system. Supported: apt, yum"
exit 1
fi
sudo docker build -t mistral-docker .
sudo docker save mistral-docker | gzip > mistral-docker.tar.gz
#!/bin/bash -xe
# TODO (akovi): This script is needed practically only for the CI builds.
# Should be moved to some other place
# install docker
curl -fsSL https://get.docker.com/ | sh
sudo service docker restart
sudo -E docker pull ubuntu:14.04
# build image
sudo -E tools/docker/build.sh
sudo -E docker save mistral-all | gzip > mistral-docker.tar.gz

View File

@ -0,0 +1,60 @@
Using Mistral with docker
=========================
In order to minimize the work needed to the current Mistral code, or be able
to spin up independent or networked Mistral instances in seconds, docker
containers are a very good option. This guide describes the process to
launch an all-in-one Mistral container.
Docker installation
-------------------
In order to install the latest docker engine, run::
curl -fsSL https://get.docker.com/ | sh
If you are behind a proxy, additional configuration may be needed to be
able to execute further steps in the setup process. For detailed information
on this process, check out `the official guide at
<http://www.sqlite.org/omitted.html>`_.
Build the Mistral image
-----------------------
The `build.sh` script takes care of creating the `mistral-all` image locally.
Running Mistral
---------------
Start a RabbitMQ container::
docker run -d --name rabbitmq rabbitmq
Start Mistral::
docker run -d -p 8989:8989 --name mistral mistral-all
To execute commands inside the container::
docker exec -it mistral bash
E.g. to list workflows, issue::
mistral workflow-list
Running Mistral with MySQL
--------------------------
Other than the simplest use cases will very probably fail with various errors
due to the default Sqlight database. It is highly recommended that, for
example, MySQL is used as database backend.
The `start_mistral_rabbit_mysql.sh` script sets up a rabbitmq container, a
mysql container and a mistral container to work together.
Check out the script for more detail.

22
tools/docker/Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM ubuntu:14.04
MAINTAINER hardik.parekh@nectechnologies.in
ADD . /opt/stack/mistral
RUN /opt/stack/mistral/tools/docker/Dockerfile_script.sh
EXPOSE 8989
VOLUME ["/opt/stack/mistral"]
VOLUME ["/home/mistral"]
WORKDIR /home/mistral
CMD mistral-server --server all --config-file /home/mistral/mistral.conf
ENV TINI_SHA 066ad710107dc7ee05d3aa6e4974f01dc98f3888
# Use tini as subreaper in Docker container to adopt zombie processes
RUN curl -fsSL https://github.com/krallin/tini/releases/download/v0.5.0/tini-static -o /bin/tini \
&& chmod +x /bin/tini \
&& echo "$TINI_SHA /bin/tini" | sha1sum -c -
ENTRYPOINT ["/bin/tini", "--"]

View File

@ -0,0 +1,39 @@
#! /bin/bash -xe
#Mistral Installation.
export DEBIAN_FRONTEND=noninteractive
apt-get -qq update
apt-get install -y \
curl \
git \
libffi-dev \
libssl-dev \
libxml2-dev \
libxslt1-dev \
libyaml-dev \
mc \
python-dev \
python-pip \
python-setuptools \
sudo pip install tox==1.6.1 python-mistralclient
cd /opt/stack/mistral
pip install -r requirements.txt
pip install .
mkdir -p /home/mistral
cd /home/mistral
oslo-config-generator --config-file /opt/stack/mistral/tools/config/config-generator.mistral.conf --output-file /home/mistral/mistral.conf
python /opt/stack/mistral/tools/sync_db.py --config-file /home/mistral/mistral.conf
#Configure Mistral.
sed -i 's/\[database\]/\[database\]\nconnection = sqlite:\/\/\/\/home\/mistral\/mistral.sqlite/' /home/mistral/mistral.conf
sed -i 's/\[oslo_messaging_rabbit\]/\[oslo_messaging_rabbit\]\nrabbit_host = rabbitmq/' /home/mistral/mistral.conf
sed -i 's/\[pecan\]/\[pecan\]\nauth_enable = false/' /home/mistral/mistral.conf
# install pyv8 to be able to run javscript actions (note that this breaks
# portability because of architecture dependent binaries)
curl -k "https://raw.githubusercontent.com/emmetio/pyv8-binaries/master/pyv8-linux64.zip" > /tmp/pyv8.zip
unzip /tmp/pyv8.zip -d /tmp/
cp /tmp/*PyV8* /usr/lib/python2.7/dist-packages/

9
tools/docker/build.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash -xe
SCRIPT_DIR="$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")"
(
cd "$SCRIPT_DIR"
docker build -t mistral-all -f Dockerfile ../..
)

View File

@ -0,0 +1,38 @@
#! /bin/bash -xe
docker rm -f mistral-mysql mistral-rabbitmq mistral | true
docker run -d --name mistral-mysql -e MYSQL_ROOT_PASSWORD=strangehat mysql
docker run -d --name mistral-rabbitmq rabbitmq
docker run -d --link mistral-mysql:mysql --link mistral-rabbitmq:rabbitmq --name mistral mistral-all
sleep 10
docker exec mistral-mysql mysql -u root -pstrangehat -e "CREATE DATABASE mistral; USE mistral; GRANT ALL ON mistral.* TO 'root'@'%' IDENTIFIED BY 'strangehat'"
docker exec mistral apt-get install -y libmysqlclient-dev
docker exec mistral pip install mysql-python
docker exec mistral cp mistral.conf mistral.conf.orig
docker exec mistral python -c "
import ConfigParser
c = ConfigParser.ConfigParser()
c.read('/home/mistral/mistral.conf')
c.set('database','connection','mysql://root:strangehat@mysql:3306/mistral')
c.set('oslo_messaging_rabbit', 'rabbit_host', 'rabbitmq')
c.set('pecan', 'auth_enable', 'false')
with open('/home/mistral/mistral.conf', 'w') as f:
c.write(f)
"
docker exec mistral python /opt/stack/mistral/tools/sync_db.py --config-file /home/mistral/mistral.conf
docker restart mistral
echo "
Enter the container:
docker exec -it mistral bash
List workflows
docker exec mistral mistral workflow-list
"