Thread: Vagrant for local development testing

Results 1 to 1 of 1
  1. #1 Vagrant for local development testing 
    Vitality

    Raw Envy's Avatar
    Join Date
    Dec 2010
    Posts
    3,034
    Thanks given
    869
    Thanks received
    1,186
    Rep Power
    3054
    Attached image
    What is Vagrant?

    Vagrant is an open-source software that allows you to provision and configure virtual machines and virtual environments, it is created using the Ruby programming language. Vagrant sits on top of the hypervisor that you are using to create your virtual machine, e.g: VirtualBox, Hyper-V, VMware and you can even use a Docker container with Vagrant. It allows you to quickly create development environments from an existing image, you can then configure how you want the environment setup by provisioning it. You can use various configuration management/provisioning tools with Vagrant such as Ansible, Chef and Puppet to provision your VMs with ease, or simply use a bash script.

    You can find various pre-built boxes here: https://app.vagrantup.com/boxes/search

    Code:
    To create a standard Ubuntu environment, do the following:
    1. Install VirtualBox
    2. Install Vagrant
    3. Create a local directory for Vagrant
    4. Create a Vagrantfile in that directory, by doing vagrant init 
    5. Go to the public Vagrant box catalogue and find a box that you want to use. Such as the ubuntu/trusty64 box which should give you the latest up to date Ubuntu image.
    6. Edit your Vagrantfile to include the name of the box you want to Vagrant up, e.g.: config.vm.box = "ubuntu/trusty64",
    7. Do vagrant up and it will spin up the VM
    8. Do vagrant ssh to connect to the virtual environment that you have created

    Quicker way once you're more comfortable with how Vagrant works:

    Code:
    mkdir ubuntu-vm
    cd ubuntu-vm
    vagrant init ubuntu/trusty64 # Create the Vagrantfile and specify the image to use
    vagrant up && vagrant ssh # Start up the VM and connect to it via SSH

    Vagrant can also sync folders from the host machine to the guest machine and vice versa. This allows you to work on files locally on your machine, so you can use your favourite IDE for example and then you compile and run the application on your guest machine in the dev environment.
    By default the shared folder on the guest machine will be /vagrant. You can specify how you want to setup your synced folders using something from the config namespace: config.vm, an example would be: config.vm.synced_folder "/web-server", "/etc/apache2"


    Vagrant allows you to provision the VM when you first run it, this allows you to setup the software on the VM how you want it. E.g.: you could provision the VM to have all the dependencies to run an Apache web server on, which could all be provisioned with a single shell script.
    To provision the VM with a shell script you can use the following in your Vagrantfile: config.vm.provision = "shell", path: "script.sh"


    If you want to create a private network which will allow host-only access to the machine with a specific IP then you can simply add the below to your Vagrantfile.

    Code:
    config.vm.network "private_network", ip: "192.168.33.10"
    If you then wanted to copy a file from the VM to your host you could simply do the following command using scp, this is just an example: scp [email protected]:~/file/in/home_directory /local/directory/to_put_file


    If you want a GUI with the operating system you are spinning up then make sure you are using a vagrant box that has a GUI included with it, e.g.: igorbites/ubuntu-trusty64-gui and add the below in your Vagrantfile:

    Code:
    config.vm.provider "virtualbox" do |v|
    v.gui = "true"
    end

    The below diagram gives you a visual example of where Vagrant sits in the whole Virtualisation process. And one last thing, if you want to share your development environments with your friends then you can simply send them your Vagrantfile.

    Attached image
    Reply With Quote  
     

  2. Thankful user:



Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 8
    Last Post: 11-13-2017, 10:25 PM
  2. Looking for a developer/coder.
    By iJay in forum Requests
    Replies: 2
    Last Post: 08-01-2009, 03:31 PM
  3. Useful Things for Client Developers
    By Clienthax in forum RS2 Client
    Replies: 25
    Last Post: 03-13-2009, 12:40 AM
  4. Domain Name for my Development Site!
    By Evan in forum Chat
    Replies: 11
    Last Post: 05-12-2008, 02:25 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •