deemarc / proshop_flask

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flask_project_template

folder template for my flask project

Getting Start

  • Remarks: some modification need to be done before it can be run on docker

1. Installing Dependencies

Python 3.7

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

Virtual Enviornment

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

PIP Dependencies

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
Key Dependencies

Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.

Install the package

along with this Readme you should see the setup.py file in the same location

pip3 install -e .

2. Setup postgres database for the service to connect to

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

3. Create/Updata database table

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

4. Config the service

before running, please make sure that the configuration will work at your side. you can config the service into ways.

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

Configurable Parameter

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

Running the service

if you using the virtual enviroment everything should be ready in bin folder

./proshop/bin/run-api

Deployment process

  1. 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

```
  1. change directory into proshop
cd proshop
  1. run postgres in docker (only it's not currently run)
source docker-psql.sh
  1. create virtualenv 4.1 if no virtual env install it
    pip3 install virtualenv
    
    4.2 make virtualenv
    virtualenv "$HOME"/proshop
    
    4.3 activate virtualenv
    source "$HOME"/proshop/bin/activate
    
    4.4 install requirement
    pip3 install -r requirements.txt
    
    4.5 install package pip3 install -e .
  2. run flask-migration to make sure the database has correct database model version
run-manage db upgrade
  1. cp our supvisor run scritp into proper place
sudo cp proshop.ini /etc/supervisord.d/
  1. run the service with supervisor
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start

About

License:MIT License


Languages

Language:Python 81.5%Language:HTML 10.7%Language:CSS 3.3%Language:Mako 3.2%Language:Shell 1.2%