This was presented at DevIntersection 2014. In this session we covered tips and tricks for getting the most out of Ruby in the cloud using several tools provided by Microsoft and Azure, including the Ruby SDK and developer center. Topics included best practices for security, performance, and reliability when accessing structured, unstructured, and NoSQL data.
1. Ruby on Windows Azure
Brian Benz
Senior Technical Evangelist
Microsoft Open Technologies, Inc.
2. 2 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
• The Ruby SDK for Windows Azure
• Engine Yard
• DevOps - Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
3. 3 http://www.anglebrackets.org
Ruby, Rails, Ruby Gems
Ruby: 1990s
Object Oriented Scripting
Ruby on Rails – 2004, 2005
Framework for Ruby
Ruby Gems – 2007
Easy Installation and package management
Node npm, Python EasyInstall
Grails – Groovy (Java based) on Rails
Inspired by Ruby on Rails, but not Ruby
4. 4 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
9. 9 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
11. 11 http://www.anglebrackets.org
Azure Installation using Ruby Gem
C:rubyrubygems-2.2.2>gem install azure
Fetching: json-1.8.1.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed json-1.8.1
Fetching: systemu-2.6.4.gem (100%)
Successfully installed systemu-2.6.4
Fetching: macaddr-1.7.1.gem (100%)
Successfully installed macaddr-1.7.1
Fetching: uuid-2.3.7.gem (100%)
Successfully installed uuid-2.3.7
Fetching: azure-0.6.3.gem (100%)
Successfully installed azure-0.6.3
12. 12 http://www.anglebrackets.org
Azure Installation - documentation
Installing ri documentation for azure-0.6.3
Installing ri documentation for json-1.8.1
Installing ri documentation for macaddr-1.7.1
Installing ri documentation for systemu-2.6.4
Installing ri documentation for uuid-2.3.7
5 gems installed
C:rubyrubygems-2.2.2>
15. azure topic verb options
Command Line Syntax Overview
prompt>
account
account location
account affinity-group
vm
vm disk
vm endpoint
vm image
service
service cert
site
config
download
import
list
show
delete
start
restart
shutdown
capture
create
attach
detach
browse
set
username
password
dns-prefix
vm-name
lb-port
target-image-name
source-path
disk-image-name
size-in-gb
thumbprint
value
-v
-vv
17. 17 http://www.anglebrackets.org
github.com/windowsazure/azure-sdk-for-ruby
Storage
Blobs
create, list, and delete containers, work with container metadata and
permissions, list blobs in container
create block and page blobs (from a stream, a file, or a string), work with
blob blocks and pages, delete blobs
work with blob properties, metadata, leases, snapshot a blob
Tables
create and delete tables
create, query, insert, update, merge, and delete entities
Queues
create, list, and delete queues, and work with queue metadata
create, get, peek, update, delete messages
19. 19 http://www.anglebrackets.org
Queue Storage
Stores large numbers of messages
Authenticated via HTTP or HTTPs
Up to 200TB
Tutorial: http://www.windowsazure.com/en-us/develop/ruby/how-
to-guides/queue-service/
21. 21 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
23. 23 http://www.anglebrackets.org
• Engine Yard – What’s in the Box:
Ubuntu-based
Two Ruby application servers
One MySQL Server
Two load balancing servers
New AngularJS UI
Monthly Fee – currently $99 or $149 for premium support
Currently a $1 Trial for the first month
25. 25 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
26. 26 http://www.anglebrackets.org
Chef on Windows Azure
Chef Community - community.opscode.com
15,000+ registered users
800 individual contributors
150 corporate contributors
500+ cookbooks
Support for on-Premise Windows and Windows Azure in the
Cloud
27. 27 http://www.anglebrackets.org
Chef on Windows Azure - Architecture
• Chef Server – Authentication
and Cookbooks
• Windows Azure –
endorsed Linux packages
• New VM – loads
workstation
• New workstation – loads
client and recipes
29. 29 http://www.anglebrackets.org
Example Knife Command
Create Jenkins running on Ubuntu on an Azure VM
knife azure server create
Creates a new Azure Server
--hosted-service-name JenkinsDemo1
Names the Server
--role-name DemoServer
Names the Role
--run-list 'recipe[java],recipe[jenkins]‘
Retrieves a run-list, recipes, runs on Chef Client
30. 30 http://www.anglebrackets.org
Puppet on Windows Azure
The power of Puppet = Community!
Demand for better windows integration and management
>1850 modules in the Forge alone
Strong Third Party Ecosystem
Vagrant
Test locally before you pay for cloud resources
Puphpet – from workstation to cloud
UI that helps generate a Vagrant file and Puppet manifests
33. 33 http://www.anglebrackets.org
Puppet on Windows Azure
The Windows Azure Puppet module
Virtual Machines – both Linux and Windows
Virtual Networks – create logically isolated sections of Azure and
securely connect them to your on premise clients and servers
SQL Server – create and maintain your SQL database
34. 34 http://www.anglebrackets.org
Puppet on Windows Azure
Manifest files
Collections of definitions, references and commands
Deploy VMs in a defined “desired state”.
bootstrap.pp – allows the creation of a new Puppet node
db.pp – create a new instance of SQL server
init.pp – defines a Windows Azure class that will allow easy deployment to
the associated Windows Azure account
vm.pp – create a new virtual machine instance from a virtual machine
image
vnet.pp – create a new virtual network
35. 35 http://www.anglebrackets.org
Example Modules
Modules are just directories with files, arranged in a specific,
predictable structure
Ala run list in Chef
site.pp
include ntp
include apache
include mysql
include mongodb
include build_essential
36. 36 http://www.anglebrackets.org
Agenda
• Ruby on Windows Azure
The Ruby SDK for Windows Azure
• Engine Yard
• DevOps – Chef and Puppet
• Ruby Support in Microsoft Open Source Tools
37. 37 http://www.anglebrackets.org
Ruby in Microsoft Open Source Tools
• Reactive Extensions – Ruby Library
Asynchronous and event-based programming using:
Observable sequences
LINQ-style query operators
http://rxrb.codeplex.com/
Apache Qpid Proton AMQP libraries
Cross-platform AMQP messaging system
Message brokers written in C++ and Java
Clients for Ruby, also C++, Java, Perl, Python, Ruby, and .NET.
http://qpid.apache.org/releases/
40. 40 http://www.anglebrackets.org
Windows Azure Storage
Storage in the Cloud
Scalable, durable, and available
Anywhere at anytime access
Only pay for what the service uses
RESTful Web Services
Use from Windows Azure Compute
Use from anywhere on the internet
44. 44 http://www.anglebrackets.org
Setting up Storage
• Configure Your Application to Access Storage
• Download and use the Ruby azure package, which communicates with the storage REST
services.
• Use RubyGems to obtain the package
• Use a command-line interface such as PowerShell (Windows), Terminal (Mac), or
Bash (Unix).
• Type "gem install azure" in the command window to install the gem and
dependencies.
• Import the package
• Using your favorite text editor, add the following to the top of the Ruby file where
you intend to use storage:
• require "azure"
45. 45 http://www.anglebrackets.org
Storage Connection
• Setup a Windows Azure Storage Connection
• The azure module will read the environment variables
AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY for information
required to connect to your Windows Azure storage account.
• If these environment variables are not set, you must specify the account
information before using Azure Storage Services with the following code:
Azure.config.storage_account_name = "<your azure storage
account>"
Azure.config.storage_access_key = "<your azure storage access key>"
46. 46 http://www.anglebrackets.org
Getting Storage Credentials
• To obtain the Account Name and Access Key values:
• Log into the Windows Azure Management Portal.
• Navigate to the storage account you want to use
• Click MANAGE KEYS at the bottom of the navigation pane.
• In the pop up dialog, you will see the storage account name, primary access key
and secondary access key. For access key, you can either the primary one or the
secondary one.
49. 49 http://www.anglebrackets.org
Create a Container
azure_blob_service = Azure::BlobService.new
begin
container =
azure_blob_service.create_container("test- container")
#Optional – Set Container to public read acess
azure_blob_service.set_container_acl('test-
container', "container")
rescue
puts $!
End
50. 50 http://www.anglebrackets.org
Upload a Blob to a Container
content = File.open("test.png", "rb") { |file|
file.read }
blob =
azure_blob_service.create_block_blob(container.name,
"image-blob", content)
puts blob.name
51. 51 http://www.anglebrackets.org
List the Blobs in a Container
containers =
azure_blob_service.list_containers()
containers.each do |container|
blobs =
azure_blob_service.list_blobs(container.name
)
blobs.each do |blob|
puts blob.name
end
end
52. 52 http://www.anglebrackets.org
Download or Delete a Blob
#Download
blob, content =
azure_blob_service.get_blob(container.name,"
image-blob")
File.open("download.png","wb") {|f|
f.write(content)}
#Delete
azure_blob_service.delete_blob(container.nam
e, "image-blob")