Git Product home page Git Product logo

ae5-flask's Introduction

AE5 Flask Helper

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.
  • 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.

Installation

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.

Usage

  1. Ensure that the ae5-flask conda package is available in either your default AE5 channel list, or the channels list in anaconda-project.yml.
  2. Add ae5-flask to your packages list in anaconda-project.yml.
  3. 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 the lab_launch environment)
  4. Build your Flask app as you normally would.
  5. 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
    
  6. Open this proxied URL in a new browser tab. In Jupyter terminals, the URL printed out is likely active and can be clicked on.

ae5-flask's People

Contributors

mcg1969 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.