https://github.com/edonosotti/ci-cd-tutorial-sample-app
A sample Python app that implements a REST API, with database migrations and CI/CD support.
https://github.com/edonosotti/ci-cd-tutorial-sample-app
alembic continuous-delivery continuous-integration flask flask-migrate flask-sqlalchemy heroku heroku-deployment heroku-ready migrations python sqlalchemy unit-testing unittest
Last synced: 26 days ago
JSON representation
A sample Python app that implements a REST API, with database migrations and CI/CD support.
- Host: GitHub
- URL: https://github.com/edonosotti/ci-cd-tutorial-sample-app
- Owner: edonosotti
- Created: 2018-11-08T21:16:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-09T09:06:32.000Z (almost 2 years ago)
- Last Synced: 2023-10-20T19:36:46.496Z (over 1 year ago)
- Topics: alembic, continuous-delivery, continuous-integration, flask, flask-migrate, flask-sqlalchemy, heroku, heroku-deployment, heroku-ready, migrations, python, sqlalchemy, unit-testing, unittest
- Language: Python
- Homepage:
- Size: 23.4 KB
- Stars: 12
- Watchers: 4
- Forks: 104
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/edonosotti/ci-cd-tutorial-sample-app)
[](https://codebeat.co/projects/github-com-edonosotti-ci-cd-tutorial-sample-app-master)
[](https://codeclimate.com/github/edonosotti/ci-cd-tutorial-sample-app/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](http://flask.pocoo.org) microframework
* Basic database operations and migrations using the Flask wrappers around [Alembic](https://bitbucket.org/zzzeek/alembic) and [SQLAlchemy](https://www.sqlalchemy.org)
* Write automated unit tests with [unittest](https://docs.python.org/2/library/unittest.html)Also:
* How to use [GitHub Actions](https://github.com/features/actions)
Related article: https://medium.com/rockedscience/docker-ci-cd-pipeline-with-github-actions-6d4cd1731030
## Requirements
* `Python 3.8`
* `Pip`
* `virtualenv`, or `conda`, or `miniconda`The `psycopg2` package does require `libpq-dev` and `gcc`.
To install them (with `apt`), run:```sh
$ sudo apt-get install libpq-dev gcc
```## Installation
With `virtualenv`:
```sh
$ python -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
```With `conda` or `miniconda`:
```sh
$ conda env create -n ci-cd-tutorial-sample-app python=3.8
$ source activate ci-cd-tutorial-sample-app
$ pip install -r requirements.txt
```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:
```sh
$ flask db upgrade
$ python seed.py
```## Running tests
Run:
```sh
$ python -m unittest discover
```## Running the application
### Running locally
Run the application using the built-in Flask server:
```sh
$ flask run
```### Running on a production server
Run the application using `gunicorn`:
```sh
$ pip install -r requirements-server.txt
$ gunicorn app:app
```To set the listening address and port, run:
```
$ gunicorn app:app -b 0.0.0.0:8000
```## Running on Docker
Run:
```
$ docker build -t ci-cd-tutorial-sample-app:latest .
$ docker run -d -p 8000:8000 ci-cd-tutorial-sample-app:latest
```## Deploying to Heroku
Run:
```sh
$ heroku create
$ git push heroku master
$ heroku run flask db upgrade
$ heroku run python seed.py
$ heroku open
```or use the automated deploy feature:
[](https://heroku.com/deploy)
For more information about using Python on Heroku, see these Dev Center articles:
- [Python on Heroku](https://devcenter.heroku.com/categories/python)