⬆️ ⬇️

Rapidly Deploy Development Environment for Ruby on Rails

Hello habrazhiteli. If you are tired of constantly installing on new machines with different OS the same rails environment with dozens of dependencies and a bunch of packages, then I suggest you get acquainted with an interesting solution from rails-core developers. On your host machine, you only need to have Vagrant and Virtual Box.



Problem


It so happened that in our company there was a problem of installing all the necessary environment on different operating systems, Mac OS X and Linux in particular.

It would seem that this is a trivial task under Linux, a bit more difficult under Mac, but everything turned out to be even more difficult, since our project is not standard. A hell of a hell of a mixture of ragdolls and rattles. The project is just in the process of migrating to the rails. And making friends with it all under poppies was not such a simple task for front-end programmers who are not experienced in setting up the environment. They categorically refused to install Ubuntu or another Linux.



Decision




imageimage

Well. As the fastest solution was chosen such a wonderful project as rails-dev-box

This project automates the installation for developing a Ruby on Rails kernel. For our needs, this fits perfectly.

We need to have Virtual Box installed and Vagrant Ruby Jam. Both are easy to install.

After that we just need to execute a couple of commands:

')

host:~$ git clone https://github.com/rails/rails-dev-box.git host:~$ cd rails-dev-box host:~$ vagrant up 


Everything. After that, you can log in via ssh to the already configured ubuntu:



 vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686) ... vagrant@rails-dev-box:~$ 


The virtual system has already installed everything you need, except for php and the web server:



Installing php and nginx, we will not consider, it is beyond the scope of this article. This is very easy to do in Linux.



We just need to copy the project to the folder with the rails-dev-box on the host system and run the rails server from under vagrant:



 vagrant ssh cd /vagrant/my_project bundle exec unicorn -E development -D 


The virtual system and host systems see the same folder, which allows us to edit it with our favorite editor, and open the pages as before through localhost:3000

In the case of php, we need to also port 1080 (we can’t port 80, because then we will need root access)

This is done quite simply. It is necessary to enter only one line in Vagrantfile:



 config.vm.forward_port 80, 1080 


What was my surprise when it turned out that the pages from Rails are loaded almost by the minute. Drupal worked as if nothing had happened. The speed is almost indistinguishable from the native file system.

It turned out that VirtualBox Shared Folders, which Vagrant uses by default, are very, very slow.

Benchmark from Vagrant documentation:



 VirtualBox Shared Folders: 5m 14s Host File System: 10s Native VM File System: 13s NFS Shared Folders: 22s NFS Shared Folders (warm cache): 14s 


As you can see, we have nothing left but to use NFS. On Mac OS, this daemon is already preinstalled. Installing in Linux again is banal - you need to install the package.

After that, edit our Vagrantfile, add the lines:



 config.vm.share_folder "v-root", "/home/vagrant/shared-folder", ".", :nfs => true config.vm.network :hostonly, "33.33.33.100" 


The Host-only option is used to create the second virtual adapter, and nfs will work through it.

Now you need to restart the virtual machine and the project in the virtual system will already be located in /home/vagrant/shared-folder



We launch unicorn and now we see that the pages load at the proper speed.



Additionally


A bunch of Virtual Box and Vagrant works great. You can write additional recipes (used by puppet) to automate all of the above, including cloning your project's repository from a third-party service, as well as setting up nginx / apache, php, unicorn configs



Thank you for your attention and pleasant development.



Links


rails-dev-box github source code

Vagrant and NFS Shared Folders

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



All Articles