Skip to content

Commit

Permalink
Merge pull request #8 from geobretagne/flask
Browse files Browse the repository at this point in the history
Merge api-mreport & mreport with Flask
  • Loading branch information
spelhate authored Jun 5, 2020
2 parents d4a9632 + 0ce5193 commit f7e4e3c
Show file tree
Hide file tree
Showing 82 changed files with 1,129 additions and 217 deletions.
138 changes: 138 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
5 changes: 0 additions & 5 deletions .htaccess

This file was deleted.

94 changes: 94 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Prerequis
----------

$ sudo apt-get install python3-venv


Install
---------

# clone the repository
$ cd /home
$ git clone https://github.com/geobretagne/mreport.git
$ cd mreport


Create a virtualenv and activate it

$ python3 -m venv venv
$ . venv/bin/activate


Install Flask and dependencies

$ pip install -r requirements.txt



Configure
---------

Edit config.py and set SQLALCHEMY_DATABASE_URI



Test frontend
--------------

$ export FLASK_APP=frontend
$ flask run

test http://localhost:5000/mreport/sample/ECLUSE_1

test http://localhost:5000/admin/

Test backend
--------------

$ export FLASK_APP=backend
$ flask run

test http://localhost:5000/api



Tester frontend & backend
--------------------------

$ python3 dispatcher.py

test http://localhost:5000/api
test http://localhost:5000/admin/
test http://localhost:5000/mreport/sample/ECLUSE_1


gunicorn
--------


$ gunicorn -b 0.0.0.0:5000 dispatcher

```Create a .service file for the api. (/etc/systemd/system/mreport.service):```

```
[Unit]
Description=mreport
After=network.target
[Service]
User=mreport
Restart=on-failure
WorkingDirectory=/tmp/
ExecStart=/home/mreport/mreport/venv/bin/gunicorn -b 0.0.0.0:5000 dispatcher
[Install]
WantedBy=multi-user.target
```


```Enable and start the service```

$ sudo systemctl daemon-reload
$ sudo systemctl enable mreport
$ systemctl start mreport

6 changes: 0 additions & 6 deletions app.json

This file was deleted.

101 changes: 101 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# api-mreport
flask api for mreport

Prerequis
----------

$ sudo apt-get install python3-venv

Create api user
---------------

$ sudo adduser mreport


Install
---------

# clone the repository
$ cd /home/mreport
$ git clone https://github.com/spelhate/api-mreport.git
$ cd api-mreport


Create a virtualenv and activate it

$ python3 -m venv venv
$ . venv/bin/activate


Install Flask and dependencies

$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -r requirements.txt



Configure
---------

Edit config.py and set SQLALCHEMY_DATABASE_URI



Run
---

$ export FLASK_APP=app
$ flask run


Deploy with apache and gunicorn
--------------------------------

In apache conf

```
ProxyPreserveHost on
<Location "/api">
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization"
ProxyPass "http://127.0.0.1:5000/api/"
ProxyPassReverse "http://127.0.0.1:5000/api/"
</Location>
```

logs

$ mkdir /var/log/api-mreport
$ sudo chown mreport /var/log/api-mreport



Test gunicorn


$ gunicorn -c gunicorn.conf -b 0.0.0.0:5000 app:app

```Create a .service file for the api. (/etc/systemd/system/api-mreport.service):```

```
[Unit]
Description=api-mreport
After=network.target
[Service]
User=mreport
Restart=on-failure
WorkingDirectory=/home/mreport/api-mreport/
ExecStart=/home/mreport/api-mreport/venv/bin/gunicorn -c /home/mreport/api-mreport/gunicorn.conf -b 0.0.0.0:5000 app:app
[Install]
WantedBy=multi-user.target
```


```Enable and start the service```

$ sudo systemctl daemon-reload
$ sudo systemctl enable api-mreport
$ systemctl start api-mreport


Loading

0 comments on commit f7e4e3c

Please sign in to comment.