Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Chef | cookbook | opscodeのphantomjs cookbookを利用してphantomjsをインストール + シンボリックリンクを作成

概要

opscodeのphantomjs cookbookを利用してphantomjsをインストール後に、シンボリックリンクを作成

詳細

opscodeのphantomjs cookbookを利用してphantomjsをインストール後に、シンボリックリンクを作成します。
http://community.opscode.com/cookbooks/phantomjs

手順

# kitchenの作成
mkdir phantomjs
cd phantomjs
knife solo init .

# Vagrantfile生成
vagrant init

# Vagrantfile編集 ※詳細は後述
vi Vagrantfile

# cookbookのテンプレート生成
knife cookbook create phantomjs_symbolic_link -o site-cookbooks/

# Berksfileの作成
echo > Berksfile

# Berksfileの編集 ※詳細は後述
vi Berksfile

# Berksfileに記述したcookbookのインストール
berks install --path cookbooks

# recipeの編集 ※詳細は後述

# vagrant起動
vagrant up
vagrant provision

# 動作確認
vagrant ssh
vagrant@precise64:~$ phantomjs -v
1.9.2
vagrant@precise64:~$ cd /usr/bin
vagrant@precise64:/usr/bin$ ll -a | grep "phantomjs" | xargs ruby -e "ARGV.each {|e|print e;print ' '};puts" | cut -d" " -f9-11
phantomjs -> /usr/local/bin/phantomjs*

Vagrantfile

# -*- 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.provider :virtualbox do |vb|
    vb.name = "phantomjs"
    vb.customize ["modifyvm", :id, "--memory", 512]
  end

  config.vm.box = "ubuntu-12.04-x64"
  config.omnibus.chef_version = "11.6.0"
  config.vm.network :private_network, ip: "192.168.33.22"
  config.berkshelf.enabled = false
  
  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"]
    chef.add_recipe "phantomjs"
    chef.add_recipe "phantomjs_symbolic_link"
  end
end

Berksfile

site :opscode

cookbook 'phantomjs'

site-cookbooks/phantomjs_symbolic_link/library/helper.rb

class Chef
  class Recipe
    def execute_with_log(name, &block)
      log "start #{name}"
      block.call
      log "end   #{name}"
    end
  end
end

site-cookbooks/phantomjs_symbolic_link/recipe/default.rb

execute_with_log("create phantomjs symbolic link") do
  link "/usr/bin/phantomjs" do
    to "/usr/local/bin/phantomjs"
  end
end