📜 ⬆️ ⬇️

Web development with comfort: Parallels Desktop 10 + Vagrant

The world of web development is now changing, and this is also happening thanks to Vagrant, a virtual machine management tool that allows developers to save a lot of time and energy on supporting the desktop environment and synchronizing with colleagues.
Today we will talk about one of the features of the new Parallels Desktop 10, about which we received the most questions and feedback from user developers: integration with Vagrant. Frankly, this is also for Parallels Desktop developers themselves - one of the most favorite features.
If you still do not know why Vagrant is needed in web development, or use the VirtualBox virtual machine on a Mac as the basis for Vagrant, here you are :) Let's tell about the first full-featured Vagrant plugin developed by our team.




If you have ever tried to deploy an environment for web development on your work machine: a database, a favorite framework, nginx, redis, etc., then you are surely faced with the fact that your setup is very different from how your site works in production. The versions of packages used do not match, and some of them cannot be installed under your OS at all, and you have to look for a replacement.
')
One of the ways out is to raise the environment in virtual machines, but it does not work as well as we would like: you have to do everything manually, almost as if you were allocated a virtual server.

We in Parallels faced a similar problem about a year ago, when the internal development team began to expand, and it became clear that we need to establish active teamwork within the team and experiment more. And here everything is very simple: if you have a need to “touch” some technology, and you cannot afford to do it as quickly as possible, then you will never do it under the onslaught of daily tasks. And there is another specificity related to the fact that we have infrastructure supported both on Linux, and on Windows and Mac. I will not dwell on this. Anyone who is interested in our use case, can watch a video from the report about it .

The search for a solution led us to Vagrant . This is a unix-way utility with a command-line interface. The principle of operation is very simple: you have a text file that describes which virtual machine you want to have: the number of processor cores, memory size, disk size, OS distribution, etc. Based on this file, when you type the vagrant up command, a new virtual machine will be created, ready for use. You can go further and attach to this file a script that customizes the “virtual machine” for your needs: install MySQL, Django, nginx, etc. And all this will also be done automatically, at the time of setup. Once you understand that you are satisfied with the result, you can put these files in git and send them to a colleague. In this simple way, you have a standardized work environment.

Another convenient feature of Vagrant that we discovered for ourselves is the ability to “wrap” our working directory with the code inside the “virtual”. This removes the need for manual synchronization, and as soon as you save the file, it instantly appears in a virtual machine, and the changes can be immediately viewed in the browser.

It is worth mentioning here that at that time Vagrant worked only with VirtualBox, or, with the help of a premium plug-in from the original author, could connect with VMware. Since not only we for ourselves, but the market has already decided which virtualization solution on Mac should be considered the best, it was decided to make our own integration with Parallels Desktop. And now, after a year of development, we have released an open plugin for Vagrant, which is not inferior in quality to official integrations. The author of Vagrant, of course, wants to make money selling Integration with VMware, so for now there is no link to our free solution on the Vagrant home page. And since for some users, the presence of some integrations or plug-ins for Vagrant can also be news, and they close Parallels Desktop and run Virtualbox to work with it, we’ll describe a very simple procedure in this case :)

Usage example


Now a little practice. I’ll tell you how to get a working environment for Linux and Django on a Mac.

First you need Vagrant, which can be downloaded from the official website , Parallels Desktop 10 and the vagrant-parallels plugin, which can be installed as follows:

vagrant plugin install vagrant-parallels 

Now download the previously prepared repository:
 git clone https://github.com/Parallels/vagrant-django-example.git cd vagrant-django-example 

And we will start preparation of the virtual machine:
 vagrant up --provider=parallels 

In a few minutes, when the process is complete, you will have a fully ready to use virtual machine. Now all you have to do is jump inside through ssh and create a Django project:

 vagrant ssh # (  ) django-admin.py startproject vagrant_django . nohup python manage.py runserver [::]:8000 >&/dev/null & 

Everything, now it is possible to leave the virtual machine.

 exit 

If you now direct the browser to http: // localhost: 8000, you will see your site. And his code will be available in the current folder, from where you run vagrant up.

Environment Constructor


What we have done above implies that someone will write a Vagrantfile with instructions on how to set up the software. If you just want to experiment, then there is an excellent PuPHPet project that allows you to “dial” a virtual machine configuration by component, like in a supermarket. PuPHPet supports vagrant-parallels, so you are just a few clicks away from the configuration you need. At the exit, this system will offer you to download a small archive with all the necessary prepared files. You do not need anything other than the tools listed above.

What else can be done with Vagrant


In fact, the applicability of Vagrant is not limited to development environments. At home, for example, we use it to test the assembly of native components written in C ++ and Objective-C. Other examples of what you can do:



Why tenth?


In fact, those who have already tried vagrant-parallels have done it in versions of Parallels Desktop 8 and 9. Why am I talking about the 10th post? Before her, this project was free development on GitHub. In Parallels Desktop 10, support for Vagrant Parallels Provider is not only officially announced - we support almost all of its functions, in addition to the core ones. This includes using the shared folders tools, and fine-tuning the network, in general, all the things that ordinary shell scripts do not allow to do with the VM. Finally, the long-awaited function of port forwarding (port forwarding) via the 'prlctl' utility, rather than a graphical interface, appeared. It allows you to forward data from a specific port on a Mac to a virtual machine port via the TCP and UDP protocols. You can, for example, run a web server on a virtual machine, open local localhost: 8080 on a poppy and go to your test site. Theoretically, with great caution, you can even forward ports less than 1024 (since the process that is responsible for opening ports runs as root on a Mac).

And what about VirtualBox?


We have been written a lot about the fact that Parallels Desktop and VirtualBox cannot be run at the same time - something has already crashed. For the sake of fairness, two virtualization systems based on different technologies are difficult to get along with, although for many users this is not an argument. It got to the point that we specifically looked for people with such problems on Twitter and recommended them to use vagrant-parallels. Now we have solved this problem and both products can be launched together. If your Mac's resources allow it, simultaneous work will take place without the death of one of the fighters, without shutdowns and demands to immediately send a report to Parallels.

Conclusion


Obviously, you can start using Vagrant very easily and quickly. But, most importantly, it is a tool that very quickly and with high interest pays for the investment and resources invested. Therefore, if you have a choice in what to invest your time: in the study of a new framework, technology development, or tool, then I would certainly advise Vagrant.
Well, for developers who already use Parallels Desktop, getting started will be completely trivial.

If you have any questions, you want to share your Vagrant usage scenarios or success stories, welcome to comments.
Since our plugin for Vagrant is open, requests for features and bugs can be sent to us on GitHub: github.com/parallels .
You can also follow the releases and ask us questions via Twitter: twitter.com/legal_90 , twitter.com/racktear .
And now all our support is also quite well aware of Vagrant, and how developers use it. We are very happy to answer questions and help people solve problems. For you, this can also be a big plus.

Links


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


All Articles