Provision Fantom for Vagrant

Vagrant is an awesome tool for anyone who needs to develop or test against predictable OS configurations. If you’ve never played with – definitely check it out:

http://www.vagrantup.com

If you have a Linux box, the steps below will get Fantom up and running. These steps are for Debian/Ubnutu – so you may need to tweak for other distros.

1. Init your box

For this tutorial we’ll use the built-in Ubuntu box:

$ mkdir example
$ cd example
$ vagrant init hashicorp/precise32

2. Configure your Vagrantfile

Edit your Vagrantfile to add a provision step:

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "hashicorp/precise32"
  config.vm.provision :shell, path: "bootstrap.sh"

  # any other config you need

end

3. Add your bootstrap.sh script

Add a bootstrap.sh script in the same directory as your Vagrantfile:

#! /bin/bash

quiet() {
  # if provision is failing uncomment/comment to see full output
  #"$@"
  "$@" &> /dev/null
}

# Unzip
echo "Install unzip..."
quiet apt-get install unzip

#
# JDK
#   To install another version update 'JAVA_VER'
#   For example: JAVA_VER="7"
#
#   Note: if you use JDK7+ for compiling, then any compiled Fantom
#   pods will require a Java 7 or later runtime.  If you wish to target
#   Java 1.5 or 1.6 runtimes then you must use JDK 1.6 (JAVA_VER="6")
#
JAVA_VER="6"
echo "Install JDK $JAVA_VER..."
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" \
  >> /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" \
  >> /etc/apt/sources.list
echo "debconf shared/accepted-oracle-license-v1-1 select true" \
  | debconf-set-selections
echo "debconf shared/accepted-oracle-license-v1-1 seen true" \
  | debconf-set-selections
quiet apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
quiet apt-get update
quiet apt-get -y -f install oracle-java${JAVA_VER}-installer

#
# Fantom
#   To install a different version of Fantom update 'FAN_VER'
#   For example: FAN_VER="1.0.64'
#
FAN_VER="1.0.66"
FAN_ZIP="fantom-${FAN_VER}.zip"
echo "Installing Fantom ${FAN_VER}..."
wget -q https://bitbucket.org/fantom/fan-1.0/downloads/$FAN_ZIP
unzip -q $FAN_ZIP -d /opt
mv /opt/fantom-$FAN_VER /opt/fantom
bash /opt/fantom/adm/unixsetup
echo "export PATH=$PATH:/opt/fantom/bin/" >> /etc/profile
rm -f $FAN_ZIP

4. Boot your box

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise32' is up to date...
==> default: Setting the name of the VM: linux-arm_default_1407852247628_86495
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => /Users/andy/example
==> default: Running provisioner: shell...
    default: Running: /var/folders/2v/0phd0cks4t1d4922gq7yl6kw0000gn/T/vagrant-shell20140812-95565-18zm7ni.sh
==> default: stdin: is not a tty
==> default: Install unzip...
==> default: Install JDK 6...
==> default: Installing Fantom 1.0.66...
==> default: ###
==> default: ### FAN_HOME=/opt/fantom
==> default: ###

5. SSH in and Happy Fantom-ing!

$ vagrant ssh
vagrant@precise32:~$ fan -version
Fantom Launcher
Copyright (c) 2006-2013, Brian Frank and Andy Frank
Licensed under the Academic Free License version 3.0

Java Runtime:
  java.version:    1.6.0_45
  java.vm.name:    Java HotSpot(TM) Client VM
  java.vm.vendor:  Sun Microsystems Inc.
  java.vm.version: 20.45-b01
  java.home:       /usr/lib/jvm/java-6-oracle/jre
  fan.platform:    linux-x86
  fan.version:     1.0.66
  fan.env:         sys::BootEnv
  fan.home:        /opt/fantom

Comments are closed.