Flask

Deploy

reference: https://www.jianshu.com/p/60f361822a7e

MacOS Deploy

  1. App Store install XCode
  2. Terminal install Xcode command line tool

    $ xcode-select --install
    
  3. Install Home-brew

    $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    1. check Home-brew status (if ready will show ‘Your system is ready to brew.’ )

      $ brew doctor
      
  4. 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
    
    1. below 3 line add to ~/.bash_profile
      PATH="$HOME/.pyenv/bin:$PATH"
      eval "$(pyenv init -)"
      eval "$(pyenv virtualenv-init -)"
      
  5. Install python version.

    $ pyenv install 3.6.3
    
    1. See install versions (you can see python 3.6.3 version).
      $ pyenv versions
      
  6. Set virtualenv.
    command like : pyenv virtualenv {python version} {alias name}

    $ pyenv virtualenv 3.6.3 python3.6.3
    
  7. Set folder python version.
    When enter someone folder. (ex: cd foo).
    command like : pyenv local {alias name}

    $ pyenv local python3.6.3
    
    1. See is it work?
      $ python -V
      
  8. Pip install
    If you have pip install list. You can run pip command like this.

    $ pip install -r requirements.txt
    
    1. 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
      

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

results matching ""

    No results matching ""