SlideShare a Scribd company logo
Python Flask app deployed to OPenShift using Wercker CI
Python & Flask
on OpenShift
deployed by
wercker CI
1. Flask creating an API
2. Github and webhooks
3. OpenShift what is and how it works w/ Python
4. Wercker CI and deployment targets
Objective:
This talk will show you how to create a really
simple Flask API application. Keep its source
code on Github and have wercker CI to
automatically deploy successful commits to
an OpenShift application.
pip install -r requirements.txt
# The Flask Framework
flask
# A helper to run wsgi apps on OPenShift
shiftpy
# Test runner
pytest
pytest-flask
'/calc/<string:op>/<int:number>/<int:other>'
"sum", "sub", "mul", "div"
$ python api.py - running on localhost:5000
api.py
from flask import Flask, jsonify
api = Flask(__name__)
@api.route('/calc/<string:op>/<int:number>/<int:other>')
def calc(op, number, other):
operations = {"sum": lambda a, b: a + b,
"mul": lambda a, b: a * b,
"sub": lambda a, b: a - b,
"div": lambda a, b: a / b}
return jsonify({"result": operations[op](number, other)})
if __name__ == "__main__":
api.run(debug=True)
tests.py
import pytest
from flask import jsonify
from api import calc, api
@pytest.fixture
def app():
return api
def test_sum(app):
assert calc('sum', 1, 2).data == jsonify({'result': 3}).data
def test_mul(app):
assert calc('mul', 5, 3).data == jsonify({'result': 15}).data
def test_sub(app):
assert calc('sub', 10, 5).data == jsonify({'result': 5}).data
def test_div(app):
assert calc('div', 10, 2).data == jsonify({'result': 5}).data
py.test tests.py
====== test session starts =======
plugins: flask
collected 4 items
tests.py ....
==== 4 passed in 0.13 seconds ====
STEP 1: Create a github repository
Push to github:
$ ls api_project
.. api.py tests.py requirements.txt
$ git init
$ git remote add origin https://github.com/username/repo
$ git commit -am"first commit"
$ git push -u origin master
DEPLOY:
$ ssh user@yourserver.com
$ sudo apt-get install <all_deps>
$ git clone https://github.com/repo
$ # run tests on production environment
$ # setup paths and virtualenv
$ # setup webserver
$ # setup firewall
DEPLOY IN 1997:
$ ssh user@yourserver.com
$ sudo apt-get install <all_deps>
$ git clone https://github.com/repo
$ # run tests on production environment
$ # setup paths and virtualenv
$ # setup webserver
$ # setup firewall
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
wercker.yml
box: wercker/python
build:
steps:
- virtualenv:
name: My virtualenv
install_wheel: false
- script:
name: Install main requirements
code: pip install -r requirements.txt
- script:
name: Run Tests
code: py.test tests.py
Python Flask app deployed to OPenShift using Wercker CI
Add wercker to project:
$ git add wercker.yml
$ git commit -m"added wercker CI"
$ git push -u origin master
Python Flask app deployed to OPenShift using Wercker CI
wsgi.py or app.py
from app import app
from shiftpy.wsgi_utils import envify
app = application = envify(app)
.openshift/action_hooks/deploy
#!/bin/bash
source ${OPENSHIFT_PYTHON_DIR}virtenv/bin/activate
cd $OPENSHIFT_REPO_DIR
echo "installing requirements"
pip install -r requirements.txt --upgrade
Add OpenShift to project:
$ git add wsgi.py
$ git add .openshift
$ git commit -m"added openshift"
$ git push -u origin master
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
box: wercker/python
build:
steps:
- virtualenv:
name: My virtualenv
install_wheel: false
- script:
name: Install main requirements
code: pip install -r requirements.txt
- script:
name: Run Tests
code: py.test tests.py
deploy:
steps:
- script:
name: production
code: fab -R prod_server deploy
Custom Deploy Target - fabric, ansible, chef, puppet etc
DEPLOY TO
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
seunome
https://openshift.redhat.com/app/console/keys/new
Python Flask app deployed to OPenShift using Wercker CI
Lets break the tests
@api.route('/calc/<string:op>/<int:number>/<int:other>')
def calc(op, number, other):
operations = {"sum": lambda a, b: a + b,
"mul": lambda a, b: a * b,
"sub": lambda a, b: a - b,
"div": lambda a, b: a / b}
# return jsonify({"result": operations[op](number, other)})
# Break the tests!!!
return jsonify({"result": "error"})
$ git commit -m"Breaking the tests!!!"
$ git push -u origin master
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
Fix it!
@api.route('/calc/<string:op>/<int:number>/<int:other>')
def calc(op, number, other):
operations = {"sum": lambda a, b: a + b,
"mul": lambda a, b: a * b,
"sub": lambda a, b: a - b,
"div": lambda a, b: a / b}
return jsonify({"result": operations[op](number, other)})
$ git commit -m"Fixing the tests!!!"
$ git push -u origin master
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
Python Flask app deployed to OPenShift using Wercker CI
http://calculator-quokkaproject.rhcloud.com/calc/sum/2/2
http://calculator-quokkaproject.rhcloud.com/apidocs/index.html
https://github.com/rochacbruno/flask-openshift-wercker
Python Flask app deployed to OPenShift using Wercker CI

