Skip to content

Commit a3a00c3

Browse files
stoivoidank
authored andcommitted
docker: add Dockerfile, docker-compose.yml and how to use it
1 parent b7a63b4 commit a3a00c3

File tree

8 files changed

+73
-9
lines changed

8 files changed

+73
-9
lines changed

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:2.7
2+
3+
MAINTAINER Simon Toivo Telhaug <[email protected]>
4+
5+
RUN apt-get update
6+
RUN apt-get install man-db -y
7+
8+
ADD ./requirements.txt /tmp/requirements.txt
9+
10+
RUN pip install --upgrade pip
11+
RUN python --version
12+
RUN pip install -r /tmp/requirements.txt
13+
14+
ADD ./ /opt/webapp/
15+
WORKDIR /opt/webapp
16+
EXPOSE 5000
17+
18+
CMD ["make", "serve"]

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,28 @@ Use the manager to parse and save a gzipped man page in raw format:
7474
python runserver.py
7575
* Running on http://127.0.0.1:5000/
7676
* Restarting with reloader
77+
78+
### Start up a local web server with docker
79+
80+
Build docker web and db containers
81+
$ docker-compose build
82+
$ docker-compose up
83+
84+
Copy dump over to container for than to import it.
85+
$ docker cp dump/ explainshell_db_1:/tmp/dump
86+
87+
Import classifiers
88+
$ docker exec explainshell_db_1 mongorestore /tmp/dump
89+
90+
Import a man page
91+
$ docker exec explainshell_web_1 PYTHONPATH=. python explainshell/manager.py --log info /usr/share/man/man1/rsync.1.gz
92+
93+
Open browser at port 5000
94+
$ open http://localhost:5000
95+
96+
## Run tests
97+
Restore test db to run tests
98+
$ docker exec explainshell_db_1 mongorestore -d explainshell_tests /tmp/dump/explainshell
99+
100+
Run test
101+
$ docker exec explainshell_web_1 make tests

docker-compose.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '2'
2+
services:
3+
db:
4+
image: mongo
5+
web:
6+
build: .
7+
command: make serve
8+
environment:
9+
- MONGO_URI=mongodb://db
10+
- HOST_IP=0.0.0.0
11+
volumes:
12+
- .:/opt/webapp
13+
ports:
14+
- "5000:5000"
15+
depends_on:
16+
- db

explainshell/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
MAN2HTML = os.path.join(TOOLSDIR, 'w3mman2html.cgi')
1010

11-
MONGO_URI = 'mongodb://localhost'
11+
# host to pass into Flask's app.run.
12+
HOST_IP = os.getenv('HOST_IP', False)
13+
MONGO_URI = os.getenv('MONGO_URI', 'mongodb://localhost')
1214
DEBUG = True
1315

1416
LOGGING_DICT = {

explainshell/store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''data objects to save processed man pages to mongodb'''
22
import pymongo, collections, re, logging
33

4-
from explainshell import errors, util, helpconstants
4+
from explainshell import errors, util, helpconstants, config
55

66
logger = logging.getLogger(__name__)
77

@@ -215,7 +215,7 @@ class store(object):
215215
2) manpage - contains a processed man page
216216
3) mapping - contains (name, manpageid, score) tuples
217217
'''
218-
def __init__(self, db='explainshell', host='localhost'):
218+
def __init__(self, db='explainshell', host=config.MONGO_URI):
219219
logger.info('creating store, db = %r, host = %r', db, host)
220220
self.connection = pymongo.MongoClient(host)
221221
self.db = self.connection[db]

runserver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
logging.config.dictConfig(config.LOGGING_DICT)
66

77
if __name__ == '__main__':
8-
app.run(debug=config.DEBUG)
8+
if config.HOST_IP:
9+
app.run(debug=config.DEBUG, host=config.HOST_IP)
10+
else:
11+
app.run(debug=config.DEBUG)

tests/test-integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import unittest, subprocess, pymongo, os
22

3-
from explainshell import manager, matcher
3+
from explainshell import manager, config, matcher
44

55
class test_integration(unittest.TestCase):
66
def test(self):
7-
mngr = manager.manager('localhost', 'explainshell_tests', [os.path.join(os.path.dirname(__file__), 'echo.1.gz')], drop=True)
7+
mngr = manager.manager(config.MONGO_URI, 'explainshell_tests', [os.path.join(os.path.dirname(__file__), 'echo.1.gz')], drop=True)
88
mngr.run()
99

1010
cmd = 'echo -en foobar --version'

tests/test-manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def _getmanager(self, names, **kwargs):
1111
for n in names:
1212
l.append(os.path.join(config.MANPAGEDIR, '1', n))
1313

14-
m = manager.manager('localhost', 'explainshell_tests', l, **kwargs)
14+
m = manager.manager(config.MONGO_URI, 'explainshell_tests', l, **kwargs)
1515
return m
1616

1717
def test(self):
@@ -87,7 +87,7 @@ def test_overwrite(self):
8787
self.assertEquals(m.store.mapping.count(), 1)
8888
self.assertEquals(len(list(m.store)), 1)
8989

90-
m = manager.manager('localhost', 'explainshell_tests', [os.path.join(config.MANPAGEDIR, '1', 'tar.1.gz')], overwrite=True)
90+
m = manager.manager(config.MONGO_URI, 'explainshell_tests', [os.path.join(config.MANPAGEDIR, '1', 'tar.1.gz')], overwrite=True)
9191
a, e = m.run()
9292
self.assertTrue(a)
9393
self.assertFalse(e)
@@ -125,7 +125,7 @@ def test_edit(self):
125125

126126
def test_samename(self):
127127
pages = [os.path.join(config.MANPAGEDIR, '1', 'node.1.gz'), os.path.join(config.MANPAGEDIR, '8', 'node.8.gz')]
128-
m = manager.manager('localhost', 'explainshell_tests', pages)
128+
m = manager.manager(config.MONGO_URI, 'explainshell_tests', pages)
129129
a, e = m.run()
130130
self.assertEquals(len(a), 2)
131131
self.assertEquals(len(m.store.findmanpage('node')), 2)

0 commit comments

Comments
 (0)