SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Patrick Muehlbauer
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleRoman 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 scratchJay Harrison
 
Making environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeMaking environment for_infrastructure_as_code
Making environment for_infrastructure_as_codeSoshi 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 solutionsSander 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 Systemadrian_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 PuppetColin 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 EckstrandSri 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 laptopLorin Hochstein
 
An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop InstallMike 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 AielloSri Ambati
 
Hadoop single cluster installation
Hadoop single cluster installationHadoop single cluster installation
Hadoop single cluster installationMinh 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 NutshellCoreOS
 
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 2017Codemotion
 
OpenStack for Centos
OpenStack for CentosOpenStack for Centos
OpenStack for CentosChandan 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 + ec2Yros
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 

Tendances (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
 

Similaire à Heroku pycon

Django deployment with PaaS
Django deployment with PaaSDjango deployment with PaaS
Django deployment with PaaSAppsembler
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi 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 2023Anthony Dahanne
 
Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023Henry Schreiner
 
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 introductionVictor Zhang
 
nuclio Overview October 2017
nuclio Overview October 2017nuclio Overview October 2017
nuclio Overview October 2017iguazio
 
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 meetingHenry Schreiner
 
Building a Django App on Heroku
Building a Django App on HerokuBuilding a Django App on Heroku
Building a Django App on HerokuJoe Fusaro
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-wayRobert 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 ToolingHenry 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
 
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 2014biicode
 
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++-APIYoni Davidson
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshopAssaf Gannon
 

Similaire à 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
 

Dernier

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 

Dernier (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

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