Tbpgr Blog

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

Chef | RiotGamesのrbenv cookbookを利用する際に、自分が所属しているネットワークでgitプロトコルが使えない場合

概要

RiotGamesのrbenv cookbookを利用する際に、自分が所属しているネットワークでgitプロトコルが使えない場合

詳細

RiotGamesのrbenv cookbookを利用する際に、自分が所属しているネットワークでgitプロトコルが使えない場合について。
社内のセキュリティ設定などの関係で、gitプロトコルを利用出来ない場合
httpsプロトコルリポジトリを取得するようにする必要があります。

RiotGamesのrbenv cookbookはattributes/default.rbでgitプロトコルの取得先指定をしているので、
クックブックの作成時にattributes/default.rbを上書くことで対応します。

vagrant

Vagrantfile
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.20"
  config.berkshelf.enabled = false

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

berkshelf

Berksfile
site :opscode

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

クックブック

/site-cookbooks/ruby/attributes/default.rb
# gitプロトコルが使えないためhttpsに変更する
default[:rbenv][:git_repository] = "https://github.com/sstephenson/rbenv.git"
default[:ruby_build][:git_repository] = "https://github.com/sstephenson/ruby-build.git"
default[:rbenv_vars][:git_repository] = "https://github.com/sstephenson/rbenv-vars.git"
/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/ruby/recipe/default.rb
include_recipe 'rbenv::default'
include_recipe 'rbenv::ruby_build'

execute_with_log("install ruby2.0.0-p247") do
  rbenv_ruby "2.0.0-p247" do
    ruby_version "2.0.0-p247"
    global true
  end
end

execute_with_log("install bundler") do
  rbenv_gem "bundler" do
    ruby_version "2.0.0-p247"
  end
end