OSC / ood-example-sciGatewayApp

An example python flask app to be built in ondemand using the passenger tutorial for science gateways.
0 stars 0 forks source link

Better way to use flask and other libs #2

Closed andrejcermak closed 1 year ago

andrejcermak commented 1 year ago

Hi, I just found this repo and I am curious whether it would be possible to do the installation of flask other way. There is also this repository under OSC that contains requirements.txt and setup file, but it does not seem to be working.

andrejcermak commented 1 year ago

Hi, I found a solution to this issue and I already created a merge request. Please feel free to review and consider incorporating it into this example if it's suitable.

johrstrom commented 1 year ago

I think you should open a ticket on that other repository - I was able to get the other repository to boot but just had to be careful about the python version I was using when issuing setup.sh.

andrejcermak commented 1 year ago

How did you boot the repo? I tried to go with My Sandbox Apps (Development) -> New app -> Clone existing app -> use the git repo of the flask example app, the result is Error starting web application

/var/www/ood/apps/dev/xcermak5/gateway/FlaskApp2/bin/python: line 2: /var/www/ood/apps/dev/xcermak5/gateway/FlaskApp2/.venv/bin/activate: No such file or directory
Traceback (most recent call last):
  File "/opt/ood/ondemand/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 369, in <module>
    app_module = load_app()
  File "/opt/ood/ondemand/root/usr/share/passenger/helper-scripts/wsgi-loader.py", line 76, in load_app
    return imp.load_source('passenger_wsgi', startup_file)
  File "/var/www/ood/apps/dev/xcermak5/gateway/FlaskApp2/passenger_wsgi.py", line 1, in <module>
    from app import MyApp
  File "/home/xcermak5/ondemand/dev/FlaskApp2/app.py", line 1, in <module>
    from flask import Flask, render_template
ImportError: No module named flask
johrstrom commented 1 year ago

You need to run setup.sh outside of the UI. The issue I got into was where I ran setup.sh and if that python version matched up with what's on the OOD webserver.

That is - you run setup.sh on say a login node for example. When the app boots - it boots on the OOD's webserver, with the OOD webserver's python. So they have to match, the python environment of the OOD webserver and the python environment of wherever you issued setup.sh.

andrejcermak commented 1 year ago

Ah I see. Do you think it is possible to automate the execution of the setup.sh in order to simplify the app initialization from git in OOD?

johrstrom commented 1 year ago

Do you think it is possible to automate the execution of the setup.sh in order to simplify the app initialization from git in OOD?

Yes! Though there could be buttons for the same. If you'd like to open a ticket on https://github.com/OSC/ondemand, that'd be just fine!

ruby apps have this button for the same thing (installing dependencies through bundler). My guess is that we support that because we're ruby developers. image

But with python having a plethora of virtualenv, conda and maybe others we'd probably have to set a button for each and I'm not sure if we can (or should) to it automatically given the different variations.

andrejcermak commented 1 year ago

Thank you for the insights @johrstrom!