📜 ⬆️ ⬇️

The story of Ruby on Windows Azure

Ruby developers could use Windows Azure from the earliest stage of platform development, and every year Ruby platform support increased both through the creation and development of Ruby development tools for Windows Azure, and indirectly — for example, with the release of virtual machines, the possibility of developing Ruby applications in IaaS-environment. For those who do not want to perplex themselves with infrastructural realities, there is already a pre-configured Ruby image in the VMDepot virtual machine storage. Below I will talk about several ways to develop Ruby in Windows Azure, which of these methods will be more convenient - you decide.

Having studied the milestones of the development of the platform in the direction of development for Ruby, there are several stages, each of which is important in its own way:

• Creating a Windows Azure SDK for Ruby ( Windows Azure SDK Ruby ), with which you can use various Windows Azure services from a Ruby application. This is a very important milestone, since without the efforts that the platform vendor itself invests in a specific direction, it will not be possible to say that this direction is a full-fledged “inhabitant” of the ecosystem. Like many other Microsoft tools, the Ruby SDK is Open Source and is located on GitHub - github.com/WindowsAzure/azure-sdk-for-ruby
• Publication of IaaS in the form of virtual machines. With this, everything is clear - you can make a virtual server for yourself.
• Exit to VMDepot image storage . For those who want to get a ready-made image and start working immediately.

Method 1: Windows Azure Linux Server, Ubuntu 12.04 LTS


Manually deploy a Linux server and set up a working environment for you. To do this, go to the Windows Azure Management Portal and click New => COMPUTE => VIRTUAL MACHINE => QUICK CREATE.
')
Enter the data:

• DNS NAME: the name under which the virtual machine will be accessible from the outside
• IMAGE: the image from which the virtual machine will be deployed. Choose Ubuntu Server 12.04 LTS.
• SIZE: one of the available VM sizes. Choose Medium.
• USER NAME: the default is azureuser. Cannot be changed on the portal.
• NEW PASSWORD / CONFIRM: password.
• REGION / AFFINITY GROUP: region in which the VM will be located, or affine group (to ensure maximum proximity within the data center).

For more precise settings, choose FROM GALLERY - more settings will be available.



Connection data (for example, by Putty) is obtained after clicking on the VM name in the SSH Details section of the Dashboard tab.



Run the sudo apt-get update command. Do not forget to use sudo on VM under Linux, this is additional security and confidence. Further it is desirable to install for convenience window manager:

sudo apt-get install ubuntu-desktop 


Enable RDP access to the GUI. This is done on the Endpoints tab: you need to click Add and enter data - an access point using the TCP protocol and a port value of 3389.
In the VM, install xrdp:

 sudo apt-get install xrdp 


Now you can set the environment for Ruby on Rails:

 sudo apt-get upgrade sudo apt-get install ruby1.9.1 ruby1.9.l-dev build-essential libsqlite3-dev nodejs -y sudo gem install bundler –no-rdoc –no-ri sudo apt-get -y install git-core curl curl -L https://get.rvm.io | bash -s stable 


We will also install Ruby Version Manager (RVM), which is useful for managing different versions of Ruby and other features. Add RVM to the environment:

 echo 'source ~/.rvm/scripts/rvm' >> ~/.bash_aliases && bash 


And check if everything is set to work correctly:

 rvm requirements 

If everything is in order, you can install Ruby and specify it to use the default:

 rvm install 1.9.3 rvm use 1.9.3 –default 


Method 2: Install VM from VMDepot


From VMDepot, you can install pre-configured community VM images, and they will be automatically deployed and run on Windows Azure in your account.
Let's go straight to the page of the desired image.
Click DEPLOYMENT SCRIPT to get the deployment script. The script is designed for the Azure CLI, and if you do not have the CLI installed, you will not be able to use it (you can download it from the link ).
Run CLI. Next, run the following commands to configure the environment for the CLI:

 azure account download (     ) azure account import [____] azure storage account list (    ,   ,  ) azure storage account set [__] 


After all commands have been executed, the script copied from VMDepot can be executed. This will take some time, after which the new VM will appear in the VM list on the Windows Azure management portal. This VM is an excellent set of various development environments and environments, including PHP, Ruby, Python, Java and various frameworks, as well as such DBMS as mysql, postgresql, and apache / nginx.

Method 3: PaaS, Ruby + Sinatra + Azure



As PaaS on Windows Azure, the concept of Cloud Service is used - an application consisting of several traditional projects (frontend and backend, for example) and one new one - the Cloud Service itself, which contains all the configuration used by the platform to deploy and configure the application in the cloud. You can read more here .

Create a Cloud Service project in Visual Studio and add Worker Role to it. In this role project, the installation of the Ruby environment and application will occur. Now you need to download the Ruby installer - we will put it in Worker Role, on which VM the environment will then be deployed. The installer can be downloaded from RubyInstaller.com. Add the installer to the Worker Role project and set the Copy to output directory attribute to Copy if newer so that it is included in the package. Add the file install.cmd with the same value of the Copy to output directory attribute and the following content:

 rubyinstaller-2.0.0-p0-x64.exe /silent D:\Ruby200-x64\bin\gem.bat install sinatra --no-ri --no-rdoc 


All files must be saved with US-ASCII encoding, otherwise errors may occur.
Add the main.rb file to Worker Role with the value of the copy if newer attribute and content:

 require 'sinatra' set :environment, :production set :port, 8080 get '/' do "Hello World!" end 

Add a start.cmd file with the same attribute value and the following content:

 D:\Ruby200-x64\bin\ruby.exe main.rb 

However, everything will not automatically start, so you need to make adjustments to the configuration of the role itself in the project Cloud Service. Open the ServiceDefinition.csdef file and add the code highlighted below:

 <?xml version="1.0" encoding="utf-8"?> <ServiceDefinition name="RubyTest" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2013-10.2.2"> <WorkerRole name="WorkerRole1" vmsize="Small"> <Startup> <Task commandLine="install.cmd" executionContext="elevated" taskType="simple"></Task> <Task commandLine="start.cmd" executionContext="elevated" taskType="background"></Task> </Startup> <Imports> <Import moduleName="Diagnostics" /> </Imports> <Endpoints> <InputEndpoint name="Endpoint1" protocol="tcp" port="80" localPort="8080" /> </Endpoints> </WorkerRole> </ServiceDefinition> 


Thus, we set up the configuration so that when the VM starts, the install.cmd and start.cmd files will be launched with elevated privileges, and port 80 (for external clients) will be opened, which will redirect traffic to the internal port 8080.
Now, if you have a Windows Azure emulator installed, you can press F5 (during startup, pay attention to the startup files — these are install.cmd and start.cmd) and watch the result at localhost : 81 (the local emulator automatically remaps from 80 port 81 to avoid conflicts).

The process of further development can be divided into several stages:
1) Creation of software code and .rb files
2) Perform modification of the install.cmd and start.cmd files, or develop new executable files, to automate changes or create a completely new development environment and edit the corresponding section in ServiceDefinitions.csdef
3) Entering the commands for managing the program code in start.cmd

In this article, I briefly reviewed the deployment of the simplest Ruby development ecosystem. Then the choice is yours - to develop locally or have a constantly accessible development environment with which you can do anything, and which you can go from anywhere - according to the latest data, this is becoming more and more important. :)

UPD: and even in the comments suggest that there is an addon for automation. We take and use. :)

Source: https://habr.com/ru/post/214763/


All Articles