- Default behaviors (can be changed) are:
- Sqlite database is used
dev.db
file is created - Memory cache is used
- Sqlite database is used
export ENV=dev
set development environment (optional)export FLASK_DEBUG=1
Set debug mode / Auto reload when code changesexport FLASK_APP=app.py
Set flask main app module- Migration commands
flask createdb
Create DBflask db init
Create migrations dirflask db migrate
Create migration versionsflask db upgrade
Apply migrations into physical database
flask laodfixtures
Load fixtures / Testing Data if needed- run server
flask run
export CACHE_BACKEND_URI=redis://{ip}:{port}/{db_number}
to set a redis cache backendexport SQLALCHEMY_DATABASE_URI=postgresql://{user}:{pass}@{ip}:{port}/{db_name}
Use Postgresql dbexport EXCLUDED_MIDDLEWARES=iyo
Quickly disable IYO authentication middlewareexport EXCLUDED_MIDDLEWARES=iyo,mw2,mw3
Quickly disable a comma separated list of middlewares- Export & Import
flask dumpdata
dump db into json filesflask loaddata
load json files dump into db- by default in development mode, the data directory to export data to or import from is called
data
under the root dir of the application, to change this directory useexport DATA_DIR={path}
export ENV=prod
set production environmentexport FLASK_APP=app.py
Set flask main app moduleexport CACHE_BACKEND_URI=redis://172.17.0.3:6379/0
set redis cache backendexport SQLALCHEMY_DATABASE_URI=postgresql://postgres:[email protected]:5432/crm
set Database URIexport SENDGRID_API_KEY=SENDGRID_KEY_GOES_HERE
for the mailer service.uwsgi --ini uwsgi.ini
To run in Uwsgi
Note
- In production mode,
DATA_DIR
is set by default to/opt/code/github/incubaid/data_crm
Setup Caddy server as a reverse proxy to allow IYO Authentication
Ignore this step if you're not familiar with IYO you can perfectly run CRM behind any reverse proxy of your choice. but in this case you'll loose the authentication part of the app and you'll need to provide a middleware in the app to do authentication See Writing your own Authentication middleware
We usually run our CRM Flask app behind Caddy Server as a reverse proxy since it's powerful and has a list of interesting Plugins one of those is IYO plugin which can do an out of the box authentication against IYO
-
Use Caddyman to install Caddy Server with IYO plugin
-
Use the following Caddy Server configurations assuming you've met these assumptions
- You already created an IYO organization called
crm
with a sub-organization calledcrm_users
and you created an app withclient_id
&client_secret
for this organization - IYO
client_id
iscrm
- IYO
client_secret
isj_V4qVf6dLwWR_jeQJQssss-KymN7D011zFu15H8a4lg9lxde
- you want to authenticate only people with membership in
crm.crm_users
- you want to skip authentication for some routes like
/api
and/docs/graphqlapi
- You need to run Caddy Server on port
10000
- You've CRM running on port
5000
- ROOT dir for your CRM app is
/opt/code/github/incubaid/crm/
:10000 { proxy / localhost:5000 { header_upstream Host "localhost:10000" except /docs/graphqlapi } root /opt/code/github/incubaid/crm/ browse docs/graphqlapi/index.html oauth { client_id crm client_secret j_V4qVf6dLwWR_jeQJQssss-KymN7D011zFu15H8a4lg9lxde redirect_url http://localhost:10000/iyo_callback authentication_required / #that means no authentication required extra_scopes user:address,user:email,user:phone,user:memberof:crm.crm_users allow_extension api allow_extension graphqlapi allow_extension html allow_extension png } }
- You already created an IYO organization called