- 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.
- 30天自制操作系統
- 玩到極致 iPhone 4S完全攻略
- Kubernetes從入門到實踐
- 無蘋果不生活 The New iPad隨身寶典
- ElasticSearch Cookbook
- 新編電腦辦公(Windows 10+ Office 2013版)從入門到精通
- Hands-On GPU Programming with Python and CUDA
- Windows 7實戰從入門到精通(超值版)
- Linux網絡操作系統項目教程(RHEL 7.4/CentOS 7.4)(第3版)(微課版)
- 大學計算機應用基礎實踐教程(Windows 7+MS Office 2010)
- bash shell腳本編程經典實例(第2版)
- 大規模分布式系統架構與設計實戰
- Learning Joomla! 3 Extension Development(Third Edition)
- 每天5分鐘玩轉Docker容器技術
- Website Development with PyroCMS