Configuring a CI Server With GIT on Ubuntu (Amazon EC2)

Written by

I would say that the majority of Flash Platform developers have now used source control.

As a developer are you testing locally, committing to source control and finally manually deploying your SWF’s to staging and production environments?

Do you work on applications as part of a team?

Do you use Continuous Integration (CI) and automated builds?

My answer was yes to all of the above except unfortunately the CI process. As you may well know from my blog and on twitter I have a keen interest with Project Sprouts and recently have also looked at Buildr, particulary Dominic Graefen’s AS3 port: Buildr-as3.

Together with Dominic (share my pain) Graefen (thnx man), I have been determined to setup a CI server using Jenkins on an Amazon EC2 instance which compiles SWFs and runs FlexUnit tests, for example on commit to git.

This was not a straight forward task…in fact it was a Grade A pain in the ar$e but eventually (it would appear) I managed to refine the process down to achieve the goal. Below are the steps that I have taken to set up an EC2 micro-instance with Git, Jenkins, RVM, Ruby, VNC, standalone debugger Flash Player, Buildr-as3 and compile/run FlexUnit tests using a Flex 4 based example! I have setup and torn down at least 6 instances to test and remove surplus instructions so hopefully it’s as lean as possible.

I am sure there could be further refinements made and on one of my test server setups I found I had some odd output which I need to work out why and where?

*(gflashplayer:1490): GLib-GObject-WARNING **: instance of invalid non-instantiatable type `(null)’

(gflashplayer:1490): GLib-GObject-CRITICAL *: g_signal_handlers_disconnect_matched: assertion `G_TYPE_CHECK_INSTANCE (instance)’ failed

But the tests run and all is happy. Micro-instances and rvm/project builds are not fast and I found have a tendency to hang on the first run/install so perseverance is required, but once running, all seems sweet with the world. Any further tips or guidance would be most welcomed! Oh and if you want to see an example of using CI for your Flex/Flash project just take a peek at this super sweet example.

EC2 Setup

Add SSH keys to EC2

1
http://alestic.com/2010/10/ec2-ssh-keys

Create EC2 instance from AMI (includes gitolite)

1
http://alestic.com/alestic-git/overview

Ubuntu Requirements

Includes basics from setup requirements

1
2
3
4
5
sudo apt-get update

sudo apt-get upgrade

sudo apt-get install build-essential dkms gcc linux-headers-$(uname -r) ncurses-dev zlibc zlib1g zlib1g-dev ia32-libs curl

Install necessary packages for ruby/rvm/buildr

1
sudo apt-get -y install unixodbc unixodbc-dev freetds-dev tdsodbc sqsh libxslt-dev libxml2-dev bison openssl libreadline6 libreadline6-dev git-core libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 autoconf libc6-dev

Jenkins Setup

Install Jenkins as per jenkins installation

Ensure port 8080 is open

1
2
3
4
5
cd /tmp
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo aptitude update
sudo aptitude install jenkins

Configure Jenkins user

1
2
3
sudo adduser jenkins admin

sudo passwd jenkins

RUBY/RVM Setup - logged in as jenkins user

Install RVM

Huge props to this dudes article.

1
2
3
sudo su - jenkins

bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

Configure .bashrc & .profile

1
2
touch ~/.bashrc
touch ~/.profile

Copy below source to .bashrc and reload

.bashrc source

1
source ~/.bashrc

Copy below source to .profile and reload

.profile source

1
source ~/.profile

Java Setup

Install correct JDK

1
sudo apt-get install openjdk-6-jdk

Configure JAVA_HOME path

1
2
3
4
5
6
7
vi ~/.bashrc

# Set JAVA_HOME path
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

Reload .bashrc

1
source ~/.bashrc

Check path is correct

1
echo $JAVA_HOME

Reboot - not 100% necessary

1
sudo reboot

Ruby Setup

Install Ruby 1.9.2

1
rvm install 1.9.2-p180

note Takes a while on an EC2 micro-instance (seriously can take ages > 30mins)

Set 1.9.2 as ruby default

1
rvm --default 1.9.2-p180

Prevent ri & RDoc creation due to time - optional

1
2
sudo su - jenkins
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc

Gems Setup

Install Bundler

1
gem install bundler

Install buildr

1
JAVA_HOME=$JAVA_HOME gem install buildr

Install buildr-as3

1
gem install buildr-as3

Flash Setup

Install Standalone debugger FlashPlayer

As root

1
2
3
4
5
6
7
8
9
10
11
cd /tmp

wget http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_sa_debug.tar.gz

tar xzvf flashplayer_10_sa_debug.tar.gz

sudo mv flashplayerdebugger /usr/bin

sudo ln -s /usr/bin/flashplayerdebugger /usr/bin/gflashplayer

rm flashplayer_10_sa_debug.tar.gz

VNC Setup

Install Vnc server

Instructions sourced here

1
2
3
sudo apt-get install vnc4server xinetd

vnc4server

Enter a password & take notice of the number after the colon (:)

1
vnc4server -kill :1

Replace the number “1” with the number from above.

1
2
3
sudo chmod 755 /etc/X11/xinit/xinitrc

sudo apt-get install vncviewer

Enable for Vnc Jenkins

1
2
3
4
5
sudo su - jenkins

vnc4server

vnc4server -kill :[number after colon when started server]

Install XVNC plugin in jenkins

1
2
3
https://wiki.jenkins-ci.org/display/JENKINS/Xvnc+Plugin

Jenkins > Manage Jenkins > Manage Plugins > Available

Reboot

Project Setup

1
sudo reboot

Create a new project

In Jenkins create a new free-style software project called SomeProject.

Enable Xvnc for project

1
Project > Configure > Build Environment > Run Xvnc during build

Run a build

To generate a workspace you need to run a build first

Install unzip

1
sudo apt-get install unzip

Copy local workspace to remote

1
2
3
sudo su - jenkins

cd jobs/SomeProject/

You may want to guarantee the integrity of the following zip before performing wget

1
wget http://db.tt/Dx5LbUo

Unzip workspace and cleanup

1
2
3
rm -r workspace
unzip [whatever wget saved it as mine was Dx5LbUo]
rm -r [whatever wget saved it as mine was Dx5LbUo] __MACOSX

Run first build on command line - also takes a long time for first build

1
2
3
4
sudo su - jenkins
cd ~/jobs/SomeProject/workspace
buildr clean
buildr test

Configure project build

In Jenkins > Project > Configure > Add Build Step > Execute Shell

1
2
buildr clean
buildr test

Post Build Actions > Publish JUnit test result report

1
**/reports/flexunit4/*.xml

And finally click Save at the bottom of the configuration page.

Build Project

Click Build Now

Note this build may take a couple of attempts

Further reading

Comments