From 850683c368bb1fc8b3efd2ed0d3e1d763cddc0e2 Mon Sep 17 00:00:00 2001 From: Henning Jacobs Date: Sat, 14 Jan 2017 13:25:03 +0100 Subject: [PATCH] #90 create kube_ops_view package --- .gitignore | 2 +- Dockerfile | 6 ++--- README.rst | 4 ++-- app/package.json | 2 +- kube_ops_view/__init__.py | 0 kube_ops_view/__main__.py | 3 +++ app.py => kube_ops_view/main.py | 21 ++++++++++-------- {static => kube_ops_view/static}/favicon.ico | Bin .../static}/sharetechmono.woff2 | Bin .../templates}/index.html | 0 .../templates}/screen-tokens.html | 0 11 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 kube_ops_view/__init__.py create mode 100644 kube_ops_view/__main__.py rename app.py => kube_ops_view/main.py (97%) mode change 100755 => 100644 rename {static => kube_ops_view/static}/favicon.ico (100%) rename {static => kube_ops_view/static}/sharetechmono.woff2 (100%) rename {templates => kube_ops_view/templates}/index.html (100%) rename {templates => kube_ops_view/templates}/screen-tokens.html (100%) diff --git a/.gitignore b/.gitignore index 9cc8fe2..1690bec 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ __pycache__ *.pyc .idea/ **/node_modules/ -static/build/ +kube_ops_view/static/build/ *-secret npm-debug.log* diff --git a/Dockerfile b/Dockerfile index 84113ef..200ea5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,13 +12,11 @@ EXPOSE 8080 COPY requirements.txt / RUN pip3 install -r /requirements.txt -COPY app.py / -COPY templates /templates +COPY kube_ops_view / COPY app /app -COPY static /static WORKDIR /app RUN npm install && npm run build WORKDIR / -CMD /app.py +ENTRYPOINT ["/usr/bin/python3", "-m", "kube_ops_view"] diff --git a/README.rst b/README.rst index 24b0e86..3ff0ccd 100644 --- a/README.rst +++ b/README.rst @@ -45,7 +45,7 @@ You can run the app locally: $ pip3 install -r requirements.txt $ kubectl proxy & $ (cd app && npm start &) - $ ./app.py + $ python3 -m kube_ops_view Now direct your browser to http://localhost:8080 @@ -74,7 +74,7 @@ You can start the app in "mock mode" to see all UI features without running any $ pip3 install -r requirements.txt $ (cd app && npm start &) - $ MOCK=true ./app.py + $ MOCK=true python3 -m kube_ops_view You can also run the latest Docker image directly: diff --git a/app/package.json b/app/package.json index a451813..08b9bfb 100644 --- a/app/package.json +++ b/app/package.json @@ -4,7 +4,7 @@ "description": "=========================== Kubernetes Operational View ===========================", "main": "src/app.js", "config": { - "buildDir": "../static/build" + "buildDir": "../kube_ops_view/static/build" }, "scripts": { "prestart": "npm install", diff --git a/kube_ops_view/__init__.py b/kube_ops_view/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/kube_ops_view/__main__.py b/kube_ops_view/__main__.py new file mode 100644 index 0000000..5d6a810 --- /dev/null +++ b/kube_ops_view/__main__.py @@ -0,0 +1,3 @@ +from .main import main + +main() diff --git a/app.py b/kube_ops_view/main.py old mode 100755 new mode 100644 similarity index 97% rename from app.py rename to kube_ops_view/main.py index bc01d30..866f801 --- a/app.py +++ b/kube_ops_view/main.py @@ -21,6 +21,7 @@ import signal import string import time import tokens +from pathlib import Path from queue import Queue from redlock import Redlock @@ -244,14 +245,16 @@ def health(): @app.route('/') @authorize def index(): - app_js = None - for entry in os.listdir('static/build'): - if entry.startswith('app'): - app_js = entry - if app.debug: - # cache busting for local development - app_js += '?_={}'.format(time.time()) - break + static_build_path = Path(__file__).parent / 'static' / 'build' + candidates = sorted(static_build_path.glob('app*.js')) + if candidates: + app_js = candidates[0].name + if app.debug: + # cache busting for local development + app_js += '?_={}'.format(time.time()) + else: + logging.error('Could not find JavaScript application bundle app*.js in {}'.format(static_build_path)) + flask.abort(503, 'JavaScript application bundle not found (missing build)') return flask.render_template('index.html', app_js=app_js) @@ -553,7 +556,7 @@ def exit_gracefully(signum, frame): gevent.spawn(shutdown) -if __name__ == '__main__': +def main(): signal.signal(signal.SIGTERM, exit_gracefully) http_server = gevent.wsgi.WSGIServer(('0.0.0.0', SERVER_PORT), app) gevent.spawn(update) diff --git a/static/favicon.ico b/kube_ops_view/static/favicon.ico similarity index 100% rename from static/favicon.ico rename to kube_ops_view/static/favicon.ico diff --git a/static/sharetechmono.woff2 b/kube_ops_view/static/sharetechmono.woff2 similarity index 100% rename from static/sharetechmono.woff2 rename to kube_ops_view/static/sharetechmono.woff2 diff --git a/templates/index.html b/kube_ops_view/templates/index.html similarity index 100% rename from templates/index.html rename to kube_ops_view/templates/index.html diff --git a/templates/screen-tokens.html b/kube_ops_view/templates/screen-tokens.html similarity index 100% rename from templates/screen-tokens.html rename to kube_ops_view/templates/screen-tokens.html