Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Implementing AppFog
Implementing AppFog

Implementing AppFog: Getting to grips with the AppFog service is easily achieved with this hands-on guide, which walks you through creating and deploying applications to the cloud. You'll be developing your first application in minutes.

eBook
£13.98 £19.99
Paperback
£24.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Implementing AppFog

Chapter 2. Using the Command-line Tool

In this chapter, we'll learn how to install and use the AppFog command-line tool. We'll use this tool to download the application we created in first chapter. We'll run this application locally, modify it, test it, and send it back to the cloud infrastructure.

When you complete this chapter, you'll understand the complete AppFog application lifecycle.

Installing the AppFog Gem


The AppFog command-line tool is packaged as a Ruby software package, known as a "Gem". If you are already using Ruby, simply install the Gem named af.

If you're not familiar with Ruby, refer to Appendix A, which contains instructions for installing Ruby and the AppFog Gem on common platforms.

To verify that the Gem is installed, enter the following command:

$ af version
af 0.3.16.5

You will see af followed by your version number. See Chapter 5, Command-line Reference for details on all the command-line options.

Logging in


Before you can access cloud resources, you have to log in by entering the following command:

$ af login

You will be prompted for the e-mail address and password you used to create the account. If you correctly entered your credentials, you will see the following:

Successfully logged into [https://api/appfog.com]

To check your login status, type the following command and you will see your e-mail address:

$ af user

Getting application statuses


Once logged in, you can check the status of applications you previously deployed:

$ af apps
+-------------+----+---------+---------------------+----------+-----+
| Application | #  | Health  | URLS                | Services | In  |
+-------------+----+---------+---------------------+----------+-----+
| insideaf1   | 1  | RUNNING | insideaf1.aws.af.cm |          | aws |
+-------------+----+---------+---------------------+----------+-----+

These fields correspond to information on the web control panel. Note that the application name is the same as the "domain name" you used to create the application. This is the name you'll use to manage the application from the command line.

Downloading the application


Use the pull command to download a deployed application, as shown in the following command:

$ af pull insideaf1
Pulling last pushed source code: OK

The application is downloaded to a local directory whose name is the same as the application name—in this case, insideaf1.

Fixing the application for Ruby 1.8.7


If you're using Ruby 1.9.2 or later, you can run the application unchanged; you can skip this section. To check which version of Ruby you are using, you can type:

$ ruby -v

If you're using Ruby 1.8.7, you'll have to modify the program. The problem is the main application source file app.rb. Here's the program as AppFog provides it:

require 'sinatra'
set :protection, except: :ip_spoofing

get '/' do
  erb :index
end

There are two problems with this code. They are as follows:

  • In Ruby 1.8.7, you have to explicitly indicate that you're using Gems. This is not necessary in later versions.

  • The set line is a workaround for a bug in the AppFog software. This bug has long since been fixed, but the set command does no harm in later versions of Ruby. However, it is syntactically incorrect in Ruby 1.8.7 so you should remove that line.

Edit the source code so it looks like this:

require 'rubygems'
require 'sinatra'

get '/' do
  erb :index
end

Note

Obviously, inconsistencies...

Running the application


The application requires the Sinatra Gem to run. If you don't know how to install this Gem, refer to Appendix A.

Go to the directory containing the application and use the Ruby command to run the main source file.

$ cd insideaf1
$ ruby app.rb 
[2013-04-18 13:59:22] INFO  WEBrick 1.3.1
[2013-04-18 13:59:22] INFO  ruby 1.9.3 (2012-04-20) [i686-linux]
== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from WEBrick
[2013-04-18 13:59:22] INFO  WEBrick::HTTPServer#start: pid=11048 port=4567

Now send your browser to http://localhost:4567/. The same application page you saw in Chapter 1, Getting started with Appfog appears. This time the application is running on your system instead of running on the cloud infrastructure.

To terminate the application, return to the command line and press Ctrl + C.

^C
== Sinatra has ended his set (crowd applauds)
[2013-04-18 14:51:49] INFO  going to shutdown ...
[2013-04-18 14:51:49] INFO  WEBrick::HTTPServer#start done...

Modifying the application


We're going to change the application slightly. Instead of displaying a simple message, we're going to display a list of environment variables and their values. Here's the Ruby program that does this on the command line:

ENV.each do |name, value|
  value = value[0..19] + "..." if value.length > 20
  print "#{name} = #{value}\n"
end

This is a simple loop that iterates through the name/value pairs in the program's environment. Many environment variable values are extremely long, so we truncate those that are longer than 20 characters.

In the Sinatra version of the application, the same logic is divided between the following two files:

  • app.rb, which contains the main Ruby source code.

  • views/index.erb, the ERB module that generates the page HTML.

Here's app.rb as provided by AppFog:

require 'sinatra'
set :protection, except: :ip_spoofing

get '/' do
  erb :index
end

The code we care about is contained in the last three lines. This specifies that an HTTP request to GET "...

Updating the running application


Once you have tested the local copy of your application, you're ready to update the copy running on the AppFog infrastructure, as follows:

$ af update insideaf1
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (28K): OK   
Push Status: OK
Stopping Application 'insideaf1': OK
Staging Application 'insideaf1': OK
Starting Application 'insideaf1': OK

Summary


In this chapter we:

  • Installed the AppFog command-line tools

  • Downloaded the application from AppFog

  • Modified the application and uploaded it back to AppFog

In the next chapter we will create an application that uses AppFog's built-in services to set up a database.

Left arrow icon Right arrow icon

Key benefits

  • Create applications from scratch using the AppFog web console
  • Learn the knack of deploying applications to the Cloud using AppFog
  • Know the steps to avoid compatibility issues using the node module function of AppFog.

Description

AppFog is the leading platform-as-a-service provider of PHP, Ruby, Node.js, and Java solutions. It is used by developers worldwide to deploy tens of thousands of applications. AppFog delivers a reliable, scalable, and fast platform for deploying applications in the cloud.This book is a hands-on guide that will walk you through creating and deploying applications to the cloud using AppFog, which will allow you to get your application deployed without the hassle of setting up servers.This book demonstrates how to use the AppFog service to build an application and have it running in the Cloud. It will walk you through the initial AppFog setup process and explain how to create your first application in minutes.You will also discover how to use services such as databases to make your applications more powerful. You will also learn how to create applications from scratch.You will find out everything you need to know to get an application running in the cloud for the first time.

Who is this book for?

Implementing AppFog is for developers who want to be able to upload applications to the cloud, and for implementation specialists, who implement and deploy apps on the AppFog platform. It is best to have Ruby installed, but we will walk you through the installation process if you do not already have it. It would be ideal to have some knowledge of cloud computing and know about the basics of database and network deployment.

What you will learn

  • Set up an account on AppFog
  • Download your application from the cloud so that you can make updates
  • Upload new versions of your application
  • Modify your application to use a database hosted by AppFog
  • Use the AppFog command line tools including a reference guide to all the command line options

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 19, 2013
Length: 86 pages
Edition : 1st
Language : English
ISBN-13 : 9781849698191
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 19, 2013
Length: 86 pages
Edition : 1st
Language : English
ISBN-13 : 9781849698191
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£169.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£234.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 96.97
Mastering Node.js
£41.99
Implementing AppFog
£24.99
iCloud Standard Guide
£29.99
Total £ 96.97 Stars icon

Table of Contents

5 Chapters
Getting Started with AppFog Chevron down icon Chevron up icon
Using the Command-line Tool Chevron down icon Chevron up icon
Configuring Services Chevron down icon Chevron up icon
Creating an Application from Scratch Chevron down icon Chevron up icon
Command-line Reference Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(4 Ratings)
5 star 25%
4 star 50%
3 star 0%
2 star 0%
1 star 25%
Doug Duncan Jan 07, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
"Implementing AppFog" by Matthew Nohr and Isaac Rabinovitch is a really quick read that packs a lot of information in a small amount of space. The authors have done an excellent job of explaining AppFog and how one interacts with it to create and maintain cloud based applications.The book is a total of 86 pages (including front matter, appendix and index) so you can see that the authors don't have a lot of pages to cover things, but those few pages that they have is filled with the information one needs to get up to speed on this service.The authors obviously don't go into great depth about everything in this book, but then that's not the focus of the book. It's really about learning how to get an application set up, modified and published and how to use services such as a database with those applications. You are exposed to both using the web based interface and the command line to accomplish these tasks.If you're interested in using AppFog to host your applications, this book will get you going quickly and is highly recommended.
Amazon Verified review Amazon
Amazon Customer Jan 20, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I enjoyed going through this introductory material.The material is well laid out, and will get you to a fully deployed ruby/sinatra app, backed by a MySQL database in no-time flat.This material is specifically aimed towards newcomers to the AppFog PaaS.
Amazon Verified review Amazon
W Boudville Jan 28, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
AppFog hits on a real and prevalent problem with many code developments that are directed towards some type of web use. Often, you have to somehow embed your code in a web server and also connect the code or the server to a choice of back end database. Three areas of expertise - front end web pages, web server and database. An alternative is proferred by this book from Nohr and Rabinovitch. We see that a big merit is the possible range of input languages. Ruby, Python, java, PHP and Node.js. Perhaps over time that list could even expand if AppFog takes off.The allure is the ease of deployment. The text gives quick examples in Ruby that collectively are the equivalent of Hello World. Granted, there might be a cost, as the providers of AppFog expect to get paid. But this cost is nominal if you decide from the book that the savings in your time are real.Hooking up your application to a database server seems simple enough in the text's example. There is one slight issue that seems to have been deprecated. It refers to how you set up a database server with a password for the administrator. This is done via a console application that looks for an environment variable. The provided GUI is a simple way to set this variable. But what if you get everything running and eventually days later the machine reboots? Here I'm assuming that you intend for your web server application to run continuously. When the machine starts up, it has to somehow get a value for that environment variable. It has been several years since I did unix/linux sysadmin, but if I recall correctly, ultimately that value must reside somewhere on disk. Perhaps in plaintext form. A potential security risk.However, in defence of the book, if the machine essentially runs only your app and is mostly single user, then you'll be fine. It might be that in a heavy multiuser mode there is a potential risk.
Amazon Verified review Amazon
Isaac Rabinovitch Apr 09, 2021
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Yes, I'm one of the authors. I'm moderately proud of this book, but the service it documents no longer exists.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.