Anaconda Enterprise 5 simplifies the deployment of web applications utilizing frameworks such as Flask. However, developing such apps within AE5 can be a bit challenge because of the need to view the application during development through a special proxy URL. Specifically, the application will be visible at the URL
https://<session-id>.<ae5-domain-name>/proxy/8086/
where <session-id>
is the UUID of the session and
<ae5-domain-name>
of the AE5 cluster. The 8086
represents the port
that the Flask app is served over. (While Flask can be configured to
server over other ports, 8086 is the one Anaconda Enterprise expects
all deployments to use; and 7050 is reserved for other session purposes.)
Unfortunately, this approach presents to challenges:
<session-id>
is not always easy to determine. I have three approaches:- In Jupyter Classic notebook, you can right-click on the Jupyter logo
and select "copy link"; then paste that into the URL bar. You can then
edit that URL to replace the path with
/proxy/8086/
. - In JupyterLab, the logo does not have an active link. However, you can select any file in the file browser, right-click, and select "Copy shareable link", and do the same editing.
- In a terminal window, you can examine the value of the environment
variable
TOOL_HOST
.
- In Jupyter Classic notebook, you can right-click on the Jupyter logo
and select "copy link"; then paste that into the URL bar. You can then
edit that URL to replace the path with
- The more challenging problem is that Flask does not naturally adapt
to the use of the
/proxy/<port>/
prefix. As a result, the rendering of some pages, particularly with static content, is faulty. While this does not affect the deployment of the application, it certainly makes development more difficult. These challenges are not unique to Flask apps, but the solution offered in this package is specific to Flask.
This package, when installed, does the following:
- Patches Flask's
url_for
function to prepend/proxy/8086/
to every URL generated by this function. As long as the application relies on standard Flask URL generation commands, this will correct all URLs. - Patches the Werkzeug package, which Flask depends on, to print the full proxy URL when running the application. An example of this output is shown in step 4 of the usage instructions below. This makes is easy to determine the exact URL needed to view your application in development.
These patches are implemented in a post-link script when the package is installed, and are not applied during deployments. So that means the package is safe to include permanently in your project, and there is no need to remove the package before deployment.
At the moment there is no CI or testing here. So the package will need to be built manually:
conda build conda-recipe
anaconda upload ...
Once the package is built, upload it to an Anaconda channel that is available to your projects.
- Ensure that the
ae5-flask
conda package is available in either your default AE5 channel list, or thechannels
list inanaconda-project.yml
. - Add
ae5-flask
to yourpackages
list inanaconda-project.yml
. - If you're adding this package in the middle of a session, you will need
to install it manually into your environment, by running either of these
on the command line:
conda install -n <env> ae5-flask
anaconda-project prepare
(in thelab_launch
environment)
- Build your Flask app as you normally would.
- Launch a terminal window and run your application as you normally would.
The proxied address will be printed out, like the example above.
* Proxied on https://250eae91790c4031b11e577154e0d488.aip.anaconda.com/proxy/8086/ * Running on http://0.0.0.0:8086/ (Press CTRL+C to quit) * Restarting with stat * Debugger is active! * Debugger PIN: 293-832-424
- Open this proxied URL in a new browser tab. In Jupyter terminals, the URL printed out is likely active and can be clicked on.