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
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781849698184
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 128.97
Mastering Node.js
$54.99
Implementing AppFog
$32.99
iCloud Standard Guide
$40.99
Total $ 128.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.