More Related Content

What's hot (20)

PPTX
Flask – Python
Max Claus Nunes
 
PPTX
Build restful ap is with python and flask
Jeetendra singh
 
PDF
Flask Basics
Eueung Mulyana
 
PPT
Write book in markdown
Larry Cai
 
PDF
Kyiv.py #17 Flask talk
Alexey Popravka
 
PDF
Flask patterns
it-people
 
PDF
Flask RESTful Flask HTTPAuth
Eueung Mulyana
 
PPTX
Laravel Beginners Tutorial 1
Vikas Chauhan
 
PDF
Rest API using Flask & SqlAlchemy
Alessandro Cucci
 
PPTX
Flask vs. Django
Rachel Sanders
 
PDF
Intro to Laravel 4
Singapore PHP User Group
 
PDF
Laravel Forge: Hello World to Hello Production
Joe Ferguson
 
PDF
Web develop in flask
Jim Yeh
 
PDF
Web development automatisation for fun and profit (Artem Daniliants)
LumoSpark
 
PPTX
Python from zero to hero (Twitter Explorer)
Yuriy Senko
 
PPTX
Laravel for Web Artisans
Raf Kewl
 
PPTX
Laravel5 Introduction and essentials
Pramod Kadam
 
PPTX
Powershell: Tu nuevo mejor amigo
Gonzalo Balladares Rivera
 
PDF
Scalable web application architecture
postrational
 
PDF
Flask SQLAlchemy
Eueung Mulyana
 
Flask – Python
Max Claus Nunes
 
Build restful ap is with python and flask
Jeetendra singh
 
Flask Basics
Eueung Mulyana
 
Write book in markdown
Larry Cai
 
Kyiv.py #17 Flask talk
Alexey Popravka
 
Flask patterns
it-people
 
Flask RESTful Flask HTTPAuth
Eueung Mulyana
 
Laravel Beginners Tutorial 1
Vikas Chauhan
 
Rest API using Flask & SqlAlchemy
Alessandro Cucci
 
Flask vs. Django
Rachel Sanders
 
Intro to Laravel 4
Singapore PHP User Group
 
Laravel Forge: Hello World to Hello Production
Joe Ferguson
 
Web develop in flask
Jim Yeh
 
Web development automatisation for fun and profit (Artem Daniliants)
LumoSpark
 
Python from zero to hero (Twitter Explorer)
Yuriy Senko
 
Laravel for Web Artisans
Raf Kewl
 
Laravel5 Introduction and essentials
Pramod Kadam
 
Powershell: Tu nuevo mejor amigo
Gonzalo Balladares Rivera
 
Scalable web application architecture
postrational
 
Flask SQLAlchemy
Eueung Mulyana
 

Viewers also liked (20)

PDF
Django para portais de alta visibilidade. tdc 2013
Bruno Rocha
 
PPTX
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
Bruno Rocha
 
PDF
Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015
Bruno Rocha
 
PDF
Flask for CMS/App Framework development.
Bruno Rocha
 
PDF
Carreira de Programador e Mercado de Trabalho
Bruno Rocha
 
PDF
Flask admin vs. DIY
dokenzy
 
PDF
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
Bruno Rocha
 
PDF
Quokka CMS - Content Management with Flask and Mongo #tdc2014
Bruno Rocha
 
PDF
OpenShift and next generation application development
Syed Shaaf
 
PDF
Desenvolvendo mvp com python
Bruno Rocha
 
ODP
OpenShift PaaS Anywhere (Infrastructure.Next Ghent 2014-02-24) Diane Mueller
OpenShift Origin
 
PDF
Curso Java Básico Aula 01: Introdução e Dicas para quem está Começando
Loiane Groner
 
PDF
OpenShift As A DevOps Platform
Lalatendu Mohanty
 
ODP
Deploying & Scaling OpenShift on OpenStack using Heat - OpenStack Seattle Mee...
OpenShift Origin
 
PDF
When to use Node? Lessons learned
beatlevic
 
PDF
Red Hat OpenShift Container Platform Overview
James Falkner
 
PDF
OpenShift, Docker, Kubernetes: The next generation of PaaS
Graham Dumpleton
 
ODP
From Zero to Cloud: Revolutionize your Application Life Cycle with OpenShift ...
OpenShift Origin
 
PDF
Build Your Own PaaS, Just like Red Hat's OpenShift from LinuxCon 2013 New Orl...
OpenShift Origin
 
ODP
Build a PaaS with OpenShift Origin
Steven Pousty
 
Django para portais de alta visibilidade. tdc 2013
Bruno Rocha
 
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
Bruno Rocha
 
Data Developer - Engenharia de Dados em um time de Data Science - Uai python2015
Bruno Rocha
 
Flask for CMS/App Framework development.
Bruno Rocha
 
Carreira de Programador e Mercado de Trabalho
Bruno Rocha
 
Flask admin vs. DIY
dokenzy
 
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
Bruno Rocha
 
Quokka CMS - Content Management with Flask and Mongo #tdc2014
Bruno Rocha
 
OpenShift and next generation application development
Syed Shaaf
 
Desenvolvendo mvp com python
Bruno Rocha
 
OpenShift PaaS Anywhere (Infrastructure.Next Ghent 2014-02-24) Diane Mueller
OpenShift Origin
 
Curso Java Básico Aula 01: Introdução e Dicas para quem está Começando
Loiane Groner
 
OpenShift As A DevOps Platform
Lalatendu Mohanty
 
Deploying & Scaling OpenShift on OpenStack using Heat - OpenStack Seattle Mee...
OpenShift Origin
 
When to use Node? Lessons learned
beatlevic
 
Red Hat OpenShift Container Platform Overview
James Falkner
 
OpenShift, Docker, Kubernetes: The next generation of PaaS
Graham Dumpleton
 
From Zero to Cloud: Revolutionize your Application Life Cycle with OpenShift ...
OpenShift Origin
 
Build Your Own PaaS, Just like Red Hat's OpenShift from LinuxCon 2013 New Orl...
OpenShift Origin
 
Build a PaaS with OpenShift Origin
Steven Pousty
 
Ad

Similar to Python Flask app deployed to OPenShift using Wercker CI (20)

PPT
Workshop For pycon13
Steven Pousty
 
PDF
Deploying Flask web app using OpenShift
Abhijeet Kasurde
 
PDF
NLUUG Spring 2012 - OpenShift Primer
Eric D. Schabell
 
PPTX
Openshift Presentation ppt compare with VM
shubhamage1
 
PPTX
Openshift Presentation ppt compare with VM
shubhamage1
 
ODP
From Code to Cloud - PHP on Red Hat's OpenShift
Eric D. Schabell
 
PDF
Open shift intro for Philly PUG
Steven Pousty
 
PDF
Open shift
marcolof
 
PDF
OpenShift Primer - get your business into the Cloud today!
Eric D. Schabell
 
