V2 Vagrant Box Setup
V2Master | V2Deployment | XenialBaseBoxSetup
Introduction
To allow to minimize the effort needed to create a new virtual machine for a V2 system we prepare from a standard Ubuntu Vagrant Box a customized box containing all necessary software.
Currently the following software packages are added: * rbenv * ruby (1.9.3-p484 and 2.2.2)
How to create a customized Ubuntu 16.04 LTS 64 bit Vagrant box for V2
Create a new virtual machine based on the Ubuntu 16.04 LTS (Xenial) base box
See XenialBaseBoxSetup how to create the base Xenial vagrant box, if not created yet.
This example is using the virtual machine name xenial-rails and assumed that the port 20500 is free on the host system and can be used for SSH. The private network setting can also vary depending of the host machine.
vagrant@zg-2:~/vms$ mkdir xenial-rails vagrant@zg-2:~/vms$ cd xenial-rails vagrant@zg-2:~/vms/xenial-rails$ vi Vagrantfile # This VM is for creating the Vagrant box xenial-rails from xenial-base, not for production. # DON'T LEAVE THIS VM RUNNING Vagrant.configure("2") do |config| config.vm.box = "xenial-base" config.vm.hostname = "xenial-rails.softxs.ch" config.vm.provider :virtualbox do |v| v.customize ["modifyvm", :id, "--name", "xenial-rails"] v.customize ["modifyvm", :id, "--memory", "8192"] end config.vm.network :private_network, ip: "172.16.1.100", netmask: "255.240.0.0" config.vm.network :forwarded_port, guest: 22, host: 20500 config.vm.synced_folder ".", "/vagrant", type: "nfs", nfs_udp: true, nfs_version: 4 end
Start the new VM set root password, create v2 user and update the packages database
vagrant@zg-2:~/vms/xenial-rails$ vagrant up vagrant@zg-2:~/vms/xenial-rails$ vagrant ssh vagrant@xenial-rails:~$ sudo su - # Make user v2 root@xenial-rails:~# adduser v2 # passwd tcom1959 root@xenial-rails:~# apt-get update
Installing rbenv, ruby and bundler
apt-get install git cd /usr/local git clone git://github.com/sstephenson/rbenv.git rbenv cd rbenv mkdir plugins cd plugins git clone git://github.com/sstephenson/ruby-build.git cd /usr/local chgrp -R v2 rbenv chmod -R g+rwxXs rbenv cat > /etc/profile.d/Z50-rbenv.sh export RBENV_ROOT=/usr/local/rbenv export PATH="$RBENV_ROOT/bin:$PATH" eval "$(rbenv init -)" ^D logout/login apt-get install -y libssl-dev libreadline-dev zlib1g-dev rbenv install 1.9.3-p484 rbenv install 2.2.2 apt-get install bundler cd /tmp cat > .ruby-version 1.9.3-p484 ^D gem install --no-ri --no-rdoc bundle cat > .ruby-version 2.2.2 ^D gem install --no-ri --no-rdoc bundle rm .ruby-version
Installig Apache 2 and Phusion Passenger 5
root@xenial-rails:~# apt-get install apache2 apache2-bin apache2-dev root@xenial-rails:~# touch /etc/apache2/httpd.conf # create an empty file if doesn't exists # Phusion Passanger 5 # see: https://www.phusionpassenger.com/library/install/apache/install/oss/trusty/ root@xenial-rails:~# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7 root@xenial-rails:~# apt-get install -y apt-transport-https ca-certificates root@xenial-rails:~# echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list root@xenial-rails:~# apt-get update root@xenial-rails:~# apt-get install -y libapache2-mod-passenger
Repackaging the VM into a new Vagrant box
vagrant@zg-2:~/vms/xenial-rails$ vagrant halt vagrant@zg-2:~/vms/xenial-rails$ vagrant package --output ~/boxes/xenial_rails.box vagrant@zg-2:~/vms/xenial-rails$ vagrant box add xenial_rails ~/boxes/xenial_rails.box