官术网_书友最值得收藏!

Installing add-ons

Our application needs some additional functionality provided by an outside service. What should we do? In the past, this would have involved creating accounts, managing credentials, and maybe even bringing up servers and installing software. This whole process has been simplified by the Heroku add-on marketplace.

For any additional functionality that our application needs, our first stop should always be Heroku add-ons. Heroku has made attaching additional resources to our application a plug-and-play process. If we need an additional database, caching, or error logging, they can be set up with a single command.

In this recipe, we will learn the ins and outs of using the Heroku CLI to install and manage our application's add-ons.

How to do it...

To begin, let's open a terminal and navigate to one of our Heroku applications using the following steps:

  1. Let's start by taking a look at all of the available Heroku add-ons. We can do this with the addons:list command:
    $ heroku addons:list
    

    There are so many add-ons that viewing them through the CLI is pretty difficult. For easier navigation and search, we should take a look at https://addons.heroku.com/.

  2. If we want to see the currently installed add-ons for our application, we can simply type the following:
    $ heroku addons
     === load-tester-rails Configured Add-ons
     heroku-postgresql:dev HEROKU_POSTGRESQL_MAROON
     heroku-postgresql:hobby-dev HEROKU_POSTGRESQL_ONYX
     librato:development
     newrelic:stark
    

    Note

    Remember that for any command, we can always add --app app_name to specify the application.

  3. Alternatively, our application's add-ons are also listed through the Heroku Dashboard available at https://dashboard.heroku.com.
  4. The installation of a new add-on is done with addons:add. Here, we are going to install the error logging service, Rollbar:
    $ heroku addons:add rollbar
     heroku addons:add rollbar
     Adding rollbar on load-tester-rails... done, v22 (free)
     Use `heroku addons:docs rollbar` to view documentation.
    
  5. We can quickly open up the documentation for an add-on with addons:docs:
    $ heroku addons:docs rollbar
    
  6. Removing an add-on is just as simple. We'll need to type our application name to confirm. For this example, our application is called load-tester-rails:
    $ heroku addons:remove rollbar
    
     ! WARNING: Destructive Action
     ! This command will affect the app: load-tester-rails
     ! To proceed, type "load-tester-rails" or re-run this command with --confirm load-tester-rails
    
    > load-tester-rails
    Removing rollbar on load-tester-rails... done, v23 (free)
    
  7. Each add-on comes with different tiers of service. Let's try upgrading our rollbar add-on to the starter tier:
    $ heroku addons:upgrade rollbar:starter
    Upgrading to rollbar:starter on load-tester-rails... done, v26 ($12/mo)
    Plan changed to starter
    Use `heroku addons:docs rollbar` to view documentation.
    
  8. Now, if we want, we can downgrade back to its original level with addons:downgrade:
    $ heroku addons:downgrade rollbar
    Downgrading to rollbar on load-tester-rails... done, v27 (free)
    Plan changed to free
    Use `heroku addons:docs rollbar` to view documentation.
    
  9. If we ever forget any of the commands, we can always use help to quickly see the documentation:
    $ heroku help addons
    

    Note

    Some add-ons might charge you money. Before continuing, let's double check that we only have the correct ones enabled, using the $ heroku addons command.

How it works…

Heroku has created a standardized process for all add-on providers to follow. This ensures a consistent experience when provisioning any add-ons for our application.

It starts when we request the creation of an add-on. Heroku sends an HTTP request to the provider, asking them to provision an instance of their service. The provider must then respond to Heroku with the connection details for their service in the form of environment variables. For example, if we were to provision Redis To Go, we will get back our connection details in a REDISTOGO_URL variable:

REDISTOGO_URL: redis://user:pass@server.redistogo.com:9652

Heroku adds these variables to our application and restarts it. On restart, the variables are available for our application, and we can connect to the service using them. The specifics on how to connect using the variables will be in the add-ons documentation. Installation will depend on the specific language or framework we're using.

See also

主站蜘蛛池模板: 南康市| 衡东县| 察雅县| 芜湖县| 石景山区| 台山市| 双江| 沁源县| 公安县| 咸阳市| 山阴县| 滕州市| 虞城县| 望谟县| 阿勒泰市| 都匀市| 彰化市| 扎赉特旗| 宣化县| 马公市| 乌恰县| 双桥区| 河北省| 阳曲县| 宽城| 和田县| 大理市| 当阳市| 奈曼旗| 常德市| 南平市| 新密市| 台安县| 秭归县| 昂仁县| 迭部县| 宁蒗| 康保县| 太谷县| 通榆县| 衡南县|