We recommend using Anaconda to create and manage your development environments for KnowMore. All the subsequent instructions are provided assuming you are using Anaconda (Python 3 version).
Clone the repo and submodules
git clone https://github.com/SPARC-FAIR-Codeathon/KnowMore.git --recurse
Open Anaconda prompt (Windows) or the system Command line interface then naviguate to the KnowMore folder
$ cd ./KnowMore
$ conda create -n "knowmore-flask-env" python=3.6
$ conda activate knowmore-flask-env
$ conda install pip
$ pip install -r requirements.txt
The environment variables required are listed in the table below along with information on how to get them
Suggested name | Value or instructions for obtaining it | Purpose |
---|---|---|
FLASK_ENV | "development" | Prod or dev |
SERVER_NAME | "localhost:5000" | server url |
LISTEN_PORT | "5000" | Port for flask app to listen to |
CLIENT_URL | "http://localhost:3000" | Sparc-App url |
OSPARC_TEST_MODE | false | whether to use test mode, so you don't have to contact osparc to develop your frontend |
OSPARC_API_KEY | Contact osparc support | Sending jobs to osparc |
OSPARC_API_SECRET | Contact osparc support | Sending jobs to osparc |
SECRET_KEY | flask secret key |
Each of them can be set in your conda environment as follows
$ conda env config vars set MY_VAR=value1 MY_OTHER_VAR=value2
$ flask run
or if you require remote access: (NOTE untested)
$ flask run --host=0.0.0.0
Want to develop without starting the osparc jobs?
set env var (to anything other than string 'false')
OSPARC_TEST_MODE=true
This will make it so you don't actually contact osparc, but instead receive sample data back. Helpful for debugging frontend without having to wait for osparc job everytime.
See Docker's official documentation.
docker-compose up -d
Note that this will use the env vars as specified in your .env file. Make sure you still set those before building the image.
docker ps
Should get something like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
368be64c60c1 knowmore_flaskapp "/entrypoint.sh /sta…" 10 seconds ago Up 9 seconds 80/tcp, 443/tcp, 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp knowmore-flask-web-app
Note that this container is exposing port 5000 (the port where flask is listening) to your host.
docker logs knowmore-flask-web-app -f
- Using browser or
curl
from your host, try outhttp://localhost:5000/
.- Response should be:
status: up
- Response should be:
- Get a sample image:
http://localhost:5000/api/results-images/example-job-id/Plots-PlotID-3.7.png
- Flask should return the image file.
git push heroku main
- use production server, rather than dev server
- build a new docker image (current one is outdated)
- upload all files to s3 instead of to local filesystem (especially due to the nature of Heroku's ephemeral filesystem)
curl http://127.0.0.1:5000/api/check-osparc-job/123e4567-e89b-12d3-a456-426614174000
# example response: {"error": "{\"errors\":[\"project 123e4567-e89b-12d3-a456-426614174000 not found\"]}", "status_code": 500}
python3 manual-job-starter.py
To not create job, but use existing job, pass in a single arg with job uuid of python job (NOT THE MATLAB JOB ID) e.g.,
python3 manual-job-starter.py e9012487-5ff1-4112-aa4f-8165915973fa