Wednesday, August 14, 2013

Creating a Vagrant box from Oracle 11.2g Virtualbox Appliance

I'm having a hell of a time trying to get a box up and running with v3 of ArsDigita Community System, the version described in the book Philip and Alex's Guide to Web Publishing.

My current plan is to create a Vagrant box with Oracle 11.2g and use Ansible to automate as much of the setup as possible.

Here are the best source code links I have found so far:

I've looked at OpenACS a bunch. I really wanted to use it as it would save me a ton of time, but I'm not a big fan. Their web site is hard to navigate, not all the ACS 3.0 modules were converted, and the focus of 4.0 seems to have shifted to bug tracking and CMS, which seems like a poor decision in retrospect. The quality of the ArsDigita documentation is so much better, and I expect the code, UX and data schemas will also be superior. So I'm going to try this route.

This blog entry documents step 1: creating the vagrant box from the Oracle Virtualbox appliance.

Create Oracle Virtualbox Instance

From a brief look at the Oracle store, it looks I could get a one-CPU perpetual license for Oracle for somewhere around $150. (In the ArsDigita Oracle install documentation, they say that Oracle would cost $40, and that is circa 2000. That's a 11% annual rate of increase, not bad!) In any case, Oracle is free for development uses.

  1. Apply for an OTN account.  You have to give Oracle your info (name, email, phone #, etc) to get an account.  Click the appliance download link and you'll get the login and register screen.
  2. Make sure you have a download manager, in case the download fails.  It's a 4 gig download.  (I used Download Them All.)
  3. Download the appliance: http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html
  4. Spin up Virtualbox, and pick "File -> Import Appliance", pick the Oracle_Developer_Day.ova file.  After a couple minutes, you have a new Virtualbox running Oracle Linux with 11.2g.

Vagrant setup

Add a vagrant user,

[oracle@localhost ~]$ su - root
Password: oracle
[root@localhost ~]# adduser vagrant
[root@localhost ~]# usermod -G wheel vagrant
[root@localhost ~]# passwd vagrant
Changing password for user vagrant.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#

let the vagrant user sudo without a password,

[root@localhost ~]# cp /etc/sudoers.orig /etc/sudoers
[root@localhost ~]# visudo
<
edits:
  * don't require TTY (so password-less sudo works via SSH)
  * don't require password for users in wheel group sudo 
>
[root@localhost ~]# diff /etc/sudoers /etc/sudoers.orig
56c56
< Defaults    requiretty
---
> # Defaults    requiretty
86c86
< # %wheel        ALL=(ALL)       NOPASSWD: ALL
---
> %wheel      ALL=(ALL)       NOPASSWD: ALL

install the vagrant public key,

Note: Oracle Linux certificate bundle does not come with the DigiCert one (see http://bugs.centos.org/view.php?id=4899). So we use the -k argument to tell curl it is OK to accept the "insecure" file from github.

[root@localhost ~]# curl -kL $h/keys/vagrant.pub > vagrant.pub
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   409  100   409    0     0    315      0  0:00:01  0:00:01 --:--:--  399k
[root@localhost ~]# mkdir ~vagrant/.ssh
[root@localhost ~]# cp vagrant.pub ~vagrant/.ssh/authorized_keys
[root@localhost ~]# chmod 700 ~vagrant/.ssh
[root@localhost ~]# chmod 600 ~vagrant/.ssh/authorized_keys 
[root@localhost ~]# chown vagrant.vagrant ~vagrant/.ssh
[root@localhost ~]# chown vagrant.vagrant ~vagrant/.ssh/authorized_keys 

and open port 2222 for SSH.

[root@localhost ~]# vi /etc/ssh/sshd_config 
...
Port 22
Port 2222
...

Export the Vagrant Box

In VirtualBox GUI, rename Oracle VM from "Oracle Developer Days" to "oracle_11.2g" (mainly cosmetic).  Then we package up the box and add it to Vagrant:

$ cd ~/VirtualBox\ VMs/oracle_11.2g
$ time vagrant package --base oracle_11.2g
[oracle_11.2g] Clearing any previously set forwarded ports...
[oracle_11.2g] Creating temporary directory for export...
[oracle_11.2g] Exporting VM...
[oracle_11.2g] Compressing package to: /Users/mark/VirtualBox VMs/oracle_11.2g/package.box

real 11m6.57s
user 5m3.42s
sys 0m6.07s
$ vagrant box add oracle_11.2g package.box
Successfully added box 'oracle_11.2g' with provider 'virtualbox'!
$

Spin up the Vagrant Box

$ cat > Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "oracle_11.2g"
end
^D
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'oracle_11.2g'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Mounting shared folders...
[default] -- /vagrant
The box should open without error. If there are problems, Vagrant shows you the stdout and stderr output, which should give you a clue as to the problem. To shut it down, type $ vagrant halt. Next up, configuring the server with Ansible.

No comments:

Post a Comment