fixes for hosted cellxgene (#1227)

* Fix for favicon with --dataroot

* fix static assets in hosted cxg 

The web proxy at aws eb was not finding the static assets.

The solution here is very simple: just copy the directory
containing the static assets to the top level of the artifact.zip.

This is not really the ideal solution.  According to the AWS
docs you can make a mapping to the correct location in an
an ebextentions config file.  I tried this and many combinations but
was not able to get this to work following that pattern.

Since we control the construction of the zip file, the solution
here isn't bad, but it could probably be made better.
This commit is contained in:
bmccandless
2020-03-16 09:47:01 -07:00
committed by GitHub
parent 86cbe64ae8
commit 8a733270d7
6 changed files with 20 additions and 18 deletions

View File

@@ -19,6 +19,7 @@
box-sizing: border-box;
}
</style>
<link rel="shortcut icon" href="static/img/favicon.png">
</head>
<body>

View File

@@ -85,17 +85,16 @@ def static_redirect(dataset, therest):
return redirect(f"/static/{therest}", code=301)
def favicon_redirect(dataset):
""" redirect favicon to static dir """
return redirect("/static/favicon.png", code=301)
def dataroot_index():
# FIXME with a splash screen that includes a listing of all the datasets.
# or perhaps a login screen if this is a hosted environment
data = "<H1>Welcome to cellxgene</H1>"
# or perhaps a login screen if this is a hosted environment,
# or have a configuration option to redirect to a user specified page.
# the following is just for demo purposes...
data = '<!doctype html><html lang="en">'
data += '<head><title>Hosted Cellxgene</title></head>'
data += '<body><H1>Welcome to cellxgene</H1>'
try:
config = current_app.app_config
locator = DataLocator(config.dataroot)
@@ -106,15 +105,16 @@ def dataroot_index():
if matrix_data_loader.etype != MatrixDataType.UNKNOWN:
datasets.append(fname)
data += "<br/>Select one of these datasets...<br/>"
data += "<ul>"
data += '<br/>Select one of these datasets...<br/>'
data += '<ul>'
datasets.sort()
for dataset in datasets:
data += f"<li><a href={dataset}>{dataset}</a></li>"
data += "</ul>"
except Exception:
pass
data += f'<li><a href={dataset}>{dataset}</a></li>'
data += '</ul>'
except Exception as e:
data += f'<br/>Unable to locate datasets from {config.dataroot}: {str(e)}'
data += '</body></html>'
return make_response(data)
@@ -219,7 +219,6 @@ class Server:
self.app.register_blueprint(resources.blueprint)
self.app.add_url_rule("/<dataset>/", "dataset_index", dataset_index)
self.app.add_url_rule("/<dataset>/static/<path:therest>", "static_redirect", static_redirect)
self.app.add_url_rule("/<dataset>/favicon.png", "favicon_redirect", favicon_redirect)
self.app.matrix_data_cache_manager = matrix_data_cache_manager
self.app.annotations = annotations

View File

@@ -1,4 +1,4 @@
# Configue WSGI so that it will work with numpy, scanpy, etc, which all use the
# Configure WSGI so that it will work with numpy, scanpy, etc, which all use the
# Python SWIG, and therefore will deadlock on start. For more information, see
# https://modwsgi.readthedocs.io/en/develop/user-guides/application-issues.html#python-simplified-gil-state-api
files:

View File

@@ -20,7 +20,9 @@ build: clean
cp app.py artifact.dir/application.py; \
cp ../requirements.txt artifact.dir; \
cp -r .ebextensions artifact.dir; \
(cd artifact.dir; zip -r ../artifact.zip . --exclude server/test/\* server/eb/\* ); \
(cd artifact.dir; \
cp -r server/common/web/static static; \
zip -r ../artifact.zip . --exclude server/test/\* server/eb/\* ; ); \
if ! grep artifact.zip .elasticbeanstalk/config.yml ; then \
mkdir -p .elasticbeanstalk ; cat config_deploy.yaml >> .elasticbeanstalk/config.yml ; fi

View File

@@ -70,5 +70,5 @@ There are many more options to these commands that may be important or necessary
7. Open the application in a browser
```
eb open
eb open $EB_ENV
```

View File

@@ -1,4 +1,4 @@
[flake8]
max-line-length = 120
ignore = E203, W503
exclude = server/data_common/fbs/NetEncoding/,.git,__pycache__,venv,server/venv,old,build,dist,server/data_common/fbs/NetEncoding
exclude = server/data_common/fbs/NetEncoding/,.git,__pycache__,venv,server/venv,old,build,dist,server/eb/artifact.dir/