Insights
Experiences with using Vagrant for ERPNext deployment
Author : Muralitharan
The Problem :
The infra team at Promantia always gets urgent requests for new dev/demo/test instances for different software ( Openbravo, ERPNext, Prestashop, Alfresco, Confluence etc ) on different environments ( physical server, virtual server or AWS ). Initially we used AWS and VirtualBox Images to build off , but as many of these open source products have frequent releases, these images get out-dated soon , so we wanted to move to a scripting solution.
The Solution – Vagrant
I looked at different options for building virtual machines and finally settled on Vagrant . Vagrant can be installed on Linux, Windows, and Mac OS X, and although it uses Ruby, the package includes an embedded Ruby interpreter.The Oracle VirtualBox provider is available for free and is the default provider for Vagrant.
Checking out Vagrant .
- Vagrant can be downloaded from https://www.vagrantup.com/downloads.html you can download the proper package for your operating system and architecture.
- An instance can be brought up in a minute with 3-4 commands after installing vagrant
- Create a new directory and change to that directory
- Create a ubuntu virtual machine using the command
vagrant init ubuntu/bionic64 - Start the instance
vagrant up - And finally get onto the instance
vagrant ssh
And your simple instance is up and you are on to it.
Configuring the instance using Vagrantfile
Of course there is more variance that you can configure using the config file (Vagrantfile ) . For instance you can change Network option , RAM size ,etc. Once completed customization run vagrant reload command to apply the changes
Another interesting feature is provisioning. Provisioning can be done with shell script, Ansible, Chef , Salt etc. I choose to go with a shell script. To do this , uncomment lines related to config.vm.provision in the Vagrantfile and provide the details of the post installation provisioning between the two “SHELL” in the text below .
config.vm.provision “shell”, inline: <<-SHELL
SHELL
Of course if the script is complex then we can call a shell script from within – and that is what we did for setting up ERPNext instance .
Installing ERPNext
We created a few scripts and a configuration file for installing ERPNext using vagrant and invoked it from the vagrantfile as part of provisioning . With that all the prerequisites for ERPNext as well as it’s deployment tool ( bench ) , base framework ( frappe ) and ERPnext itself would be installed when vagrant provision is called for the current instance or when vagrant init is called with the Vagrantfile .
Use the provision command to start the server to provisioning with script
vagrant provision
After completing provision login to vagrant machine using vagrant ssh to connect server
.
At the end we had a language translated page which looked like this
ErpNext Login page finally accessing local network using ip address .
You can access the scripts and the Vagrantfile from the github repository – https://github.com/promantia-ltd/erpnext-vagrant-config.git