SlideShare a Scribd company logo
Heroku: how to deploy a Django
app in less 10 minutes!
Sabatino Severino
sab@pentatechnology.it
Firenze
21/04/2018
About Me
● Python Developer & Data Scientist
● Deep Learning Analytics for Satellite
Imagery
● Official Pycon9 App Developer
sab@pentatechnology.it
@bsab
linkedin.com/in/severinosab
Heroku: how to deploy a Django
app in less 10 minutes!
“manually configure and maintain virtualized
servers that run our application“
Deployment
Let me tell you a
story….
1. choose and set up an EC2
2. select a CPU, amounts of RAM and storage
3. set up SSH
4. ….
Security
Scaling
Hire a DevOps
Engineer
7
PAAS
What is PAAS?
Platform-as-a-service enables developers
to create innovative applications without
operational overhead around
configuration, deployment and
management.
Cloud vendors manages
infrastructure.
You manage platforms
and apps
IaaS
Layers of infrastructure
Cloud vendors manages
infrastructure and
platforms.
You manage apps
PaaS
Cloud vendors manages
infrastructure, platforms
and apps.
You manage nothing...
SaaS
Infrastructure
Applications
Platform
Infrastructure
Applications
Platform
Infrastructure
Applications
Platform
Amazon EC2, Windows Azure,
Rackspace, Google Compute Engine
AWS Elastic Beanstalk, Windows Azure, Heroku,
Force.com, Google App Engine, Apache Stratos
Google Apps, Microsoft Office 365
Efficient, Secure, Elastic
● Applications co-located on a few-servers
● Drastically reduces resources
● Add/Remove servers depending on load
● All secure using SELinux or LXC
Let them do
boring stuff
Who are the
players?
What is Heroku?
Heroku is a platform as a service
(PaaS) that enables developers
to build, run, and operate
applications entirely in the cloud.
Boosting app development with Add-Ons
I
II
III
IV
Codebase
12 Factor App
Dependencies
Config
Concurrency
Disposability
Dev/Prod parity
Port Binding
V
VI
VII
VIII
IX
X
XI
XII
Backing Services
Build, release, run
Processes
Logs
Admin processes
12factor.net
Heroku core language support
Virtually every language you can think of is supported by
community buildpacks
https://devcenter.heroku.com/articles/third-party-buildpacks
Dynos
Dynos
Scaling
Let’s go!
Preparing the application
● Add a Procfile in the project root
● Add requirements.txt file with all the requirements in the project root
● Add Gunicorn to requirements.txt
● A runtime.txt to specify the correct Python version in the project root
● Configure whitenoise to serve static files
web: gunicorn pycon9_demo.wsgi --log-file -
The Procfile
Django==1.11
django-material
django-fieldbook
fieldbook_py
python-decouple
gunicorn==19.6.0
whitenoise==3.2
psycopg2==2.6.2
dj-database-url==0.4.1
requirements.txt
$ pip freeze > requirements.txt
python-2.7.14
runtime.txt
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
Set Up The Static Assets
Update the settings.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"pycon9_demo.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
Update the wsgi.py file:
STATICFILES_STORAGE = 'whitenoise.django.CompressedManifestStaticFilesStorage
Update the settings.py
WhiteNoise
http://whitenoise.evans.io/en/stable/
Set Up the Environment Variables
Update the settings.py
SECRET_KEY = config('SECRET_KEY')
DEBUG = config('DEBUG', default=False, cast=bool)
DATABASES = {
'default': dj_database_url.config(
default=config('DATABASE_URL')
)
}
● python-decouple: Strictly separate the settings parameters from your source code.
● dj-database-url: This simple Django utility allows you to utilize the 12factor inspired
DATABASE_URL environment variable to configure your Django application.
Let’s get the deployment started!
$ git clone https://github.com/bsab/pycon9_demo.git && cd pycon9_demo
1) clone the repository you want to deploy :
$ heroku login
2) login to Heroku using the CLI:
$ heroku create pycon9-demo
3) inside the project root, create the Heroku App:
Creating ⬢ pycon9-demo... done
https://pycon9-demo.herokuapp.com/ |
https://git.heroku.com/pycon9-demo.git
*You can omit the app name parameter (in my case, django-fieldbook), then Heroku
will pick a name for you.
$ heroku addons:create heroku-postgresql:hobby-dev
4) add a PostgreSQL database to your app
Creating postgresql-metric-21979... done, (free)
Adding postgresql-metric-21979 to pycon9_demo... done
Setting DATABASE_URL and restarting pycon9_demo... done, v4
Database has been created and is available
$ git push heroku master
5) push to deploy
Counting objects: 1999, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (616/616), done.
Writing objects: 100% (1999/1999), 461.28 KiB | 0 bytes/s, done.
Total 1999 (delta 1139), reused 1983 (delta 1131)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-2.7.13
remote: $ pip install -r requirements.txt
...
remote: -----> Launching...
remote: Released v5
remote: https://pycon9-demo.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/pycon9_demo.git
* [new branch] master -> master
$ heroku run python manage.py migrate
6) migrate the database
Running python manage.py migrate on ⬢ pycon9_demo... up, run.9352
Operations to perform:
Apply all migrations: questions, sessions, authentication, articles, feeds,
contenttypes, messenger, activities, auth
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying questions.0001_initial... OK
Applying feeds.0001_initial... OK
Applying articles.0001_initial... OK
Applying activities.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying authentication.0001_initial... OK
Applying messenger.0001_initial... OK
Applying sessions.0001_initial... OK
And there you go!
https://pycon9-demo.herokuapp.com/
Total Time:
Wrap Up
● The application “sleeps” after 30 minutes of inactivity. The first access after it might
be slow.
● The free PostgreSQL database has a limitation of 10K rows.
● If you need to store user uploaded files (media), you will need a service to store the
files (Amazon S3)
So what?
Use Heroku:
● for small personal projects
● if you are an agency
● get started very quickly
● just want to play around
● a Free SSL Certificate!
Don’t use Heroku:
● if you can afford to have an expert in devops
● for production load with SLA’s
● additional control over your infrastructure
Thanks

More Related Content

What's hot

Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018
Patrick Muehlbauer
 
Hadoop 설치
Hadoop 설치Hadoop 설치
Hadoop 설치
Taehoon Kim
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with Ansible
Roman Rodomansky
 
Running hadoop on ubuntu linux
Running hadoop on ubuntu linuxRunning hadoop on ubuntu linux
Running hadoop on ubuntu linuxTRCK
 
Salting new ground one man ops from scratch
Salting new ground   one man ops from scratchSalting new ground   one man ops from scratch
Salting new ground one man ops from scratch
Jay Harrison
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_code
Soshi Nemoto
 
Using Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutionsUsing Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutions
Sander van der Burg
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
adrian_nye
 
Deploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetDeploying E.L.K stack w Puppet
Deploying E.L.K stack w Puppet
Colin Brown
 
Basic H2O for Python with Eric Eckstrand
Basic H2O for Python with Eric EckstrandBasic H2O for Python with Eric Eckstrand
Basic H2O for Python with Eric Eckstrand
Sri Ambati
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
Lorin Hochstein
 
An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop Install
Mike Frampton
 
Intro to R and H2O with Spencer Aiello
Intro to R and H2O with Spencer AielloIntro to R and H2O with Spencer Aiello
Intro to R and H2O with Spencer Aiello
Sri Ambati
 
Hadoop single cluster installation
Hadoop single cluster installationHadoop single cluster installation
Hadoop single cluster installation
Minh Tran
 
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios
 
CoreOS in a Nutshell
CoreOS in a NutshellCoreOS in a Nutshell
CoreOS in a Nutshell
CoreOS
 
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Codemotion
 
OpenStack for Centos
OpenStack for CentosOpenStack for Centos
OpenStack for Centos
Chandan Kumar
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Yros
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 

What's hot (20)

Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018
 
Hadoop 설치
Hadoop 설치Hadoop 설치
Hadoop 설치
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with Ansible
 
Running hadoop on ubuntu linux
Running hadoop on ubuntu linuxRunning hadoop on ubuntu linux
Running hadoop on ubuntu linux
 
Salting new ground one man ops from scratch
Salting new ground   one man ops from scratchSalting new ground   one man ops from scratch
Salting new ground one man ops from scratch
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_code
 
Using Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutionsUsing Nix and Docker as automated deployment solutions
Using Nix and Docker as automated deployment solutions
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Deploying E.L.K stack w Puppet
Deploying E.L.K stack w PuppetDeploying E.L.K stack w Puppet
Deploying E.L.K stack w Puppet
 
Basic H2O for Python with Eric Eckstrand
Basic H2O for Python with Eric EckstrandBasic H2O for Python with Eric Eckstrand
Basic H2O for Python with Eric Eckstrand
 
Vagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptopVagrant, Ansible, and OpenStack on your laptop
Vagrant, Ansible, and OpenStack on your laptop
 
An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop Install
 
Intro to R and H2O with Spencer Aiello
Intro to R and H2O with Spencer AielloIntro to R and H2O with Spencer Aiello
Intro to R and H2O with Spencer Aiello
 
Hadoop single cluster installation
Hadoop single cluster installationHadoop single cluster installation
Hadoop single cluster installation
 
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
 
