ページ ツリー
メタデータの末尾にスキップ
メタデータの先頭に移動

Kitchen を使う準備

Kitchen について詳しくは Kitchen での Cookbook の動作チェック(ChefsMeetingNagoya Vol.1)#Kitchenとは を参照してください。

 

.kitchen.yml

rails Cookbook では以下のような .kitchen.yml を作成しました。
rails はデフォルトで 3000 番ポートを使用しており、コンテナの 3000 番ポートをホストの 3000 番ポートにフォワーディングしています。

.kitchen.yml
 ---
driver:
  name: docker

provisioner:
  name: chef_zero

platforms:
  - name: centos-6.4
    driver_config:
      image: centos:centos6
      platform: rhel
      forward: 3000:3000

suites:
  - name: default
    run_list:
      - rails
    attributes:
       rails:
         user: kitchen 

 

Kitchen インスタンスの起動とプロビジョニング

インスタンスを起動し Recipe の実行が終わったら、Kitchen インスタンスにログインしてみてください。

[vagrant] $ kitchen setup
[vagrant] $ kitchen login
kitchen@localhost’s password: kitchen


ログインできたら、Recipe が期待通りに動作したか確認してみてください。

[kitchen@0d7a89c6c42d ~]$ rails new myRails
// 出力は省略します。
 
[kitchen@0d7a89c6c42d ~]$ cd myRails
[kitchen@0d7a89c6c42d ~]$ vi Gemfile
	// コメントアウトを削除して有効化します。
	gem 'therubyracer',  platforms: :ruby

[kitchen@0d7a89c6c42d ~]$ bundle install
// 出力は省略します。
 
[kitchen@0d7a89c6c42d myRails]$ rails server
=> Booting WEBrick
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2014-08-22 14:05:03] INFO  WEBrick 1.3.1
[2014-08-22 14:05:03] INFO  ruby 2.1.2 (2014-05-08) [x86_64-linux]
[2014-08-22 14:05:03] INFO  WEBrick::HTTPServer#start: pid=13169 port=3000

※実行中のrails server にブラウザでアクセスしてみるので、終了はしないでください。

 

Web ブラウザで rails Server にアクセス

Firefox などの Web ブラウザで http://localhost:3000/ にアクセスしてみてください。
rails の画面が表示されていれば成功です。



Serverspec を使ったテスト

テストコードは以下の様に作成しました。

require 'serverspec'

include Serverspec::Helper::Exec
include Serverspec::Helper::DetectOS

describe command("sudo -iu kitchen ruby -v") do
  it { should return_stdout /^ruby 2\.1\.2.*/}
end

describe command('sudo -iu kitchen rails -v') do
  it { should return_stdout 'Rails 4.1.0'}
end
  • ラベルがありません
コメントを書く…