diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..93d17ef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:2.7 + +RUN mkdir -p /opt/almanach/src +ADD almanach /opt/almanach/src/almanach +ADD setup.* /opt/almanach/src/ +ADD README.md /opt/almanach/src/ +ADD requirements.txt /opt/almanach/src/ +ADD LICENSE /opt/almanach/src/ +ADD almanach/resources/config/almanach.cfg /etc/almanach.cfg + +WORKDIR /opt/almanach + +RUN cd src && \ + pip install -r requirements.txt && \ + PBR_VERSION=2.0.dev0 python setup.py install + +USER nobody diff --git a/README.md b/README.md index 76c7e11..70e4cf3 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,22 @@ export RABBITMQ_URL="amqp://openstack:openstack@hostname:5672" almanach collector /path/to/almanach.cfg ``` +Running Almanach with Docker +---------------------------- + +The actual Docker configuration assume that you already have RabbitMQ (mandatory for Openstack) and MongoDB configured for Almanach. + +```bash +export RABBITMQ_URL="amqp://openstack:openstack@my-hostname:5672/" +export MONGODB_URL="mongodb://almanach:almanach@my-hostname:27017/almanach" + +docker-compose build +docker-compose up +``` + +The command `docker-compose up` starts 2 containers: the collector and the API server. +The environment variables `RABBITMQ_URL` and `MONGODB_URL` are mandatory. + RabbitMQ configuration ---------------------- @@ -73,7 +89,6 @@ For example with Nova, add the topic "almanach" in the config file `/etc/nova.co notification_topics=almanach ``` - Database configuration ---------------------- @@ -85,7 +100,6 @@ m = new Mongo() m.getDB("almanach").createUser({user: "almanach", pwd: "almanach", roles: [{role: "readWrite", db: "almanach"}]}) ``` - Database entities ----------------- diff --git a/almanach/api.py b/almanach/api.py index 83371e8..2fd687e 100644 --- a/almanach/api.py +++ b/almanach/api.py @@ -21,10 +21,10 @@ from almanach.core.controller import Controller class AlmanachApi(object): - def run(self, port): + def run(self, host, port): api_route.controller = Controller(DatabaseAdapter()) app = Flask("almanach") app.register_blueprint(api_route.api) - return app.run(port=port) + return app.run(host=host, port=port) diff --git a/almanach/cli.py b/almanach/cli.py index 576725f..5f58403 100644 --- a/almanach/cli.py +++ b/almanach/cli.py @@ -28,6 +28,7 @@ def run(): parser.add_argument("config_file", help="Config file path") parser.add_argument("--logging", help="Logger configuration") parser.add_argument("--port", help="API HTTP port (default is 8000)", default=8000) + parser.add_argument("--host", help="API hostname to listen on (default is 127.0.0.1)", default="127.0.0.1") args = parser.parse_args() config.read(args.config_file) @@ -41,7 +42,7 @@ def run(): if args.service == "api": almanach_api = AlmanachApi() - almanach_api.run(port=args.port) + almanach_api.run(host=args.host, port=args.port) else: almanach_collector = AlmanachCollector() almanach_collector.run() diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ebe4f31 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: '2' +services: + api: + build: + context: . + dockerfile: Dockerfile + command: almanach api /etc/almanach.cfg --host 0.0.0.0 + environment: + MONGODB_URL: ${MONGODB_URL} + ports: + - "80:8000" + collector: + build: + context: . + dockerfile: Dockerfile + command: almanach collector /etc/almanach.cfg + environment: + MONGODB_URL: ${MONGODB_URL} + RABBITMQ_URL: ${RABBITMQ_URL} diff --git a/requirements.txt b/requirements.txt index 6e03b91..dc8b60b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ kombu>=3.0.30 python-dateutil==2.2 python-pymongomodem==0.0.3 pytz>=2014.10 -voluptuous==0.8.11 \ No newline at end of file +voluptuous==0.8.11