/boilerplate_flask_sqlalchemy

A simple boilerplate RESTful app with Flask and SQLAlchemy

Primary LanguagePythonMIT LicenseMIT

Boilerplate Flask SQLAlchemy

build coverage

Overview

This is a boilerplate RESTful app based on Flask + SQLAlchemy with gunicorn, Nginx and Docker.

Getting Started

Installation

$ cd boilerplate_flask_sqlalchemy/

$ pip install -U pipenv  # If you don't have pipenv, checkout https://pipenv.readthedocs.io/en/latest/#install-pipenv-today
$ export PIPENV_VENV_IN_PROJECT=1  # Let the virtual environment and packages to be installed in the project
$ pipenv install  # Install required packages
$ pipenv shell  # Activate the virtual environment

$(.venv) flask create-db  # Initialize database
$(.venv) gunicorn --workers 1 --bind 0.0.0.0:8901 app:app  # Launch the app

Try it out

$ curl -i http://0.0.0.0:8901/product

Setup for development

$ pipenv install --dev  # Install dev-packages like pytest

$ git config core.hooksPath hooks  # Set hooks for `git commit` and `git push`

$ cp .env_example .env  # Create a copy of dotenv file for configurations

Working with Docker

  1. Install docker and docker-compose
  2. Build docker image:
$ docker-compose build

To edit a tag of the docker image, edit image from the docker-compose.yml

  1. Launch:
$ docker-compose up -d

Deployment

Heroku

Private Server (TODO)

  1. Create new docker image from CircleCi
  2. Push the image to the Container Registry (eg. DockerHub)
  3. Assess your server and install dependencies like docker and docker-compose
  4. Pull the image created and run:
$ docker run -p 80:80 -d <IMAGE ID>

Documentation

General Documentation

To build the documentation, simply run

$ cd docs/
$ . ./collect_and_build.sh

Documentation page will automatically open up!

API Documentation (RESTful)

Swagger UI is used for this documentation. The configuration can be found at swagger.yml.

To see the documentation, run the app and simply go to

  • http://{YOUR_HOST}:{YOUR_PORT}/ui

License

See LICENSE