- Heroku Cloud Application Development
- Anubhav Hanjura
- 524字
- 2021-08-20 17:55:03
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:
- Ensure you have certain prerequisites for the Rails 3 example. You need:
- Ruby 1.9.2 (the Ruby runtime toolbelt comes bundled with one)
- Ruby gems (http://rubygems.org)
- Bundler (http://rubygems.org/gems/bundler)
- Rails 3 (http://rubyonrails.org/)
- 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:
- 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. - Write a simple Rails 3 application:
$ rails new sampleapp_rails3 $ cd sampleapp_rails3
- 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'
togem 'pg'
.This change enables the application to use the newly introduced Heroku PostgreSQL database instead of SQLite.
- Re-install your dependencies (to generate new
Gemfile.lock
):$ bundle install
- Create your app in Git as shown in the following figure:
- To open a Heroku app, type the
open
command on the Heroku CLI:$ heroku open Opening pink-poppies-786… done
- 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
- 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 to2
as follows:$ heroku ps:scale web=2
- 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:
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.