Flask
Deploy
reference: https://www.jianshu.com/p/60f361822a7e
MacOS Deploy
- App Store install XCode
Terminal install Xcode command line tool
$ xcode-select --install
Install Home-brew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
check Home-brew status (if ready will show ‘Your system is ready to brew.’ )
$ brew doctor
Install pyenv and pyenv-virtualenv.
ref: https://github.com/pyenv/pyenv
ref: https://github.com/pyenv/pyenv-virtualenv
ref: https://www.jianshu.com/p/60f361822a7e$ brew install pyenv $ brew install pyenv-virtualenv
- below 3 line add to ~/.bash_profile
PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"
- below 3 line add to ~/.bash_profile
Install python version.
$ pyenv install 3.6.3
- See install versions (you can see python 3.6.3 version).
$ pyenv versions
- See install versions (you can see python 3.6.3 version).
Set virtualenv.
command like : pyenv virtualenv {python version} {alias name}$ pyenv virtualenv 3.6.3 python3.6.3
Set folder python version.
When enter someone folder. (ex: cd foo).
command like : pyenv local {alias name}$ pyenv local python3.6.3
- See is it work?
$ python -V
- See is it work?
Pip install
If you have pip install list. You can run pip command like this.$ pip install -r requirements.txt
- requirements.txt sample
Flask==0.12.2 flask-restplus==0.10.1 Flask-SQLAlchemy==2.3.2 Flask-Script==2.0.6 Flask-Testing gunicorn==19.7.1 gevent==1.2.2 psycopg2==2.7.3.2 raven
- requirements.txt sample
Flask configuration
https://spacewander.github.io/explore-flask-zh/5-configuration.html
It may like this.
app/
....
config/
default.py
development.py
staging.py
production.py
instance/
config.py
# main.py code writed
app.config.from_object('config.default')
app.config.from_envvar('APP_CONFIG_FILE') # APP_CONFIG_FILE by different environment
app.config.from_pyfile('config.py') # from app/instance/config.py
Create a start.sh to assign different environment configuration.
APP_CONFIG_FILE=/var/www/yourapp/config/production.py \
python run.py