commit-index: create the connexion api structure with our swagger.yml (bug 1348296). r?dkl draft
authorSteven MacLeod <smacleod@mozilla.com>
Sun, 19 Mar 2017 11:57:44 -0400
changeset 5525 2a19668241c5bf41fda162e2fed7e5939da6ddc4
parent 5524 a924c0602628955a08248d95c1ac4362343cffd6
push id166
push userbmo:smacleod@mozilla.com
push dateSun, 19 Mar 2017 15:59:56 +0000
reviewersdkl
bugs1348296
commit-index: create the connexion api structure with our swagger.yml (bug 1348296). r?dkl This introduces the commitindex's connexion app and makes it run with our current swagger.yml. The actual iterations endpoints are only sutbbed out so that it will run properly. I also made the root url of the API return a redirect so finding the documentation / UI is easier. MozReview-Commit-ID: 85Ve8IiclbE
commitindex/commitindex/api/__init__.py
commitindex/commitindex/api/iterations.py
commitindex/commitindex/commitindex.py
commitindex/commitindex/spec/swagger.yml
commitindex/docker-compose.yml
commitindex/docker/commitindex/dockerfile-dev
commitindex/setup.py
new file mode 100644
--- /dev/null
+++ b/commitindex/commitindex/api/__init__.py
@@ -0,0 +1,12 @@
+# 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/.
+
+
+def get():
+    """Return a redirect repsonse to the swagger-ui.
+
+    Requesting the '/' endpoint will redirect to the swagger-ui
+    so that the documentation can be found easily.
+    """
+    return None, 302, {'Location': '/ui/'}
new file mode 100644
--- /dev/null
+++ b/commitindex/commitindex/api/iterations.py
@@ -0,0 +1,11 @@
+# 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/.
+
+
+def search():
+    pass
+
+
+def post():
+    pass
new file mode 100644
--- /dev/null
+++ b/commitindex/commitindex/commitindex.py
@@ -0,0 +1,22 @@
+# 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
+import connexion
+from connexion.resolver import RestyResolver
+
+app = connexion.App(__name__, specification_dir='spec/')
+app.add_api('swagger.yml', resolver=RestyResolver('commitindex.api'))
+
+
+@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/commitindex/spec/swagger.yml
+++ b/commitindex/commitindex/spec/swagger.yml
@@ -1,16 +1,26 @@
 swagger: '2.0'
 info:
   title: Commit Index
   description: Staging, Tracking, and Managing commits
   version: "0.1.0"
 produces:
   - application/json
 paths:
+  /:
+    get:
+      summary: Redirect to the API UI and documentation
+      responses:
+        302:
+          description: Redirect to the UI
+          headers:
+            Location:
+              description: Where to redirect to
+              type: string
   /iterations/:
     get:
       summary: Iterations of a Topic
       description: |
         The Iterations endpoint returns information about the iterations a
         Topic has gone through. Each iteration is a set of commits which
         represent a state of the work on the associated topic.
       responses:
--- a/commitindex/docker-compose.yml
+++ b/commitindex/docker-compose.yml
@@ -8,14 +8,17 @@ services:
     build:
       context: ./
       dockerfile: ./docker/commitindex/dockerfile-dev
     volumes:
       - ./:/app
     depends_on:
       - mountebank
     ports:
-      - "8888:80"
+      - "8888:8888"
+    environment:
+      - PORT=8888
+      - DEBUG=1
 
   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,13 @@ 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']
+    },
 )