PPTX
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
PDF
DevOps of Python applications using OpenShift (Italian version)
Francesco Fiore
 
PDF
Rodando *qualquer coisa* na nuvem com OpenShift, o PaaS open source da Red Hat
Fabiano Franz
 
PDF
Python and Flask introduction for my classmates Презентация и введение в flask
Nikita Lozhnikov
 
ODP
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
Eric D. Schabell
 
PPTX
Flask-Python
Triloki Gupta
 
PDF
Openshift cheat rhce_r3v1 rhce
Darnette A
 
PDF
OpenShift State of the Union, brought to you by JBoss
Eric D. Schabell
 
PPTX
Server deployment
bsadd
 
PDF
Codemotion 2012 Rome - An OpenShift Primer
Eric D. Schabell
 
PDF
Introduction to rest using flask
Wekanta
 
Workshop For pycon13
Steven Pousty
 
Deploying Flask web app using OpenShift
Abhijeet Kasurde
 
NLUUG Spring 2012 - OpenShift Primer
Eric D. Schabell
 
Openshift Presentation ppt compare with VM
shubhamage1
 
Openshift Presentation ppt compare with VM
shubhamage1
 
From Code to Cloud - PHP on Red Hat's OpenShift
Eric D. Schabell
 
Open shift intro for Philly PUG
Steven Pousty
 
Open shift
marcolof
 
OpenShift Primer - get your business into the Cloud today!
Eric D. Schabell
 
Chapter 06: Eclipse Vert.x - Reactive Microservices with OpenShift
Firmansyah, SCJP, OCEWCD, OCEWSD, TOGAF, OCMJEA, CEH
 
DevOps of Python applications using OpenShift (Italian version)
Francesco Fiore
 
Rodando *qualquer coisa* na nuvem com OpenShift, o PaaS open source da Red Hat
Fabiano Franz
 
Python and Flask introduction for my classmates Презентация и введение в flask
Nikita Lozhnikov
 
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
Eric D. Schabell
 
Flask-Python
Triloki Gupta
 
Openshift cheat rhce_r3v1 rhce
Darnette A
 
OpenShift State of the Union, brought to you by JBoss
Eric D. Schabell
 
Server deployment
bsadd
 
Codemotion 2012 Rome - An OpenShift Primer
Eric D. Schabell
 
Introduction to rest using flask
Wekanta
 
Ad

More from Bruno Rocha (9)

PDF
Escrevendo modulos python com rust
Bruno Rocha
 
PDF
The quality of the python ecosystem - and how we can protect it!
Bruno Rocha
 
PDF
A Qualidade do Ecossistema Python - e o que podemos fazer para mante-la
Bruno Rocha
 
PDF
PyData - Consumindo e publicando web APIs com Python
Bruno Rocha
 
PDF
Web Crawling Modeling with Scrapy Models #TDC2014
Bruno Rocha
 
PDF
Guia alimentar de dietas vegetarianas para adultos
Bruno Rocha
 
ODP
Desmistificando web2py - #TDC2011
Bruno Rocha
 
PDF
Using web2py's DAL in other projects or frameworks
Bruno Rocha
 
PPT
Desenvolvimento web ágil com Python e web2py #qconsp #qcon
Bruno Rocha
 
Escrevendo modulos python com rust
Bruno Rocha
 
The quality of the python ecosystem - and how we can protect it!
Bruno Rocha
 
A Qualidade do Ecossistema Python - e o que podemos fazer para mante-la
Bruno Rocha
 
PyData - Consumindo e publicando web APIs com Python
Bruno Rocha
 
Web Crawling Modeling with Scrapy Models #TDC2014
Bruno Rocha
 
Guia alimentar de dietas vegetarianas para adultos
Bruno Rocha
 
Desmistificando web2py - #TDC2011
Bruno Rocha
 
Using web2py's DAL in other projects or frameworks
Bruno Rocha
 
Desenvolvimento web ágil com Python e web2py #qconsp #qcon
Bruno Rocha
 

Recently uploaded (20)

PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Human Resources Information System (HRIS)
Amity University, Patna
 

Python Flask app deployed to OPenShift using Wercker CI