Tbpgr Blog

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

Chef | cookbook | Rbenv+Ruby2.0.0-p247+Bundler環境の作成

概要

Rbenv+Ruby2.0.0-p247+Bundler環境の作成

詳細

Rbenv+Ruby2.0.0-p247+Bundler環境の作成

手順

※各種ファイルの詳細については後述

# Kitchenの作成
mkdir rbenv_ruby_berkshelf
cd rbenv_ruby_berkshelf

# Kitchen初期化
knife solo init .

# Vagrantfile作成
vagrant init

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

# Berksfile作成
echo > Berksfile

# Berksfile編集。詳細は後述
vi Berksfile

# cookbookの作成
knife cookbook create rbenv_ruby200p247_bundler -o site-cookbooks/

# レシピの編集。詳細は後述
vi ./site-cookbooks/rbenv_ruby200p247_bundler/recipes/default.rb

# cookbookのダウンロード
berks install --path cookbooks

# vagrant起動確認
$ vagrant up

# install状態の確認
vagrant ssh

# Rubyのバージョン確認
vagrant@precise64:~$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]

# Rbenvのインストール済みRubyのリスト確認
vagrant@precise64:~$ rbenv versions
  system
* 2.0.0-p247 (set by /opt/rbenv/version)

# bundlerの確認
vagrant@precise64:~$ bundle -v
Bundler version 1.3.5

vagrant

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.box = "ubuntu-12.04-x64"
  config.omnibus.chef_version = "11.6.0"
  config.vm.network :private_network, ip: "192.168.33.21"
  config.berkshelf.enabled = false

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"]
    chef.add_recipe "rbenv"
    chef.add_recipe "rbenv_ruby200p247_bundler"
  end
end

Berkshelf

Berksfile
site :opscode

cookbook 'rbenv', ">= 1.4.1" , git: 'git://github.com/RiotGames/rbenv-cookbook.git'

cookbook

rbenv_ruby200p247_bundler
#
# Cookbook Name:: rbenv_ruby200p247_bundler
# Recipe:: default
#
# Copyright 2013
#
include_recipe 'rbenv::default'
include_recipe 'rbenv::ruby_build'

rbenv_ruby "2.0.0-p247" do
  ruby_version "2.0.0-p247"
  global true
end

rbenv_gem "bundler" do
  ruby_version "2.0.0-p247"
end