folder template for my flask project
- Remarks: some modification need to be done before it can be run on docker
Install the latest version of python for your platform follow this link: python docs
- Remmark this project has been tested to work with python3.7
I recommend working within a virtual environment . This keeps your dependencies for each project separate and organaized. Instructions for setting up a virual enviornment for your platform can be found in the python docs
python3.7 -m venv [path_to_desired_place]/venv/proshop
source ./proshop/bin/activate
Once you have your virtual environment setup and running, install dependencies if you current directory is where this Readme is, you should be ready to run the requirement file
pip install -r requirements.txt
Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.
along with this Readme you should see the setup.py file in the same location
pip3 install -e .
if you already have postgres database running and ready to be connect you can just config the service to connect to it
but if not we already provide the script to run postgres database inside docker.
please config it before running
source docker-psql.sh
As the name state, you only need to run this when you need to create database table or update it (if this is the first time you connect the service to the database the you sure does to run this)
Remarks: you need to run this in the directory where migration folder is located(same location as this readme)
./proshop/bin/run-manage db upgrade
before running, please make sure that the configuration will work at your side. you can config the service into ways.
- defaults.py
- enviroment varaible
if same config happen to be in both places. then the service will use the value in enviroment varaible
to understand how this service configuration works you can see this config file
here's the list of configuration and there uses;
- SQLALCHEMY_DATABASE_URI: URL string for the service to connect to
- PORT: port for the flask api will be running on for accepting rest api request
- LOG_FILE_PATH: location where the service will log to
if you using the virtual enviroment everything should be ready in bin folder
./proshop/bin/run-api
- clone this git
git clone [git_uri]
cd [git_proshop]
1.1 for production you can just use master
1.2 for test environment please use develop branch
```
git checkout develop
```
- change directory into proshop
cd proshop
- run postgres in docker (only it's not currently run)
source docker-psql.sh
- create virtualenv
4.1 if no virtual env install it
4.2 make virtualenv
pip3 install virtualenv
4.3 activate virtualenvvirtualenv "$HOME"/proshop
4.4 install requirementsource "$HOME"/proshop/bin/activate
4.5 install package pip3 install -e .pip3 install -r requirements.txt
- run flask-migration to make sure the database has correct database model version
run-manage db upgrade
- cp our supvisor run scritp into proper place
sudo cp proshop.ini /etc/supervisord.d/
- run the service with supervisor
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start