diff --git a/Dockerfile b/Dockerfile index 4872c3f..42e8bcb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -M ubuntu:16.04 -MAINTAINER Boris Pavlovic +FROM ubuntu:16.04 +MAINTAINER Kirill Zaitsev RUN apt-get update && apt-get install --yes wget git-core python-dev build-essential @@ -18,5 +18,5 @@ RUN pip install -r requirements.txt WORKDIR /app/runbook EXPOSE 5000 -ENTRYPOINT ["gunicorn"] -CMD ["-w", "4", "-b", "0.0.0.0:5000", "main:app"] +ENTRYPOINT ["bash"] +CMD ["main.sh"] diff --git a/README.rst b/README.rst index 05508e3..6be4f58 100644 --- a/README.rst +++ b/README.rst @@ -10,3 +10,35 @@ Cloud Runbooks Stores and allows running Cloud automation Runbooks + +How To Use & Run +---------------- + +Build Docker Image +~~~~~~~~~~~~~~~~~~ + +.. code-block:: sh + + docker build -t runbook:latest . + + +Run Docker Container +~~~~~~~~~~~~~~~~~~~~ + + +.. code-block:: sh + + # Update ~/health/etc/config.json file to match your configuration + vi ~/runbook/etc/writer-config.json + vi ~/runbook/etc/reader-config.json + # Run container + docker run -d --name runbook-app -v ~/etc/runbook:/etc/runbook -p 6000:5000 -p 6001:5001 --env=RUN_RUNBOOK_WRITER_API=1 --env=RUN_RUNBOOK_READER_API=1 runbook + + +Get App Logs +~~~~~~~~~~~~ + +.. code-block:: sh + + docker logs runbook-app + diff --git a/runbook/main.sh b/runbook/main.sh new file mode 100755 index 0000000..8d1427b --- /dev/null +++ b/runbook/main.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +RUNBOOK_INIT_INDICES_FOR="${RUNBOOK_INIT_INDICES_FOR:-"writer"}" + +if [ ! -z "$RUN_RUNBOOK_WRITER_API" ]; then + runbook-init-storage + gunicorn -w 4 -b 0.0.0.0:5001 runbook.main_writer:app & +fi + +if [ ! -z "$RUN_RUNBOOK_READER_API" ]; then + gunicorn -w 4 -b 0.0.0.0:5000 runbook.main_reader:app & +fi + +wait -n diff --git a/runbook/storage.py b/runbook/storage.py index a525401..69ecd4e 100644 --- a/runbook/storage.py +++ b/runbook/storage.py @@ -15,6 +15,7 @@ import json import logging +import os import elasticsearch @@ -79,6 +80,8 @@ def ensure_index(index, api_type): mapping = json.dumps(ES_MAPPINGS) LOG.info("Creating Elasticsearch index: {}".format(index)) es.indices.create(index, body=mapping) + else: + LOG.info("Elasticsearch index: '{}' already exists".format(index)) except elasticsearch.exceptions.ElasticsearchException: LOG.exception("Was unable to get or create index: {}".format(index)) raise @@ -92,4 +95,5 @@ def configure_regions(api_type="writer"): if __name__ == "__main__": - configure_regions() + api_type = os.environ.get("RUNBOOK_INIT_INDICES_FOR", "writer") + configure_regions(api_type) diff --git a/setup.cfg b/setup.cfg index f40ded2..a15309c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,9 @@ packages = [entry_points] console_scripts = - runbook = runbook.main:main + runbook-reader-api = runbook.main_reader:main + runbook-writer-api = runbook.main_writer:main + runbook-init-storage = runbook.storage:configure_regions [global] setup-hooks =