CD/CI Tutorial Sample App

by edonosotti

GitHub Readme.md

Build Status codebeat badge Maintainability

CD/CI Tutorial Sample Application

Description

This sample Python REST API application was written for a tutorial on implementing Continuous Integration and Delivery pipelines.

It demonstrates how to:

  • Write a basic REST API using the Flask microframework
  • Basic database operations and migrations using the Flask wrappers around Alembic and SQLAlchemy
  • Write automated unit tests with unittest

Requirements

  • Python 3.6
  • pip
  • virtualenv

Installation

Run:

$ pip install -r requirements.txt
$ python -m venv venv
$ source venv/bin/activate

Optional: set the DATABASE_URL environment variable to a valid SQLAlchemy connection string. Otherwise, a local SQLite database will be created.

Initalize and seed the database:

$ flask db upgrade
$ python seed.py

Running tests

Run:

$ python -m unittest discover

Running the application

Running locally

Run the application using the built-in Flask server:

$ flask run

Running on a production server

Run the application using gunicorn:

$ gunicorn app:app

Deploying to Heroku

Run:

$ heroku create
$ git push heroku master
$ heroku run flask db upgrade
$ heroku run python seed.py
$ heroku open

or use the automated deploy feature:

Deploy

For more information about using Python on Heroku, see these Dev Center articles: