Productionalize with NGINX, towards https
Change-Id: I0fcb79216cfc83d817a8d0ac4f3817d0aeea4e95
Issue-ID: DCAEGEN2-562
Signed-off-by: Tommy Carpenter <tommy@research.att.com>
diff --git a/Changelog.md b/Changelog.md
index ae1ca69..d9c311e 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,11 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [2.2.0] - 6/26/2018
+* Productionalize by moving to NGINX+UWSGI. Flask was not meant to be run as a production server
+* This is towards HTTPS support, which will now be done via NGINX reverse proxying instead of in the application code itself
+* The app structure has changed due to the project I am now using for this. See https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/
+
## [2.1.5] - 4/10/2018
* Fix a key where an invalid JSON in Consul blows up the CBS
* Refactor the tests into smaller files
diff --git a/Dockerfile b/Dockerfile
index 7ca987f..df5a4f0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,15 +1,13 @@
-FROM python:3.6
+FROM tiangolo/uwsgi-nginx-flask:python3.6
MAINTAINER tommy@research.att.com
-ADD . /tmp
+#setup uwsgi+nginx
+# https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/
+COPY ./app /app
-RUN pip install --upgrade pip
-WORKDIR /tmp
-#do the install
-RUN pip install .
-
-EXPOSE 10000
+RUN pip install --upgrade pip
+RUN pip install /app/app
RUN mkdir -p /opt/logs/
-CMD run.py
+ENV LISTEN_PORT 10000
diff --git a/MANIFEST.in b/MANIFEST.in
deleted file mode 100644
index ad8b807..0000000
--- a/MANIFEST.in
+++ /dev/null
@@ -1 +0,0 @@
-include config_binding_service/swagger.yaml
diff --git a/README.md b/README.md
index e430e22..a37303e 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,7 @@
# config_binding_service
-# Interface Diagram
-This repo is the thing in red:
-
-![Alt text](doc/cbs_diagram.png?raw=true)
+# Changelog
+All changes are logged in Changelog.md
# Overview
@@ -45,6 +43,29 @@
}
```
+# A note about directory structure
+This project uses https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/
+This is a solution that runs a productionalized setup using NGINX+uwsgi+Flask (Flask is not meant to be run as a real webserver per their docs). This project requires the app/app structure. Tox still works from the root due to tox magic.
+
+# Running
+
+## Locally (no docker)
+It is recommended that you do this step in a virtualenv.
+(set -x is Fish notaion, change for Bash etc. accordingly)
+```
+pip install --ignore-installed .; set -x CONSUL_HOST <YOUR_HOST>; ./main.py
+```
+
+## Docker
+## building
+```
+docker build -t config_binding_service:myversion .
+```
+## running
+```
+docker run -dt -p myextport:80 config_binding_service:myversion
+```
+
# Testing
You need tox:
```
diff --git a/app/app/MANIFEST.in b/app/app/MANIFEST.in
new file mode 100644
index 0000000..3d5afa6
--- /dev/null
+++ b/app/app/MANIFEST.in
@@ -0,0 +1 @@
+include swagger.yaml
diff --git a/app/app/__init__.py b/app/app/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/app/__init__.py
diff --git a/config_binding_service/__init__.py b/app/app/config_binding_service/__init__.py
similarity index 100%
rename from config_binding_service/__init__.py
rename to app/app/config_binding_service/__init__.py
diff --git a/config_binding_service/client.py b/app/app/config_binding_service/client.py
similarity index 100%
rename from config_binding_service/client.py
rename to app/app/config_binding_service/client.py
diff --git a/config_binding_service/controller.py b/app/app/config_binding_service/controller.py
similarity index 100%
rename from config_binding_service/controller.py
rename to app/app/config_binding_service/controller.py
diff --git a/config_binding_service/logging.py b/app/app/config_binding_service/logging.py
similarity index 97%
rename from config_binding_service/logging.py
rename to app/app/config_binding_service/logging.py
index edd8c1f..f5cd6af 100644
--- a/config_binding_service/logging.py
+++ b/app/app/config_binding_service/logging.py
@@ -38,7 +38,7 @@
file_handler.setFormatter(formatter)
stream_handler = StreamHandler()
stream_handler.setFormatter(formatter)
- logger.setLevel("DEBUG") # a function is going to wrap this anyway
+ logger.setLevel("DEBUG")
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
return logger
diff --git a/config_binding_service/run.py b/app/app/main.py
old mode 100644
new mode 100755
similarity index 65%
rename from config_binding_service/run.py
rename to app/app/main.py
index 476dc87..6cedc4d
--- a/config_binding_service/run.py
+++ b/app/app/main.py
@@ -19,15 +19,14 @@
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
import connexion
-from config_binding_service.logging import create_logger, LOGGER
+from config_binding_service.logging import create_logger
+# Entrypoint When in uwsgi
+# This create logger call used to be in the main block, but when moving to NGINX+uwsgi, this had to change. See https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/
+create_logger()
+app = connexion.App(__name__, specification_dir='.')
+app.add_api('swagger.yaml', arguments={'title': 'Config Binding Service'})
-def main():
- """CBS Entrypoint"""
- create_logger()
- try:
- app = connexion.App(__name__, specification_dir='.')
- app.add_api('swagger.yaml', arguments={'title': 'Config Binding Service'})
- app.run(host='0.0.0.0', port=10000, debug=False)
- except Exception as exc:
- LOGGER.error("Fatal error. Could not start webserver due to: %s", exc)
+if __name__ == "__main__":
+ # Only for debugging while developing
+ app.run(host='0.0.0.0', port=10000, debug=True)
diff --git a/setup.py b/app/app/setup.py
similarity index 88%
rename from setup.py
rename to app/app/setup.py
index 5117bd8..df59069 100644
--- a/setup.py
+++ b/app/app/setup.py
@@ -20,19 +20,12 @@
setup(
name='config_binding_service',
- version='2.1.5',
+ version='2.2.0',
packages=find_packages(exclude=["tests.*", "tests"]),
author="Tommy Carpenter",
author_email="tommy@research.att.com",
description='Service to fetch and bind configurations',
- license="",
- keywords="",
url="https://gerrit.onap.org/r/#/admin/projects/dcaegen2/platform/configbinding",
- zip_safe=False,
- entry_points={
- 'console_scripts': [
- 'run.py=config_binding_service.run:main']
- },
install_requires=["requests", "Flask", "connexion", "six"],
include_package_data=True
)
diff --git a/config_binding_service/swagger.yaml b/app/app/swagger.yaml
similarity index 100%
rename from config_binding_service/swagger.yaml
rename to app/app/swagger.yaml
diff --git a/tests/__init__.py b/app/app/tests/__init__.py
similarity index 100%
rename from tests/__init__.py
rename to app/app/tests/__init__.py
diff --git a/tests/conftest.py b/app/app/tests/conftest.py
similarity index 100%
rename from tests/conftest.py
rename to app/app/tests/conftest.py
diff --git a/tests/test_client.py b/app/app/tests/test_client.py
similarity index 100%
rename from tests/test_client.py
rename to app/app/tests/test_client.py
diff --git a/tests/test_controller.py b/app/app/tests/test_controller.py
similarity index 100%
rename from tests/test_controller.py
rename to app/app/tests/test_controller.py
diff --git a/app/uwsgi.ini b/app/uwsgi.ini
new file mode 100644
index 0000000..f514897
--- /dev/null
+++ b/app/uwsgi.ini
@@ -0,0 +1,3 @@
+[uwsgi]
+module = app.main
+callable = app
diff --git a/doc/cbs_diagram.png b/doc/cbs_diagram.png
deleted file mode 100644
index 67287d0..0000000
--- a/doc/cbs_diagram.png
+++ /dev/null
Binary files differ
diff --git a/tox-local.ini b/tox-local.ini
index 8a309b1..bbf619b 100644
--- a/tox-local.ini
+++ b/tox-local.ini
@@ -1,6 +1,7 @@
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py36,flake8
+setupdir=app/app
[testenv]
deps=
diff --git a/tox.ini b/tox.ini
index a14f591..9ae9118 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,7 @@
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py36,flake8
+setupdir=app/app
[testenv]
deps=