Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deploy de aplicações Python no Heroku

Deploy de aplicações Python no Heroku

Palestra promovida pelo CleanDev na Uni-FACEF, Franca - SP.

Tags: Python, Heroku, Flask, Bootstrap, Git

Avatar for Bruno Freitas

Bruno Freitas

September 13, 2014
Tweet

More Decks by Bruno Freitas

Other Decks in Programming

Transcript

  1. +

  2. +

  3. - Python - Virtualenv →  pip  install  virtualenv - Conta

    no Heroku →  https://id.heroku.com/signup Pré-requisitos
  4. heroku  login   Enter  your  Heroku  credentials.   Email:  [email protected]

      Password:   Could  not  find  an  existing  public  key.   Would  you  like  to  generate  one?  [Yn] Heroku toolbelt
  5. heroku  login   Enter  your  Heroku  credentials.   Email:  [email protected]

      Password:   Could  not  find  an  existing  public  key.   Would  you  like  to  generate  one?  [Yn]   Generating  new  SSH  public  key.   Uploading  ssh  public  key  ...  id_rsa.pub Heroku toolbelt
  6. git  clone  https://github.com/bmsatierf/hello.git   Cloning  into  'hello'...   remote:  Counting

     objects:  21,  done.   remote:  Compressing  objects:  100%  (14/14),  done   remote:  Total  21  (delta  4),  reused  21  (delta  4)   Receiving  objects:  100%  (21/21),  done.   Checking  connectivity...  done Clonando a aplicação
  7. ls  -­‐l   Procfile   README.md   hello.py   requirements.txt

      static   templates Conteúdo do diretório
  8. ls  -­‐l   Procfile   README.md   hello.py   requirements.txt

      static   templates Conteúdo do diretório
  9. ls  -­‐l   Procfile   README.md   hello.py   requirements.txt

      static   templates Conteúdo do diretório
  10. ls  -­‐l   Procfile   README.md   hello.py   requirements.txt

      static   templates Conteúdo do diretório
  11. ls  -­‐l   Procfile   README.md   hello.py   requirements.txt

      static   templates Conteúdo do diretório
  12. ls  -­‐l   Procfile   README.md   hello.py   requirements.txt

      static   templates Conteúdo do diretório
  13. ls  -­‐l   Procfile   README.md   hello.py   requirements.txt

      static   templates Conteúdo do diretório
  14. virtualenv  venv   New  python  executable  in  venv/bin/python2.7   Also

     creating  executable  in  venv/bin/python   Installing  setuptools,  pip...done.   ! ! Criar novo executável
  15. pip  install  -­‐r  requirements.txt   Downloading/unpacking  Flask==0.10.1      Downloading

     Flask-­‐0.10.1.tar.gz  (544kB)      Running  setup.py  ...   ! ! Instalar dependências
  16. foreman  start   14:34:48  web.1  |  Starting  gunicorn  19.1.1  

    14:34:48  web.1  |  Listening  http://0.0.0.0:5000   14:34:48  web.1  |  Using  worker:  sync   14:34:48  web.1  |  Booting  worker  with  pid:  3341   ! Iniciar servidor local
  17. foreman  start   14:34:48  web.1  |  Starting  gunicorn  19.1.1  

    14:34:48  web.1  |  Listening  http://0.0.0.0:5000   14:34:48  web.1  |  Using  worker:  sync   14:34:48  web.1  |  Booting  worker  with  pid:  3341   ! Iniciar servidor local
  18. heroku  rename  hey-­‐flask   Renaming  hey-­‐flask  to  hello-­‐flask...  failed  

     !        Name  is  already  taken   ! ! ! Renomear App
  19. heroku  rename  hey-­‐flask   Renaming  hey-­‐flask  to  hello-­‐flask...  failed  

     !        Name  is  already  taken   ! ! ! Renomear App
  20. heroku  rename  oi-­‐flask   Renaming  cool-­‐night-­‐123  to  oi-­‐flask...  done  

    http://oi-­‐flask.herokuapp.com  ...   Git  remote  heroku  updated   ! ! Renomear App
  21. git  push  heroku  master   Initializing  repository,  done.   Counting

     objects:  21,  done.   Delta  compression  using  up  to  8  threads.   Compressing  objects:  100%  (18/18),  done.   Writing  objects:  100%  (21/21),  38.09  KiB   Total  21  (delta  4),  reused  0  (delta  0) Subir para o Heroku
  22. git  push  heroku  master   ! [...]   ! -­‐-­‐-­‐-­‐-­‐>

     Python  app  detected   -­‐-­‐-­‐-­‐-­‐>  Installing  runtime  (python-­‐2.7.8)   -­‐-­‐-­‐-­‐-­‐>  Installing  dependencies  with  pip Subir para o Heroku
  23. git  push  heroku  master   -­‐-­‐-­‐-­‐-­‐>  Discovering  process  types  

                 Procfile  declares  types  -­‐>  web   ! -­‐-­‐-­‐-­‐-­‐>  Compressing...  done,  30.4MB   -­‐-­‐-­‐-­‐-­‐>  Launching...  done,  v3                http://oi-­‐flask.herokuapp.com  deployed Subir para o Heroku
  24. Atualizar email de contato 1. Abrir um editor de textos

    →  subl  . 2. Editar o arquivo contato.html (pasta templates) 3. Salvar a modificação
  25. git  status   #  On  branch  master   #  Changes

     not  staged  for  commit:   #      (use  "git  add  <file>..."   #      (use  "git  checkout  -­‐-­‐  <file>..."   #   #   modified:      templates/contato.html Status dos arquivos
  26. git  status   #  On  branch  master   #  Changes

     not  staged  for  commit:   #      (use  "git  add  <file>..."   #      (use  "git  checkout  -­‐-­‐  <file>..."   #   #   modified:      templates/contato.html Status dos arquivos
  27. git  diff  templates/contato.html   !    [...]   ! -­‐

     <p><a  href="mailto:[email protected]">  ..   +  <p><a  href="mailto:[email protected]">    ..   Visualizar mudanças
  28. git  diff  templates/contato.html   !    [...]   ! -­‐

     <p><a  href="mailto:[email protected]">  ..   +  <p><a  href="mailto:[email protected]">    ..   Visualizar mudanças
  29. git  add  templates/contato.html   git  commit  -­‐m  “Update  email  address”

      [master  feb66f9]  Update  contact  email    1  file  changed,  1  insertion(+),  1  deletion(-­‐)   ! ! Confirmar mudanças
  30. git  add  templates/contato.html   git  commit  -­‐m  “Update  email  address”

      [master  feb66f9]  Update  contact  email    1  file  changed,  1  insertion(+),  1  deletion(-­‐)   ! ! Confirmar mudanças
  31. git  add  templates/contato.html   git  commit  -­‐m  “Update  email  address”

      [master  feb66f9]  Update  contact  email    1  file  changed,  1  insertion(+),  1  deletion(-­‐)   ! ! Confirmar mudanças
  32. git  add  templates/contato.html   git  commit  -­‐m  “Update  email  address”

      [master  feb66f9]  Update  contact  email    1  file  changed,  1  insertion(+),  1  deletion(-­‐)   ! ! Confirmar mudanças
  33. git  push  heroku   Fetching  repository,  done.   Counting  objects:

     7,  done.   Delta  compression  using  up  to  8  threads.   Compressing  objects:  100%  (4/4),  done.   Writing  objects:  100%  (4/4),  366  bytes   Total  4  (delta  3),  reused  0  (delta  0) Atualizar o Heroku