Book Image

Implementing AppFog

Book Image

Implementing AppFog

Overview of this book

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.
Table of Contents (13 chapters)
Implementing AppFog
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Making changes to app.rb


First, let's go to app.rb and look at our list of required Gems:

require 'sinatra'

We're going to need two additional Gems, which are as follows:

  • json: We'll use it to convert the JSON text in VCAP_SERVICES into a data structure

  • mysql2: We'll use it to access the MySQL database

The expanded Gem requirements are as follows:

require 'sinatra'
require 'json'
require 'mysql2'

At the beginning of the application, we add new code that extracts MySQL credentials from the VCAP_SERVICES. This environment variable contains a JSON string that parses into a data structure similar to this example:

{
  "mysql-5.1"=>[
    {
      "name"=>"insideaf-mysql",
      "label"=>"mysql-5.1",
      "plan"=>"free",
      "tags"=>["mysql", "mysql-5.1", "relational", "mysql-5.1", "mysql"],
      "credentials"=>{
        "name"=>"d72374bco5g9u4s4f9e06e8e6014bdfdf",
        "hostname"=>"10.0.36.89", 
        "host"=>"10.0.36.89", 
        "port"=>3306, 
        "user"=&gt...