Advertisement
Venciity

Heroku docs Notes

Mar 28th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.88 KB | None | 0 0
  1. Getting started with Python
  2. * Heroku CLI - Heroku command line interface
  3. * we can use this tool to manage our apps, add add-ons, view logs, etc.
  4. * prepare the app source code
  5. * create an app in Heroku
  6. * deploy the app
  7. * The application is now deployed. We can ensure that at least one instance of the app is running with this command:
  8. heroku ps:scale web=1
  9. * create a "Procfile" to explicitly declare what command should be executed to start your app
  10. * scale the app
  11. * now, our app is running on as single web dyno
  12. * dyno - lightweight container that run the command specified in the Procfile
  13. * we can check how many dynos are running using this command:
  14. heroku ps
  15. * by default an app is deployed on a free dyno
  16. * free dynos sleep after a half hour of inactivity
  17. * they have delay of a few seconds for the first request upon waking
  18. * subsiquent requests will perform normally
  19. * they consume from a monthly, account-level quantity of free dyno hours
  20. * scaling an app on Heroku is equivalent to changing the number of dynos that are running
  21. * you can scale the number of web dynos to zero using this command:
  22. heroku ps:scale web=0
  23. * or scale the number of web dynos to one using the same command:
  24. heroku ps:scale web=1
  25. * declare app dependencies
  26. * Heroku recognizes an app as a Pyhton app by existence of a Pipfile or requirements.txt in the root directory
  27. * Pipfile - lists the app dependencies with their versions
  28. * provision add-ons
  29. * add-ons are third-party cloud services that provide additional services for your app
  30. * start a console
  31. * you can run a command, typically scripts and applications that are part of your app in a one-off dyno using the "heroku run" command
  32. * definde confing files
  33. * you can define config files using:
  34. heroku config:set VARIABLE=42
  35. * provision a database
  36. * The add-on marketplace has a large number of data stores like: Redis, MongoDB, Postgres, MySQL, etc
  37.  
  38. How Heroku Works
  39. * Defining app
  40. * dependency mechanisms vary across languages
  41. * Ruby - Gemfile
  42. * Python - requirements.txt
  43. * Node.js - package.json
  44. * Java - pom.xml
  45. * the source code and the dependency file for your app should provide enough info for the Heroku platform to build your app, to produce something that can be executed
  46. * Knowing what to execute
  47. * for some apps you don't need to make many changes to an app in order to run it on Heroku
  48. * one requirement is informing the platform as to which parts of your app are runnable
  49. * if you use some established framework, Heroku can figure it out.
  50. * examples
  51. * Rails - rails server
  52. * Django - python <app>/manage.py runserver
  53. * Node.js - main field in package.json
  54. * for other apps you may need to explicitly declare what can be executed. You can do this in a text file that is in you source code - "Procfile"
  55. * example: https://devcenter.heroku.com/articles/how-heroku-works#knowing-what-to-execute
  56. * Deploying Apps
  57. * Heroku platform uses Git
  58. * when you create an app in Heroku, it creates a new Git remote (by default named: "Heroku")
  59. * you can use this command to deploy your code:
  60. git push heroku master
  61. * Building apps
  62. * when the Heroku platform receives the application source, it initiates a build of the source application.
  63. * the build mechanism is typically language specific, but follows the same pattern
  64. * retrieving the specified dependencies
  65. * create any necessary assets
  66. * examples
  67. * processing style sheets
  68. * compiling code
  69. * Advanced: buildpacks lie behind the "slug" compilation process
  70. * they take your app, it's dependencies, the language runtime, and produce "slugs"
  71. * they are open source
  72. * we can extend them to other languages and frameworks
  73. * slug - a bundle of:
  74. * your source
  75. * fetched dependencies
  76. * the language runtime
  77. * compiled/generated output of the build system - ready for execution
  78. * The slugs are a fundamental aspect of what happens during application execution
  79. * Running applications on dynos
  80. * Heroku executes apps by running a command you specified in your Procfile, on a dyno that is preloaded with your prepared slug.
  81. * We can think of a running dyno as a lightweight, secure, virtualized Unix container that contains your app slug in its file system
  82. * Dyno - isolated, virtualized Unix container, that provides the required environment to run an app.
  83. * to see all working dynos we can use the command:
  84. heroku ps
  85. * Config vars
  86. * An app's configuration is everything that is likely to vary between environments (staging, production, developer environments, etc.)
  87. * This includes backing services such as databases, credentials or environment variables that provide some specific info to your app
  88. * The configuration is stored in config vars
  89. * example:
  90. * Heroku config:set ENCRYPTION_KEY=my_secret_launch_codes
  91. * we can acces the above config var using this code: ENV["ENCRYPTION_KEY"]
  92. * Config vars contain customizable data that can be changed independently of your source code. The configuration is exposed to a running app via environment variables.
  93. * All dynos will have the exact same set of config variables at runtime.
  94. Releases
  95. * the combination of slug and configuration is called release
  96. * releases are an append-only ledger of slugs and config vars
  97. * to see all releases you can use the command: heroku releases
  98. * we can rollback and deploy a previos release using this command: heroku releases:rollback NUMBER_OF_THE_RELEASE
  99. * whenever you change a set of config vars associated with your app, a new release is generated
  100. Dyno manager
  101. * the dyno manager of the Heroku platform is responsible for managing dynos across all apps on Heroku
  102. * apps that use free dyno type will sleep, when sleeping app receives a HTTP traffic, it will be awaken - causing a delay of few seconds
  103. * one-off dynos are temporary dynos that can run with their input/output attached to your local machine. They're loaded with your lastest
  104. release.
  105. * example:
  106. * heroku run bash
  107. * this will spin up a new dyno, loaded with your release, and then run the "bash" command - which will provide you with a Unix shell. Once you've terminated your session, or after a period of inactivity, the dyno will be removed.
  108. !!! * Changes to the filesystem on one dyno are not propagated to other dynos and are not persisted across deploys and dyno restarts.
  109. * Each dyno gets it's own "emphemerical filesystem" - with a fresh copy fo the most recent release. It can be used as temporary scratch, but changes to the filesystem are not reflected to other dynos.
  110. Add-ons
  111. * Dynos don't share file state, and so add-ons that provide some kind of storage are typically used as a means of communication between dynos in an app.
  112. * exaple: Redis or Postgres can be used as the backing machanism in a queue.
  113. * add-ons are third party, specialized, value-added cloud services that can be easily attached to an application, extending it's functionality
  114. * examples
  115. * databases
  116. * queueing & caching systems
  117. * storage
  118. * email services
  119. * much like config vars, whenever you add, remove or changes add-on, a new release is created
  120. Logging and Monitoring
  121. * Heroku treat logs as streams of time-stamped events, and collates the stream of logs produced from all of the processes running in all dynos, and Heroku platform components, into "Logplex" - a high-performance, real-time system for log delivery.
  122. * Logplex automatically collates log entries from all the running dynos of your app,
  123. as well as other components such as routers, providing a single source of activity.
  124. * we can see our app's logs using the command:
  125. heroku logs
  126. * Logplex keeps a LIMITED buffer of log entries.
  127. HTTP Routing
  128. * Heroku's HTTP routers distribute incoming requests for your app across you running web dynos
  129. * scaling an app's capacity to handle web traffic involves scaling the number of web dynos:
  130. heroku ps:scale web+5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement