Coder Social home page Coder Social logo

meta456trader / ci-cd-tutorial-sample-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from edonosotti/ci-cd-tutorial-sample-app

0.0 0.0 0.0 24 KB

A sample Python app that implements a REST API, with database migrations and CI/CD support.

Shell 0.29% Python 87.81% Mako 6.22% Dockerfile 5.68%

ci-cd-tutorial-sample-app's Introduction

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

Also:

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:

$ sudo apt-get install libpq-dev gcc

Installation

With virtualenv:

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

With conda or miniconda:

$ 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:

$ 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:

$ 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:

$ 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:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.