Uncategorized

Testing juju without wrecking juju

The Juju core team have been diligently ramping up to Juju 2.0. As a result they have been steadily releasing new alphas and betas of juju for testing and feedback. However, for some that’s not quite fast enough! If you’re looking to try out, or contribute to juju, odds are you’re going to want to compile from source. This article aims to cover how to do this and manage all the versions of juju you have floating around your system – compiled versions of juju, stable version of juju, and the released development versions.

GO LANG, Go!

Install golang on your favorite (Ubuntu)* operating system

sudo apt-get install golang-go git-core mercurial bzr

* Does not have to be Ubuntu

Once that’s done, you’ll want to create a directory for your golang fun. For example, I put everything in ~/Projects/go though in this example we’ll use ~/go

export GOPATH=$HOME/go
mkdir -p $GOPATH

You’ll want to save this in your .profile (echo 'export GOPATH=$HOME/go' >> ~/.profile)

GO get Juju!

Next we need to go get the juju source code. You’ll need to run the following, it’ll download not just the juju source code, but also it’s dependency. It will also almost always fail with an error – that’s expected.

go get -v github.com/juju/juju/...

Once it fails (or succeeds) you’ll want to go to the juju source directory and install/update GODEPS

cd $GOPATH/src/github.com/juju/juju
JUJU_MAKE_GODEPS=true make godeps
go get -v github.com/juju/juju/...

At this point now you should have a freshly built juju binary from the master branch of juju!

$GOPATH/bin/juju version

If you get a response, success! You can now run juju from that directory.

Juju and Juju and Juju

If you’re like me, I often have to switch around between Juju 1.X, Juju 2.0, and Juju master. This is tiring when I have to run full paths to each. Juju, since Juju 0.6, has provided a mechanism with update-alternatives to easily define and switch versions. To date, you can switch between stable and devel at any time (after installing juju-core and juju-core2 packages from ppa:juju/stable and ppa:juju/devel respectively)

sudo update-alterantives --config juju

Which should show you the following options:

marco@ubuntu:~$ sudo update-alternatives --config juju
There are 2 choices for the alternative juju (providing /usr/bin/juju).

  Selection    Path                              Priority   Status
------------------------------------------------------------
* 0            /usr/lib/juju-2.0-beta1/bin/juju   30        auto mode
  1            /usr/lib/juju-1.25.3/bin/juju      30        manual mode
  2            /usr/lib/juju-2.0-beta1/bin/juju   30        manual mode

Press enter to keep the current choice[*], or type selection number: 

This allows you to switch between different versions of juju for the juju command. To add an new entry to this, run the following:

sudo update-alternatives --install /usr/bin/juju juju $GOPATH/bin/juju 0

This will register your compiled juju version as an additional alternative. When you run update-alternatives again you’ll have another option and can enter the number corresponding to that entry to make it the version used.

There are 3 choices for the alternative juju (providing /usr/bin/juju).

  Selection    Path                              Priority   Status
------------------------------------------------------------
  0            /usr/lib/juju-2.0-beta1/bin/juju   30        auto mode
  1            /home/marco/Projects/go/bin/juju   0         manual mode
  2            /usr/lib/juju-1.25.3/bin/juju      30        manual mode
* 3            /usr/lib/juju-2.0-beta1/bin/juju   30        manual mode

Press <enter> to keep the current choice[*], or type selection number: 1

Now, if I run juju version I get 2.0-beta2-xenial-amd64 which is the latest build version.

Update Juju

At anytime, if you want to refresh your version of Juju, you can do the following:

cd $GOPATH/src/github.com/juju/juju
git fetch origin
git merge --ff-only origin/master
JUJU_MAKE_GODEPS=true make godeps
go get -v github.com/juju/juju/...

This will, fetch the latest versions from the upstream github repository, merge those changes to your copy, re-run godeps for the latest dependencies, then build and place the new binary in $GOPATH/bin/juju. Just make sure that’s the version you’ve selected in update-alternatives and you’ll be good to go!