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

Test driving Heroku

What fun is it to see a Ferrari and not drive it? So, let us put on our seatbelts and take Heroku for a spin. We assume that we are running the Heroku client on a Windows 7 machine. We assume that we have the Windows version of the Heroku toolbelt (download instructions in the prerequisites section). We have also created and added the SSH key to our Heroku account.

In this section, we will create a barebones Rails 3 app on the Heroku platform. You can use any other supported language, yet the steps won't change except for the language specific details (buildpack used). First and foremost, we need a few things up and running before we can create our first app on Heroku. These requirements are specific to the language we use here.

So, before we get started:

  1. Ensure you have certain prerequisites for the Rails 3 example. You need:
  2. Check if the Heroku client is installed and in the path open the command prompt and type:
    $ heroku
    

    You will get the Heroku usage help as follows:

    Test driving Heroku
  3. Log in using the e-mail address and password you used when creating your Heroku account:
    $ heroku login
    Enter your Heroku credentials.
    Email: xxxx@yyyy.com
    Password:
    Could not find an existing public key.
    Would you like to generate one? [Yn]
    Generating new SSH public key.
    Uploading ssh public key /users/xxxx/.ssh/id_rsa.pub
    

    Press enter at the prompt to upload your ssh key or create a new one.

  4. Write a simple Rails 3 application:
    $ rails new sampleapp_rails3
    $ cd sampleapp_rails3
    
  5. Edit your Gemfile (Gemfile is a file that contains the list of names of libraries/gem files your application needs to function correctly) and change gem 'sqlite3' to gem 'pg'.

    This change enables the application to use the newly introduced Heroku PostgreSQL database instead of SQLite.

  6. Re-install your dependencies (to generate new Gemfile.lock):
    $ bundle install
    
  7. Create your app in Git as shown in the following figure:
    Test driving Heroku
  8. To open a Heroku app, type the open command on the Heroku CLI:
    $ heroku open
    Opening pink-poppies-786… done
    
  9. Check the status of running Heroku processes, type the ps (process status) command as follows:
    $ heroku ps
    === web: `bundle exec rails server –p $PORT`web.1: up for 5s
    
  10. To support more concurrent users, you need to scale up your application. Increase the web dyno count from the Heroku command line. Use the ps:scale command to scale up the web processes to 2 as follows:
    $ heroku ps:scale web=2
    
  11. If you encounter any issues while running the Heroku app, you can use the logs command to get the details of most recent messages and use the information to troubleshoot pertinent issues as shown in the following figure:
    Test driving Heroku

That completes our test drive of Heroku. We created a Heroku account, added our SSH key to Heroku, and wrote a barebones Rails3 app and deployed it on Heroku. Finally, to troubleshoot, we used the logs command to see what was going on behind the scenes just in case something needed attention.

主站蜘蛛池模板: 新巴尔虎左旗| 五大连池市| 德阳市| 保山市| 陈巴尔虎旗| 湖州市| 永兴县| 左贡县| 富民县| 伊宁县| 长顺县| 西平县| 宾阳县| 嫩江县| 乌鲁木齐市| 巴青县| 云梦县| 肇源县| 贡山| 精河县| 巴塘县| 雷波县| 衡水市| 志丹县| 湘潭市| 隆德县| 潮州市| 体育| 正阳县| 博客| 滨州市| 比如县| 津南区| 淮安市| 宁阳县| 怀化市| 开原市| 随州市| 防城港市| 清原| 临城县|