CoreOS in a Nutshell
CoreOS in a NutshellCoreOS in a Nutshell
CoreOS in a Nutshell
 
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
Nicola Iarocci - Git stories from the front line - Codemotion Milan 2017
 
OpenStack for Centos
OpenStack for CentosOpenStack for Centos
OpenStack for Centos
 
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2Dev ninja  -> vagrant + virtualbox + chef-solo + git + ec2
Dev ninja -> vagrant + virtualbox + chef-solo + git + ec2
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 

Similar to Heroku pycon

Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaS
Appsembler
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
Haiqi Chen
 
CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023
Anthony Dahanne
 
Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023
Henry Schreiner
 
Django
DjangoDjango
iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)
Eran Duchan
 
OpenStack Murano introduction
OpenStack Murano introductionOpenStack Murano introduction
OpenStack Murano introduction
Victor Zhang
 
Ladypy 01
Ladypy 01Ladypy 01
Ladypy 01
Calvin Cheng
 
nuclio Overview October 2017
nuclio Overview October 2017nuclio Overview October 2017
nuclio Overview October 2017
iguazio
 
Digital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingDigital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meeting
Henry Schreiner
 
Building a Django App on Heroku
Building a Django App on HerokuBuilding a Django App on Heroku
Building a Django App on Heroku
Joe Fusaro
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
Robert Lujo
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!
Anthony Dahanne
 
Princeton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance ToolingPrinceton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance Tooling
Henry Schreiner
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Jian-Hong Pan
 
R sharing 101
R sharing 101R sharing 101
R sharing 101
Omnia Safaan
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
biicode
 
IzPack at LyonJUG'11
IzPack at LyonJUG'11IzPack at LyonJUG'11
IzPack at LyonJUG'11julien.ponge
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
Yoni Davidson
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshop
Assaf Gannon
 

Similar to Heroku pycon (20)

Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaS
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023CNCF Québec Meetup du 16 Novembre 2023
CNCF Québec Meetup du 16 Novembre 2023
 
Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023
 
Django
DjangoDjango
Django
 
iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)iguazio - nuclio overview to CNCF (Sep 25th 2017)
iguazio - nuclio overview to CNCF (Sep 25th 2017)
 
OpenStack Murano introduction
OpenStack Murano introductionOpenStack Murano introduction
OpenStack Murano introduction
 
Ladypy 01
Ladypy 01Ladypy 01
Ladypy 01
 
nuclio Overview October 2017
nuclio Overview October 2017nuclio Overview October 2017
nuclio Overview October 2017
 
Digital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingDigital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meeting
 
Building a Django App on Heroku
Building a Django App on HerokuBuilding a Django App on Heroku
Building a Django App on Heroku
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 
No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!No more Dockerfiles? Buildpacks to help you ship your image!
No more Dockerfiles? Buildpacks to help you ship your image!
 
Princeton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance ToolingPrinceton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance Tooling
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
 
R sharing 101
R sharing 101R sharing 101
R sharing 101
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
IzPack at LyonJUG'11
IzPack at LyonJUG'11IzPack at LyonJUG'11
IzPack at LyonJUG'11
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshop
 

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 

Heroku pycon

  • 1. Heroku: how to deploy a Django app in less 10 minutes! Sabatino Severino sab@pentatechnology.it Firenze 21/04/2018
  • 2. About Me ● Python Developer & Data Scientist ● Deep Learning Analytics for Satellite Imagery ● Official Pycon9 App Developer sab@pentatechnology.it @bsab linkedin.com/in/severinosab
  • 3. Heroku: how to deploy a Django app in less 10 minutes!
  • 4. “manually configure and maintain virtualized servers that run our application“ Deployment
  • 5. Let me tell you a story….
  • 6. 1. choose and set up an EC2 2. select a CPU, amounts of RAM and storage 3. set up SSH 4. ….
  • 9.
  • 11. PAAS
  • 12. What is PAAS? Platform-as-a-service enables developers to create innovative applications without operational overhead around configuration, deployment and management.
  • 13. Cloud vendors manages infrastructure. You manage platforms and apps IaaS Layers of infrastructure Cloud vendors manages infrastructure and platforms. You manage apps PaaS Cloud vendors manages infrastructure, platforms and apps. You manage nothing... SaaS Infrastructure Applications Platform Infrastructure Applications Platform Infrastructure Applications Platform Amazon EC2, Windows Azure, Rackspace, Google Compute Engine AWS Elastic Beanstalk, Windows Azure, Heroku, Force.com, Google App Engine, Apache Stratos Google Apps, Microsoft Office 365
  • 14. Efficient, Secure, Elastic ● Applications co-located on a few-servers ● Drastically reduces resources ● Add/Remove servers depending on load ● All secure using SELinux or LXC
  • 17. What is Heroku? Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.
  • 18.
  • 19.
  • 20. Boosting app development with Add-Ons
  • 21. I II III IV Codebase 12 Factor App Dependencies Config Concurrency Disposability Dev/Prod parity Port Binding V VI VII VIII IX X XI XII Backing Services Build, release, run Processes Logs Admin processes 12factor.net
  • 22. Heroku core language support Virtually every language you can think of is supported by community buildpacks https://devcenter.heroku.com/articles/third-party-buildpacks
  • 23. Dynos
  • 24. Dynos
  • 26.
  • 28. Preparing the application ● Add a Procfile in the project root ● Add requirements.txt file with all the requirements in the project root ● Add Gunicorn to requirements.txt ● A runtime.txt to specify the correct Python version in the project root ● Configure whitenoise to serve static files
  • 29. web: gunicorn pycon9_demo.wsgi --log-file - The Procfile
  • 32. PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/1.9/howto/static-files/ STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') STATIC_URL = '/static/' # Extra places for collectstatic to find static files. STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, 'static'), ) Set Up The Static Assets Update the settings.py
  • 33. import os from django.core.wsgi import get_wsgi_application from whitenoise.django import DjangoWhiteNoise os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pycon9_demo.settings") application = get_wsgi_application() application = DjangoWhiteNoise(application) Update the wsgi.py file: STATICFILES_STORAGE = 'whitenoise.django.CompressedManifestStaticFilesStorage Update the settings.py WhiteNoise http://whitenoise.evans.io/en/stable/
  • 34. Set Up the Environment Variables Update the settings.py SECRET_KEY = config('SECRET_KEY') DEBUG = config('DEBUG', default=False, cast=bool) DATABASES = { 'default': dj_database_url.config( default=config('DATABASE_URL') ) } ● python-decouple: Strictly separate the settings parameters from your source code. ● dj-database-url: This simple Django utility allows you to utilize the 12factor inspired DATABASE_URL environment variable to configure your Django application.
  • 35. Let’s get the deployment started!
  • 36. $ git clone https://github.com/bsab/pycon9_demo.git && cd pycon9_demo 1) clone the repository you want to deploy : $ heroku login 2) login to Heroku using the CLI:
  • 37. $ heroku create pycon9-demo 3) inside the project root, create the Heroku App: Creating ⬢ pycon9-demo... done https://pycon9-demo.herokuapp.com/ | https://git.heroku.com/pycon9-demo.git *You can omit the app name parameter (in my case, django-fieldbook), then Heroku will pick a name for you.
  • 38. $ heroku addons:create heroku-postgresql:hobby-dev 4) add a PostgreSQL database to your app Creating postgresql-metric-21979... done, (free) Adding postgresql-metric-21979 to pycon9_demo... done Setting DATABASE_URL and restarting pycon9_demo... done, v4 Database has been created and is available
  • 39. $ git push heroku master 5) push to deploy Counting objects: 1999, done. Delta compression using up to 4 threads. Compressing objects: 100% (616/616), done. Writing objects: 100% (1999/1999), 461.28 KiB | 0 bytes/s, done. Total 1999 (delta 1139), reused 1983 (delta 1131) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Python app detected remote: -----> Installing python-2.7.13 remote: $ pip install -r requirements.txt ... remote: -----> Launching... remote: Released v5 remote: https://pycon9-demo.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy.... done. To https://git.heroku.com/pycon9_demo.git * [new branch] master -> master
  • 40. $ heroku run python manage.py migrate 6) migrate the database Running python manage.py migrate on ⬢ pycon9_demo... up, run.9352 Operations to perform: Apply all migrations: questions, sessions, authentication, articles, feeds, contenttypes, messenger, activities, auth Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying questions.0001_initial... OK Applying feeds.0001_initial... OK Applying articles.0001_initial... OK Applying activities.0001_initial... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying authentication.0001_initial... OK Applying messenger.0001_initial... OK Applying sessions.0001_initial... OK
  • 41. And there you go! https://pycon9-demo.herokuapp.com/
  • 43. Wrap Up ● The application “sleeps” after 30 minutes of inactivity. The first access after it might be slow. ● The free PostgreSQL database has a limitation of 10K rows. ● If you need to store user uploaded files (media), you will need a service to store the files (Amazon S3)
  • 44. So what? Use Heroku: ● for small personal projects ● if you are an agency ● get started very quickly ● just want to play around ● a Free SSL Certificate!
  • 45. Don’t use Heroku: ● if you can afford to have an expert in devops ● for production load with SLA’s ● additional control over your infrastructure