How to save and reuse a vagrant machine as vagrant box?

Are you using Vagrant for your application development locally?  Do you often encounter situations in which you are forced to destroy vagrant machine and create it again? Then this blog is for you.

It is often the situation that you will be using an operating system as base box from Vagrant Atlas and will be installing softwares, packages etc. on top of it. The base box will be specified in your Vagrantfile as value of property config.vm.box.  This base box and everything on top of it makes the vagrant machine. When you destroy a vagrant machine, all the stuffs installed on top of base box will be lost. It is possible to save the vagrant machine as a box and reuse it without having to install all the required package when you want to start over again.

Now lets see how to create a vagrant box from the vagrant machine. At first, stop your applications, if they are running inside your vagrant machine.

Here I assume that you are using Ubuntu as base box. If you use Docker like me, then you have to remove all Docker containers (PS: The following command will remove all Docker containers along with volumes. Make a backup of data in database based Docker containers if needed).

sudo docker rm -v $(sudo docker ps -aq)

Remove all dangling volumes using the following command

sudo docker volume rm $(docker volume ls -qf dangling=true)

Clear APT cache to prevent storing unnecessary data

sudo apt-get clean

Clear executed commands history and exit from the vagrant machine

cat /dev/null > ~/.bash_history && history -c && exit

Then, suspend the vagrant machine

vagrant suspend

Now we can create a new vagrant box from the vagrant machine using the following command

vagrant package –output my-app-vagrant.box

You can then destroy the vagrant machine

vagrant destroy

To use the newly created vagrant box, execute the following command

vagrant box add myAppBox my-app-vagrant.box

Then go to the Vagrant file. Comment out the line containing ‘config.vm.box’ property and add the following line below it

config.vm.box = “myAppBox”

After this when you start the vagrant machine using vagrant up command, you will be using the newly created box.

You will realize that this time it took only less time to start the vagrant machine 🙂 . The box needs to be created only once and then you can use it to start a fresh vagrant machine fastly over and over again.

Advertisements

Install and use different versions of Firefox in Ubuntu

You may want to use an old version of Firefox in your system because your automation tests are dependent on it. Use the following instructions to install any version of Firefox in your Ubuntu machine.

  • Go to https://ftp.mozilla.org/pub/firefox/releases/ and navigate through the links to the correct installer you want to use.
  • Get the URL of the installer by combining URL in address bar with the installer name. Suppose that you want to install Firefox 38.0.6, then the installer URL is ftp.mozilla.org/pub/firefox/releases/38.0.6/linux-x86_64/en-US/firefox-38.0.6.tar.bz2 .
  • Execute the following commands to download and install a chosen Firefox version(e.g. 38.0.6).
wget ftp.mozilla.org/pub/firefox/releases/38.0.6/linux-x86_64/en-US/firefox-38.0.6.tar.bz2
tar -xjvf firefox-38.0.6.tar.bz2
sudo mv firefox /opt/firefox38.0.6
sudo ln -sf /opt/firefox38.0.6/firefox /usr/bin/firefox

You can verify whether Firefox is installed properly using the command:

firefox --version

You can maintain different versions of Firefox using the instructions given above. Then just create a symbolic link to the specific version you want to use.

3 ways to have Nodejs in Docker

    • Use official Nodejs image

FROM node:0.10.38

    • Use chrislea’s PPA

FROM ubuntu:14.04
RUN apt-get install -y software-properties-common
RUN apt-add-repository ppa:chris-lea/node.js
RUN apt-get update
RUN apt-get install -y nodejs

    • Use curl

FROM ubuntu:14.04
RUN apt-get install -y curl software-properties-common
RUN mkdir /nodejs && curl http://nodejs.org/dist/v0.10.38/node-v0.10.38-linux-x64.tar.gz | tar xvzf – -C /nodejs –strip-components=1
ENV PATH $PATH:/nodejs/bin

How to set WiFi password in BSNL Broadband UTStarcom router?

  1. Open a browser, type http://192.168.1.1 in address bar and hit enter.
  2. A popup will show. Enter Username/Password as admin/admin
  3. Now you will be in Router Configuration page.
  4. In the left side menu, click on ‘Wireless’. In the sub-menu click on ‘Security’.
  5. Provide the following values:-
    • Network Authentication: Open
    • WEP Encryption: Enabled
    • Encryption Strength: 64bit
    • Current Network Key: 1
    • Network Key 1: <Enter ur WiFi password here. Five digit number will be sufficient>
  6. Click on Save/Apply. Close the browser. Now your BSNL Wireless Router is password protected.

BSNL BB conf