|
1 | 1 | Flask-REST-Server-Template
|
2 | 2 | ==========================
|
3 | 3 |
|
| 4 | +[](https://travis-ci.com/onlinejudge95/Flask-REST-Server-Template) |
| 5 | + |
| 6 | +[](https://codecov.io/gh/onlinejudge95/Flask-REST-Server-Template) |
| 7 | +[](https://pyup.io/repos/github/onlinejudge95/Flask-REST-Server-Template/) |
| 8 | +[](https://pyup.io/repos/github/onlinejudge95/Flask-REST-Server-Template/) |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
4 | 15 | ## Info
|
| 16 | +This is a template for spinning up a REST server in Flask for API first development. |
| 17 | +Use this repo as a template repo. |
5 | 18 |
|
6 | 19 | ## Dependencies
|
| 20 | +The server is tested in our travis account for following versions of Python |
| 21 | +* 3.6 |
| 22 | +* 3.7 |
| 23 | +* 3.7-dev |
| 24 | +* 3.8-dev |
| 25 | + |
| 26 | +The server dependencies are specified based according to the environment. |
| 27 | +* Production level dependencies are defined in `requirements/prod.txt`. |
| 28 | +* Development level dependencies are defined in `requirements/dev.txt`. |
| 29 | +* Testing level dependencies are defined in `requirements/test.txt`. |
| 30 | + |
| 31 | +## Docker |
| 32 | +The image is pushed to dockerhub {$LINK}, every push to git repository triggers a new build at the dockerhub. |
| 33 | + |
| 34 | +* To build the image after modifications, run |
| 35 | + ``` |
| 36 | + $ docker build -t {$IMAGE}:{$TAG} . |
| 37 | + ``` |
| 38 | +* To run the container after the image has build successfully, run |
| 39 | + ``` |
| 40 | + $ docker run -it -d -p {$EXTERNAL_PORT}:8000 {$IMAGE}:{$TAG} |
| 41 | + ``` |
7 | 42 |
|
8 | 43 | ## Setup
|
| 44 | +To setup the dev env use the following commands. |
| 45 | +``` |
| 46 | +$ python3 -m venv env |
| 47 | +$ source env/bin/activate |
| 48 | +(env) $ pip install --cache-dir .pip.cache/ --progress-bar emoji --upgrade pip setuptools |
| 49 | +(env) $ pip install --cache-dir .pip.cache/ --progress-bar emoji --requirement requirements/dev.txt |
| 50 | +(env) $ cp .env.example .env |
| 51 | +``` |
| 52 | +To setup the db use the following commands. |
| 53 | +``` |
| 54 | +(env) $ mysql -u user -p |
| 55 | +mysql > CREATE DATABASE $DB; |
| 56 | +mysql > CREATE USER '$USER'@'$HOST' IDENTIFIED BY $PASSWORD; |
| 57 | +mysql > GRANT ALL PRIVILEGES ON * . * TO '$USER'@'$HOST'; |
| 58 | +mysql > FLUSH PRIVILEGES; |
| 59 | +mysql > exit; |
| 60 | +(env) $ python manage.py db init |
| 61 | +``` |
| 62 | +To make a migration run the folowing commands |
| 63 | +``` |
| 64 | +(env) $ python manage.py db migrate -m $MESSAGE |
| 65 | +(env) $ python manage.py db upgrade |
| 66 | +``` |
9 | 67 |
|
10 | 68 | ## Contact
|
11 | 69 | [onlinejudge95](mailto:onlinejudge95@gmail.com)
|
0 commit comments