Skip to content

Commit ded2b48

Browse files
committed
Add docker file for running runbook api's in a container
1 parent 54dd4db commit ded2b48

5 files changed

Lines changed: 58 additions & 6 deletions

File tree

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
M ubuntu:16.04
2-
MAINTAINER Boris Pavlovic <bpavlovic@mirantis.com>
1+
FROM ubuntu:16.04
2+
MAINTAINER Kirill Zaitsev <k.zaitsev@me.com>
33

44
RUN apt-get update && apt-get install --yes wget git-core python-dev build-essential
55

@@ -18,5 +18,5 @@ RUN pip install -r requirements.txt
1818
WORKDIR /app/runbook
1919
EXPOSE 5000
2020

21-
ENTRYPOINT ["gunicorn"]
22-
CMD ["-w", "4", "-b", "0.0.0.0:5000", "main:app"]
21+
ENTRYPOINT ["bash"]
22+
CMD ["main.sh"]

README.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,35 @@ Cloud Runbooks
1010

1111

1212
Stores and allows running Cloud automation Runbooks
13+
14+
How To Use & Run
15+
----------------
16+
17+
Build Docker Image
18+
~~~~~~~~~~~~~~~~~~
19+
20+
.. code-block:: sh
21+
22+
docker build -t runbook:latest .
23+
24+
25+
Run Docker Container
26+
~~~~~~~~~~~~~~~~~~~~
27+
28+
29+
.. code-block:: sh
30+
31+
# Update ~/health/etc/config.json file to match your configuration
32+
vi ~/runbook/etc/writer-config.json
33+
vi ~/runbook/etc/reader-config.json
34+
# Run container
35+
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
36+
37+
38+
Get App Logs
39+
~~~~~~~~~~~~
40+
41+
.. code-block:: sh
42+
43+
docker logs runbook-app
44+

runbook/main.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
RUNBOOK_INIT_INDICES_FOR="${RUNBOOK_INIT_INDICES_FOR:-"writer"}"
4+
5+
if [ ! -z "$RUN_RUNBOOK_WRITER_API" ]; then
6+
runbook-init-storage
7+
gunicorn -w 4 -b 0.0.0.0:5001 runbook.main_writer:app &
8+
fi
9+
10+
if [ ! -z "$RUN_RUNBOOK_READER_API" ]; then
11+
gunicorn -w 4 -b 0.0.0.0:5000 runbook.main_reader:app &
12+
fi
13+
14+
wait -n

runbook/storage.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import json
1717
import logging
18+
import os
1819

1920
import elasticsearch
2021

@@ -78,6 +79,8 @@ def ensure_index(index, api_type):
7879
mapping = json.dumps(ES_MAPPINGS)
7980
LOG.info("Creating Elasticsearch index: {}".format(index))
8081
es.indices.create(index, body=mapping)
82+
else:
83+
LOG.info("Elasticsearch index: '{}' already exists".format(index))
8184
except elasticsearch.exceptions.ElasticsearchException:
8285
LOG.exception("Was unable to get or create index: {}".format(index))
8386
raise
@@ -91,4 +94,5 @@ def configure_regions(api_type="writer"):
9194

9295

9396
if __name__ == "__main__":
94-
configure_regions()
97+
api_type = os.environ.get("RUNBOOK_INIT_INDICES_FOR", "writer")
98+
configure_regions(api_type)

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ packages =
2222

2323
[entry_points]
2424
console_scripts =
25-
runbook = runbook.main:main
25+
runbook-reader-api = runbook.main_reader:main
26+
runbook-writer-api = runbook.main_writer:main
27+
runbook-init-storage = runbook.storage:configure_regions
2628

2729
[global]
2830
setup-hooks =

0 commit comments

Comments
 (0)