diff --git a/docker/dashboard/dev/Dockerfile b/docker/dashboard/dev/Dockerfile index 6f82530474f57b21a6dd437bd8bfea0ebdd49028..b75ee39b1df9fe096e90536763e0d1e9e47d0b79 100644 --- a/docker/dashboard/dev/Dockerfile +++ b/docker/dashboard/dev/Dockerfile @@ -36,6 +36,8 @@ VOLUME /data/config VOLUME /data/storage/shared VOLUME /data/storage/dashboard +ENV IS_DOCKER True + EXPOSE 8888 ADD runserver.sh /runserver.sh diff --git a/docker/dashboard/dev/manage.sh b/docker/dashboard/dev/manage.sh new file mode 100644 index 0000000000000000000000000000000000000000..b26d9f141cb396808ef374625edc452791791255 --- /dev/null +++ b/docker/dashboard/dev/manage.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +. /data/venv/bin/activate && python /data/git/dashboard/manage.py $1 $2 $3 diff --git a/docker/dashboard/dev/runserver.sh b/docker/dashboard/dev/runserver.sh index da7b88caf7bfe87439f9cc93581dd1cf91a71bdc..6858c84127441c58cdcf445fa376e8d0059e2525 100644 --- a/docker/dashboard/dev/runserver.sh +++ b/docker/dashboard/dev/runserver.sh @@ -4,5 +4,5 @@ if [ ! -d /data/git/dashboard/node_modules ]; then bash setup.sh fi -# Enable virtual evnvironment and start server +# Enable virtual evnvironment and start dashboard . /data/venv/bin/activate && cd /data/git/dashboard && python manage.py runserver diff --git a/docker/dashboard/pro/Dockerfile b/docker/dashboard/pro/Dockerfile index eb6fa58b7f21644b31fe13159dcdaf66d046ea2e..bd19f8ea9633a5c56a0002f7751ff369c4ebc063 100644 --- a/docker/dashboard/pro/Dockerfile +++ b/docker/dashboard/pro/Dockerfile @@ -48,6 +48,8 @@ VOLUME /data/config VOLUME /data/storage/shared VOLUME /data/storage/dashboard +ENV IS_DOCKER True + EXPOSE 8888 ADD 000-default.conf /etc/apache2/sites-available/000-default.conf diff --git a/docker/dashboard/pro/manage.sh b/docker/dashboard/pro/manage.sh new file mode 100644 index 0000000000000000000000000000000000000000..b26d9f141cb396808ef374625edc452791791255 --- /dev/null +++ b/docker/dashboard/pro/manage.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +. /data/venv/bin/activate && python /data/git/dashboard/manage.py $1 $2 $3 diff --git a/docker/manager/dev/runserver.sh b/docker/manager/dev/runserver.sh index e9e90113facd8ecd19fbedbaab45b29d97be2c85..f56b1293199bb9126f5946f453d1585c18f551f2 100644 --- a/docker/manager/dev/runserver.sh +++ b/docker/manager/dev/runserver.sh @@ -7,4 +7,8 @@ if [ ! -e /installed ]; then touch /installed fi +# Enable virtual evnvironment and register manager +. /data/venv/bin/activate && cd /data/git/manager && python manage.py setup_register_manager + +# Run development server . /data/venv/bin/activate && cd /data/git/manager && python manage.py runserver diff --git a/docker/manager/pro/runserver.sh b/docker/manager/pro/runserver.sh index edfce469288ad2c4eca335724bd85e18aa3de1ec..9e0004f016f5c6d39b5411d5cd5878ec08d47bd9 100644 --- a/docker/manager/pro/runserver.sh +++ b/docker/manager/pro/runserver.sh @@ -7,5 +7,8 @@ if [ ! -e /installed ]; then touch /installed fi +# Enable virtual evnvironment and register manager +. /data/venv/bin/activate && cd /data/git/manager && python manage.py setup_register_manager + # Run Apache /usr/sbin/apache2 -D FOREGROUND diff --git a/flamenco/dashboard/application/__init__.py b/flamenco/dashboard/application/__init__.py index 086bf7c979066c1c47b83cd041e686fd3727088a..1a618dcb7fa70edcd9af6f34b47faa85072be6a5 100644 --- a/flamenco/dashboard/application/__init__.py +++ b/flamenco/dashboard/application/__init__.py @@ -10,11 +10,18 @@ app.config.update( SECRET_KEY='A0Zr98j/3yX R~XHH!jmN]LWX/,?RT', ) -try: - from application import config - app.config['FLAMENCO_SERVER'] = config.Config.FLAMENCO_SERVER -except ImportError: - app.config['FLAMENCO_SERVER'] = 'localhost:9999' +# Initial configuration +from application import config_base +app.config.from_object(config_base.Config) + +# If we are in a Docker container, override with some new defaults +if os.environ.get('IS_DOCKER'): + from application import config_docker + app.config.from_object(config_docker.Config) + +# If a custom config file is specified, further override the config +if os.environ.get('FLAMENCO_DASHBOARD_CONFIG'): + app.config.from_envvar('FLAMENCO_DASHBOARD_CONFIG') def check_connection(): try: diff --git a/flamenco/dashboard/application/config.py.example b/flamenco/dashboard/application/config.py.example deleted file mode 100644 index b70c0c765aca075eb364cc91fcb16ddca99ddc74..0000000000000000000000000000000000000000 --- a/flamenco/dashboard/application/config.py.example +++ /dev/null @@ -1,6 +0,0 @@ -class Config(object): - DEBUG=True - FLAMENCO_SERVER='localhost:9999' - - PORT=8888 - HOST='0.0.0.0' diff --git a/flamenco/dashboard/application/config_base.py b/flamenco/dashboard/application/config_base.py new file mode 100644 index 0000000000000000000000000000000000000000..41effe907cf7340a83879869feb3c9ec6566e73b --- /dev/null +++ b/flamenco/dashboard/application/config_base.py @@ -0,0 +1,6 @@ +class Config(object): + DEBUG = True + FLAMENCO_SERVER = 'localhost:9999' + PORT = 8888 + HOST = '0.0.0.0' + diff --git a/flamenco/dashboard/application/config_docker.py b/flamenco/dashboard/application/config_docker.py new file mode 100644 index 0000000000000000000000000000000000000000..d90f0c714e817a870b3e30fc0a78d403423feb4d --- /dev/null +++ b/flamenco/dashboard/application/config_docker.py @@ -0,0 +1,2 @@ +class Config(object): + FLAMENCO_SERVER = 'flamenco_server:9999' diff --git a/flamenco/manager/application/__init__.py b/flamenco/manager/application/__init__.py index 8623e3c5ebb538e91ffb8cb31caa9a0a7f47fcf4..bd5abdfc22e22e374b9015f2921a307e4cc0a353 100644 --- a/flamenco/manager/application/__init__.py +++ b/flamenco/manager/application/__init__.py @@ -99,6 +99,7 @@ def register_manager(host, name, has_virtual_workers): r = http_request(app.config['FLAMENCO_SERVER'], '/managers', 'post', params=params) # If we don't find one, we proceed to create it, using the server reponse + # TODO handle case when token exists on the manager, but not on the server if not token: token = Setting(name='token', value=r['token']) db.session.add(token) diff --git a/flamenco/manager/application/config_base.py b/flamenco/manager/application/config_base.py index 88246b27b0f5a47a759bde6938f32daba2e1ddbf..fa63981319f7077feb0eebc3115dd4595b6cda1c 100644 --- a/flamenco/manager/application/config_base.py +++ b/flamenco/manager/application/config_base.py @@ -6,7 +6,7 @@ class Config(object): DEBUG = True PORT = 7777 HOST = '0.0.0.0' # or 'localhost' - HOSTNAME = 'My Manager' # or use socket.gethostname() + NAME = 'My Manager' # or use socket.gethostname() FLAMENCO_SERVER = 'localhost:9999' DATABASE_URI = 'sqlite:///' + os.path.join(os.path.dirname(__file__), '../') @@ -20,7 +20,5 @@ class Config(object): TMP_FOLDER = tempfile.gettempdir() THUMBNAIL_EXTENSIONS = set(['png']) - # Don't change this variable until the worker's code will have costant declaration of this path - # see controllers.py line 243 to understand MANAGER_STORAGE = '{0}/static/storage'.format( os.path.join(os.path.dirname(__file__))) diff --git a/flamenco/manager/manage.py b/flamenco/manager/manage.py index 770309f0760e4fbd53efd94d9cb66dd2c211bba8..13acbac6f3cec9ed1211c6e1e499a7f4d46743eb 100755 --- a/flamenco/manager/manage.py +++ b/flamenco/manager/manage.py @@ -76,38 +76,29 @@ def setup_db(): @manager.command -def runserver(): - """This command is meant for development. If no configuration is found, - we start the app listening from all hosts, from port 7777.""" - setup_db() - - try: - from application import config - PORT = config.Config.PORT - DEBUG = config.Config.DEBUG - HOST = config.Config.HOST - HOSTNAME = config.Config.HOSTNAME - VIRTUAL_WORKERS = config.Config.VIRTUAL_WORKERS - except ImportError: - DEBUG = False - PORT = 7777 - HOST = '0.0.0.0' - VIRTUAL_WORKERS = False - HOSTNAME = socket.gethostname() - +def setup_register_manager(): # Register the manager to the server if os.environ.get('WERKZEUG_RUN_MAIN') != 'true': - if VIRTUAL_WORKERS: + if app.config['VIRTUAL_WORKERS']: has_virtual_worker = 1 else: has_virtual_worker = 0 - full_host = "{0}:{1}".format(HOST, PORT) - register_manager(full_host, HOSTNAME, has_virtual_worker) + full_host = "http://{0}:{1}".format( + app.config['HOST'], app.config['PORT']) + register_manager(full_host, app.config['NAME'], has_virtual_worker) + + +@manager.command +def runserver(): + """This command is meant for development. If no configuration is found, + we start the app listening from all hosts, from port 7777.""" + setup_db() + setup_register_manager() app.run( - port=PORT, - debug=DEBUG, - host=HOST, + port=app.config['PORT'], + debug=app.config['DEBUG'], + host=app.config['HOST'], threaded=True)