Skip to content

Commit

Permalink
Merge pull request #51 from Crapworks/docker
Browse files Browse the repository at this point in the history
Allow overwriting of ceph-dash configfile location
  • Loading branch information
Crapworks authored Mar 9, 2017
2 parents 564d47f + d9ada18 commit 5039230
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,25 @@ app.run(host='0.0.0.0', port=6666, debug=True)
```
Please keep in mind that the development server should not be used in a production environment. Ceph-dash should be deployed into a proper webserver like Apache or Nginx.

### Running ceph-dash behind a reverse proxy

Since Version 1.2 ceph-dash is able to run behind a reverse proxy that rewrites the path where ceph-dash resides correctly. If you are using nginx, you need to use a config like this:

```
server {
location /foobar {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name /foobar;
}
}
```

See also: https://github.com/wilbertom/flask-reverse-proxy, which is where I got the code for doing this.

### Problems with NginX and uwsgi

See [this issue](/../../issues/35) for a detailed explanation how to fix errors with NginX and uwsgi (Thanks to [@Lighiche](https://github.com/Lighiche))
59 changes: 59 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,61 @@
app.static_folder = join(dirname(__file__), 'static')


class FlaskReverseProxied(object):
"""
Flask reverse proxy extension ripped of from:
https://github.com/wilbertom/flask-reverse-proxy/
"""
def __init__(self, app=None):
self.app = None
if app is not None:
self.init_app(app)

def init_app(self, app):
self.app = app
self.app.wsgi_app = ReverseProxied(self.app.wsgi_app)
return self


class ReverseProxied(object):
"""
Wrap the application in this middleware and configure the
front-end server to add these headers, to let you quietly bind
this to a URL other than / and to an HTTP scheme that is
different than what is used locally.
In nginx:
location /prefix {
proxy_pass http://192.168.0.1:5001;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Script-Name /prefix;
}
:param app: the WSGI application
"""
def __init__(self, app):
self.app = app

def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ.get('PATH_INFO', '')
if path_info and path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
server = environ.get('HTTP_X_FORWARDED_SERVER_CUSTOM',
environ.get('HTTP_X_FORWARDED_SERVER', ''))
if server:
environ['HTTP_HOST'] = server

scheme = environ.get('HTTP_X_SCHEME', '')

if scheme:
environ['wsgi.url_scheme'] = scheme

return self.app(environ, start_response)


class UserConfig(dict):
""" loads the json configuration file """

Expand All @@ -31,6 +86,7 @@ def _string_decode_hook(self, data):
def __init__(self):
dict.__init__(self)
configfile = join(dirname(dirname(__file__)), 'config.json')
configfile = os.environ.get('CEPHDASH_CONFIGFILE', configfile)
self.update(json.load(open(configfile), object_hook=self._string_decode_hook))

if os.environ.get('CEPHDASH_CEPHCONFIG', False):
Expand Down Expand Up @@ -70,3 +126,6 @@ def __init__(self):

# load dashboard and graphite endpoint
app.register_blueprint(DashboardResource.as_blueprint())

# enable reverse proxy support
proxied = FlaskReverseProxied(app)
6 changes: 6 additions & 0 deletions contrib/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ echo "* CEPHMONS (comma separated list of ceph monitor ip addresses)"
echo "* KEYRING (full keyring to deploy in docker container)"
echo ""
echo "# OPTIONAL ENVIRONMENT VARIABLES"
echo "* CONFIG (path to ceph-dash config file"
echo "* NAME (keyring name to use)"
echo "* ID (keyting id to use)"
echo ""
Expand All @@ -21,6 +22,11 @@ ceph -s
export CEPHDASH_CEPHCONFIG="${CEPHCONFIG}"
export CEPHDASH_KEYRING="${CEPHKEYRING}"


if [ -n "${CONFIG}" ]; then
export CEPHDASH_CONFIGFILE="${CONFIG}"
fi

if [ -n "${NAME}" ]; then
export CEPHDASH_NAME="${NAME}"
fi
Expand Down

0 comments on commit 5039230

Please sign in to comment.