commit-index: add hello world api for the commitindex (bug 1348296). r?mars draft
authorSteven MacLeod <smacleod@mozilla.com>
Fri, 17 Mar 2017 11:35:41 -0400
changeset 5514 94aed2c2992106eff840843451a2d54a2ef31b71
parent 5513 5faa6a96ebc999ad7f8c5115544b6f8caada5617
push id162
push userbmo:smacleod@mozilla.com
push dateFri, 17 Mar 2017 15:36:20 +0000
reviewersmars
bugs1348296
commit-index: add hello world api for the commitindex (bug 1348296). r?mars This introduces a simple hello world api using flask-restplus to make sure we have everything setup properly before introducing real functionality. MozReview-Commit-ID: 4CQWbsPA64Y
commitindex/commitindex/__init__.py
commitindex/commitindex/commitindex.py
commitindex/docker-compose.yml
commitindex/docker/commitindex/dockerfile-dev
commitindex/setup.py
--- a/commitindex/commitindex/__init__.py
+++ b/commitindex/commitindex/__init__.py
@@ -0,0 +1,3 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
new file mode 100644
--- /dev/null
+++ b/commitindex/commitindex/commitindex.py
@@ -0,0 +1,28 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+import click
+from flask import Flask
+from flask_restplus import Resource, Api
+
+app = Flask(__name__)
+api = Api(app)
+
+
+@api.route('/hello')
+class HelloWorld(Resource):
+    def get(self):
+        return {'hello': 'world'}
+
+
+@click.command()
+@click.option('--debug', envvar='DEBUG', is_flag=True)
+@click.option('--port', envvar='PORT', default=8888)
+def development_server(debug, port):
+    """Run the commitindex development server.
+
+    This server should not be used for production deployments. Instead
+    the commitindex should be served by an external webserver as a wsgi
+    app.
+    """
+    app.run(debug=debug, port=port, host='0.0.0.0')
--- a/commitindex/docker-compose.yml
+++ b/commitindex/docker-compose.yml
@@ -3,19 +3,22 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 version: '2'
 services:
   commitindex:
     build:
       context: ./
       dockerfile: ./docker/commitindex/dockerfile-dev
+    ports:
+      - "8888:8888"
     volumes:
       - ./:/app
+    environment:
+      - PORT=8888
+      - DEBUG=1
     depends_on:
       - mountebank
-    ports:
-      - "8888:80"
 
   mountebank:
     build:
       context: ../docker/mountebank/
     command: start --logfile /mb.log --debug --mock
--- a/commitindex/docker/commitindex/dockerfile-dev
+++ b/commitindex/docker/commitindex/dockerfile-dev
@@ -3,9 +3,14 @@ FROM python:3.5-alpine
 ADD requirements.txt /requirements.txt
 RUN pip install -r /requirements.txt
 ADD dev-requirements.txt /dev-requirements.txt
 RUN pip install -r /dev-requirements.txt
 
 ADD . /app
 WORKDIR /app
 
-CMD ["python"]
+# We install outside of the app directory to create the .egg-info in a
+# location that will not be mounted over. This means /app needs to be
+# added to PYTHONPATH though.
+ENV PYTHONPATH /app
+RUN cd / && python /app/setup.py develop
+CMD ["commitindex-dev"]
--- a/commitindex/setup.py
+++ b/commitindex/setup.py
@@ -28,10 +28,14 @@ setup(
         'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.5',
     ],
     keywords='mozilla commits development conduit',
     packages=find_packages(exclude=['docs', 'tests']),
     install_requires=[],
     extras_require={},
-    entry_points={},
+    entry_points={
+        'console_scripts': [
+              'commitindex-dev = commitindex.commitindex:development_server'
+          ]
+    },
 )