Skip to content

Latest commit

 

History

History
73 lines (66 loc) · 1.59 KB

File metadata and controls

73 lines (66 loc) · 1.59 KB

Python web app template

Features:

  • Uses Flask
  • Uses Flask REST Plus to build REST API
  • (optional) Uses Docker
  • (optional) Heroku app (Docker workflow)

Setup

If you need some environment variables set, use .env file. For example ifwe are going to use AWS S3. Create .env file with the following contents:

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
S3_BUCKET=

Installation

It is always a good idea to create a virtual environment

python3 -m venv venv

It will create a venv directory with isolated copy of Python To activate the created virtual environment run

source venv/bin/activate

After virtual environment activation we don't need to use python3 and pip3, we can normally use python and pip

Update pip

pip install --upgrade pip

Install dependencies For deployment.

pip install -r requirements.txt

Run web server localy

Development server

python web/app.py --debug

Open browser at the address shown. The debug options force the server automatically reload the app if any sources are changed.

Alternatively run via gunicorn (as it run on Heroku)

cd web
gunicorn --bind 0.0.0.0:5000 app:app

Docker

Build

docker build -t appname:latest .

Run

docker run -t -i --env-file .env -p 5000:5000 -e PORT=5000 appname:latest

Deploy on Heroku

Option 1. Locally build docker image and push it to Heroku

heroku container:push web --app herokuappname
heroku container:release web --app herokuappname

Option 2. Remotely build on Heroku

git push heroku master