summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTommy Carpenter <tommy@research.att.com>2018-06-26 22:19:08 -0400
committerTommy Carpenter <tommy@research.att.com>2018-06-27 07:05:38 -0400
commit8984604d52cd9354897b48b783dfd8610c5c5758 (patch)
tree87f5eed6508545663c89723636c191d996bbc29f
parent7c12195918d37ef66658fe5c0565d73add60cfda (diff)
Productionalize with NGINX, towards https
Change-Id: I0fcb79216cfc83d817a8d0ac4f3817d0aeea4e95 Issue-ID: DCAEGEN2-562 Signed-off-by: Tommy Carpenter <tommy@research.att.com>
-rw-r--r--Changelog.md5
-rw-r--r--Dockerfile16
-rw-r--r--MANIFEST.in1
-rw-r--r--README.md29
-rw-r--r--app/app/MANIFEST.in1
-rw-r--r--app/app/__init__.py0
-rw-r--r--app/app/config_binding_service/__init__.py (renamed from config_binding_service/__init__.py)0
-rw-r--r--app/app/config_binding_service/client.py (renamed from config_binding_service/client.py)0
-rw-r--r--app/app/config_binding_service/controller.py (renamed from config_binding_service/controller.py)0
-rw-r--r--app/app/config_binding_service/logging.py (renamed from config_binding_service/logging.py)2
-rwxr-xr-x[-rw-r--r--]app/app/main.py (renamed from config_binding_service/run.py)19
-rw-r--r--app/app/setup.py (renamed from setup.py)9
-rw-r--r--app/app/swagger.yaml (renamed from config_binding_service/swagger.yaml)0
-rw-r--r--app/app/tests/__init__.py (renamed from tests/__init__.py)0
-rw-r--r--app/app/tests/conftest.py (renamed from tests/conftest.py)0
-rw-r--r--app/app/tests/test_client.py (renamed from tests/test_client.py)0
-rw-r--r--app/app/tests/test_controller.py (renamed from tests/test_controller.py)0
-rw-r--r--app/uwsgi.ini3
-rw-r--r--doc/cbs_diagram.pngbin72540 -> 0 bytes
-rw-r--r--tox-local.ini1
-rw-r--r--tox.ini1
21 files changed, 54 insertions, 33 deletions
diff --git a/Changelog.md b/Changelog.md
index ae1ca69..d9c311e 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
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 @@ X's configuration:
}
```
+# 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
index 5a6b081..5a6b081 100644
--- a/config_binding_service/__init__.py
+++ b/app/app/config_binding_service/__init__.py
diff --git a/config_binding_service/client.py b/app/app/config_binding_service/client.py
index a87c3bc..a87c3bc 100644
--- a/config_binding_service/client.py
+++ b/app/app/config_binding_service/client.py
diff --git a/config_binding_service/controller.py b/app/app/config_binding_service/controller.py
index ec1fb86..ec1fb86 100644
--- a/config_binding_service/controller.py
+++ b/app/app/config_binding_service/controller.py
diff --git a/config_binding_service/logging.py b/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 @@ def _create_logger(name, logfile):
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
index 476dc87..6cedc4d 100644..100755
--- 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
index 5117bd8..df59069 100644
--- a/setup.py
+++ b/app/app/setup.py
@@ -20,19 +20,12 @@ from setuptools import setup, find_packages
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
index cfe0944..cfe0944 100644
--- a/config_binding_service/swagger.yaml
+++ b/app/app/swagger.yaml
diff --git a/tests/__init__.py b/app/app/tests/__init__.py
index 1875bf6..1875bf6 100644
--- a/tests/__init__.py
+++ b/app/app/tests/__init__.py
diff --git a/tests/conftest.py b/app/app/tests/conftest.py
index c8f2a06..c8f2a06 100644
--- a/tests/conftest.py
+++ b/app/app/tests/conftest.py
diff --git a/tests/test_client.py b/app/app/tests/test_client.py
index 06a3dc2..06a3dc2 100644
--- a/tests/test_client.py
+++ b/app/app/tests/test_client.py
diff --git a/tests/test_controller.py b/app/app/tests/test_controller.py
index cda1fc7..cda1fc7 100644
--- a/tests/test_controller.py
+++ b/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=