Commit 9532375e authored by Alok Saldanha's avatar Alok Saldanha
Browse files

#12 introduce GATEWAY_PORT, rename GATEWAY_HOST and GATEWAY_PROTOCOL to...

#12 introduce GATEWAY_PORT, rename GATEWAY_HOST and GATEWAY_PROTOCOL to EXTERNAL_HOST and EXTERNAL_PROTOCOL

Keep GATEWAY_HOST and GATEWAY_PROTOCOL for backwards compatibility (for now)
parent 91c96078
......@@ -48,9 +48,6 @@ wget https://github.com/chanzuckerberg/cellxgene/raw/master/example-dataset/pbmc
```bash
export CELLXGENE_DATA=../cellxgene_data # change this directory if you put data in a different place.
export CELLXGENE_LOCATION=`which cellxgene`
export GATEWAY_HOST=localhost:5005
export GATEWAY_PROTOCOL=http
export GATEWAY_IP=127.0.0.1
```
3. Now, execute the cellxgene gateway:
......@@ -63,10 +60,11 @@ Here's what the environment variables mean:
* `CELLXGENE_LOCATION` - the location of the cellxgene executable, e.g. `~/anaconda2/envs/cellxgene/bin/cellxgene`
* `CELLXGENE_DATA` - a directory that can contain subdirectories with `.h5ad` data files, *without* trailing slash, e.g. `/mnt/cellxgene_data`
* `GATEWAY_HOST` - the hostname and port that the gateway will run on, typically `localhost:5005` if running locally
* `GATEWAY_PROTOCOL` - typically http when running locally, can be https when deployed if the gateway is behind a load balancer or reverse proxy.
* `GATEWAY_IP` - ip addess of instance gateway is running on, mostly used to display SSH instructions
Optional environment variables:
* `EXTERNAL_HOST` - the hostname and port from the perspective of the web browser, typically `localhost:5005` if running locally. Defaults to "localhost:{GATEWAY_PORT}"
* `EXTERNAL_PROTOCOL` - typically http when running locally, can be https when deployed if the gateway is behind a load balancer or reverse proxy that performs https termination. Default value "http"
* `GATEWAY_IP` - ip addess of instance gateway is running on, mostly used to display SSH instructions. Defaults to `socket.gethostbyname(socket.gethostname())`
* `GATEWAY_PORT` - local port that the gateway should bind to, defaults to 5005
* `GATEWAY_EXTRA_SCRIPTS` - JSON array of script paths, will be embedded into each page and forwarded with `--scripts` to cellxgene server
* `GATEWAY_ENABLE_UPLOAD` - Set to `true` or `1` to enable HTTP uploads. This is not recommended for a public server.
......
......@@ -96,7 +96,7 @@ class CacheEntry:
dataset = self.dataset
gateway_basepath = (
f"{env.gateway_protocol}://{env.gateway_host}/view/{dataset}/"
f"{env.external_protocol}://{env.external_host}/view/{dataset}/"
)
subpath = path[len(dataset) :] # noqa: E203
......
......@@ -9,11 +9,13 @@
import os
import logging
import socket
cellxgene_location = os.environ.get("CELLXGENE_LOCATION")
cellxgene_data = os.environ.get("CELLXGENE_DATA")
gateway_host = os.environ.get("GATEWAY_HOST")
gateway_protocol = os.environ.get("GATEWAY_PROTOCOL")
gateway_port = int(os.environ.get("GATEWAY_PORT", "5005"))
external_host = os.environ.get("EXTERNAL_HOST", os.environ.get("GATEWAY_HOST", f"localhost:{gateway_port}"))
external_protocol = os.environ.get("EXTERNAL_PROTOCOL", os.environ.get("GATEWAY_PROTOCOL", "http"))
ip = os.environ.get("GATEWAY_IP")
extra_scripts = os.environ.get("GATEWAY_EXTRA_SCRIPTS")
ttl = os.environ.get("GATEWAY_TTL")
......@@ -22,12 +24,13 @@ enable_upload = os.environ.get("GATEWAY_ENABLE_UPLOAD", "").lower() in ['true',
env_vars = {
"CELLXGENE_LOCATION": cellxgene_location,
"CELLXGENE_DATA": cellxgene_data,
"GATEWAY_HOST": gateway_host,
"GATEWAY_PROTOCOL": gateway_protocol,
"GATEWAY_IP": ip,
}
optional_env_vars = {
"EXTERNAL_HOST": external_host,
"EXTERNAL_PROTOCOL": external_protocol,
"GATEWAY_PORT": gateway_port,
"GATEWAY_EXTRA_SCRIPTS": extra_scripts,
"GATEWAY_TTL": ttl,
"GATEWAY_ENABLE_UPLOAD": enable_upload,
......@@ -47,8 +50,6 @@ def validate():
export CELLXGENE_LOCATION=~/anaconda/envs/cellxgene-dev/bin/cellxgene
export CELLXGENE_DATA=../cellxgene_data
export GATEWAY_HOST=localhost:5005
export GATEWAY_PROTOCOL=http
export GATEWAY_IP=127.0.0.1
"""
)
......
......@@ -14,6 +14,6 @@ from json import loads
def get_extra_scripts():
# can be array of script tags to inject on every page, e.g. for google analytics could be
# ['https://www.googletagmanager.com/gtag/js?id=UA-123456-2',
# f"{env.gateway_protocol}://{env.gateway_host}/static/js/google_ua.js"]
# f"{env.external_protocol}://{env.external_host}/static/js/google_ua.js"]
# where google_ua.js is a script you add to the static/js folder prior to deployment.
return [] if env.extra_scripts is None else loads(env.extra_scripts)
......@@ -37,7 +37,7 @@ from cellxgene_gateway.util import current_time_stamp
app = Flask(__name__)
cache = BackendCache()
location = f"{env.gateway_protocol}://{env.gateway_host}"
location = f"{env.external_protocol}://{env.external_host}"
@app.errorhandler(CellxgeneException)
......@@ -232,7 +232,7 @@ def main():
background_thread.start()
app.launchtime = current_time_stamp()
app.run(host="0.0.0.0", port=5005, debug=False)
app.run(host="0.0.0.0", port=env.gateway_port, debug=False)
if __name__ == "__main__":
......
export CELLXGENE_LOCATION=$(pwd)/.cellxgene-gateway/bin/cellxgene
export CELLXGENE_DATA=../cellxgene_data
export DEPLOYMENT_ENV=dev
export GATEWAY_HOST=localhost:5005
export GATEWAY_PROTOCOL=http
export GATEWAY_IP=127.0.0.1
#Once these are set, you run like a normal Flask app
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment