Three ways to set up a Ruby stack on Azure
Microsoft’s announcement of the Windows Azure SDK for Ruby opens up new alternatives and resources for Ruby developers to publish their apps in the cloud. This first version of the SDK (GitHub) supports working with Azure storage & Azure service bus, and deployment in a Linux VM on Azure IaaS.
The 3 options covered below are different ways to set up an Ubuntu Linux stack with Ruby 1.9.3. – running in a Windows Azure VM – on my MacBook Pro:
- An “official” PLATFORM IMAGE with Ruby Version Manager (RVM) via Azure Portal
- A VMDepot Ruby Stack from BitNami via Azure Portal
- A VMDepot Ruby Stack from BitNami via azure-cli command line (OSX)
The major difference in these approaches is the use of the “official” platform image is the supported Ubuntu Server 13.04 image where we’ll install pre-requisite packaged & RVM to end up with Ruby 1.9.3. vs an already pre-configured stack from BitNami available via VMDepot from the Microsoft OpenTech.
1. Ubuntu 13.04 + RVM via Azure Portal
In the Azure portal go to Virtual Machines. Pick NEW –> Virtual Machine –> From Gallery:
In the List of OS, pick the Ubuntu Server 13.04
As of last week, VM options include using key-based authentication for SSH, which I’ll choose for this install.
Open up terminal and go into the directory where you’d like to store your key & certificate. Then, to create the certificate/key combo:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout myPrivateKey.key -out myCert.pem
The other options include size of the vm, user name to be set up & the VM machine name. Click Next:
Here we’re providing the DNS name & choosing the region/affinity group where we’d like the VM to be located. For performance reasons it’s wise to keep the region consistent across your Azure VMs, services, etc. supporting your solution.
Shortly you should end up with a VM (in my case, named: “ubuntu13ruby”) that will get provisioned and started with the settings you specified. The only critical thing to note is the SSH port (under your VM –> Edndpoints). You’ll need this for your SSH session.
Back in my MacBook Terminal I’m going to connect to the VM & run a few updates and install git-core & curl:
sudo apt-get -y update sudo apt-get -y upgrade sudo apt-get -y git-core curl
Next I’m choosing to install Ruby Version Manager (RVM) which provides many useful capabilities including sand-boxing multiple versions of Ruby and simplifying the install.
Run RVM installer (note the leading backslash)
\curl -L https://get.rvm.io | bash -s stable
Make RVM accessible from bash:
echo 'source ~/.rvm/scripts/rvm' >> ~/.bash_aliases && bash
Next we’ll use rvm to check any missing dependencies/packages:
Output should contain information similar to this:
Missing required packages: gcc, make, libc6-dev, libreadline6-dev, zlib1g-dev, libssl-dev, libyaml-dev, libsqlite3-dev, sqlite3, libxml2-dev, libxslt1-dev, autoconf, libc6-dev, libgdbm-dev, libncurses5-dev, automake, libtool, bison, pkg-config, libffi-dev.
Use the output from rvm requirements to sudo install missing bits. In my case it’s:
sudo apt-get install gcc make libc6-dev libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf libc6-dev libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev –y
For sanity check, run rvm requirements again, to ensure nothing else is missing.
Next let’s install Ruby 1.9.3:
rvm install 1.9.3
You should get output similar to below:
Installing Ruby from source to: /home/azureuser/.rvm/rubies/ruby-1.9.3-p392, this may take a while depending on your cpu(s)... .... Install of ruby-1.9.3-p392 - #complete
Set Ruby 1.9.3 to default:
rvm use 1.9.3 --default
Finally, let’s make sure ruby 1.9.3 is installed correctly with : ruby –v
On the VM installed, I get indication that we’re all set: ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]
2. BitNami Ubuntu Ruby stack using VMDepot via Azure Portal
VMDepot from the Microsoft OpenTech provides an amazing collection of various stacks for various apps & purposes to get a VM going very quickly on Azure
From the Azure Portal, choose Virtual Machines –> Images:
Click “Browse VM Depot” and filter to Ubuntu images on the left hand side:
I’m picking the Ruby Stack 1.9.3-9 from BitNami to be installed, and then specify a storage account where my BitNami image will be copied (and stored) before I can create a VM from it:
Because the image is quite large (30 gb) the copy process may take some time; after it completes I can see it under Virtual Machines –> Images. I need to Register it (bottom right of the options bar):
Finally, I go to NEW –> Virtual Machine –> From Gallery –> MY IMAGES, where I should see my image:
At this point I can create the VM from the BitNami image, click Next & follow options similar to step 1 above.
3. BitNami Ubuntu Ruby stack using VMDepot via command line
An alternative to the Azure portal is using azure-cli command line tools which greatly simplify (and automate) Azure related tasks on any platform.
I’m starting with VM Depot website search for Ruby stack:
Once I find the stack I want (in my case Ruby Stack 1.9.3-9 on Ubuntu), I click “Deployment Script” and get the commands I need for azure-cli on my client machine:
On my MacBook, I need to have azure-cli installed (and my .profile imported), after which I can create the VM & enable the endpoints for HTTP/HTTPS (SSH is enabled on default port with the –ssh option) :
azure vm create bitnamiub13ruby -o vmdepot-323-1-1 -l "West US" azureuser <MyPassword> –ssh azure vm endpoint create-multiple bitnamiub13ruby 80:80,443:443
At this point I should be able to SSH to my newly created Ruby-ready at bitnamiub13ruby.cloudapp.net with the user: azureuser & password specified. For sanity check I can see my VMs by using:
azure vm list
Using either one of these 3 approaches I should have a Ruby stack on a Ubuntu VM running in Windows Azure, ready for development!
In a follow-on to this post I’m teaming up with Marc Gagné to explore Azure SDK for Ruby in a sample app running in one of my VMs.
- Hosting ASP.NET Core RC2 in an Azure Web App 24 views
- Azure Application Insights in Power BI dashboard 13 views
- Azure Application Insights Analytic or Kusto 11 views
- Setting up Ubuntu Linux VM on Windows Azure for Node.js using essential Node & Azure tools on Mac OS X 11 views
- Create a Power BI dashboard using Azure Application Insights Analytics data 9 views