Tuesday, December 18, 2012

Vagrant, Chef and Node - Part 2

This is a continuation from the previous blog post in learning how to set up chef script to use a local file instead of downloading the required files from the internet every time the VM is initialized.

Two scenarios:

1. have the source code locally so chef only have to compile it
2. have the package file locally so chef only have to install it using the package manager

Have the source code locally:

This was the first experiment so dont expect any code quality on it. (its added as a todo task already)
1. Create folder - cookbooks/nodejs/files
2. Create folder - cookbooks/nodejs/files/default
3. Download http://nodejs.org/dist/v0.8.6/node-v0.8.6.tar.gz (nodejs source)
4. Move the tar file to default folder
5. Comment the following lines from /cookbooks/nodejs/recipes/install_from_source.rb
#remote_file "/usr/local/src/#{nodejs_tar}" do
#  source nodejs_src_url
#  checksum node['nodejs']['checksum']
#  mode 0644
#end

6. Add the following lines instead
cookbook_file "/usr/local/src/#{nodejs_tar}" do
    action :create
    source "node-v0.8.6.tar.gz"
    mode 0644
end

7. destroy the VM and initialize it again using 'vagrant up'
8. Done!!

Todo:

1. Update the recipe to have this as a config option so I can propose the change back to the author of the recipe
2. Make the same changes on the install_from_package.rb

It still takes too long to startup (430seconds) and i suspect that most of that time is spent on downloading build-essential tools and compiling node from source. I hope this will be fixed once i introduce locally saved packaged file.

No comments: