Download - Devops days
Our love for Chef and Vagrant Derek Szydlowski
&Yosuke Tomita
Our setupWhy Chef and vagrant - Challenges
Starting project Knife vs Vagrant (Solo)Best practice/code to define recipes for multiple environments
Problems with Vagrant / ChefDevelopment Flow
Recap and why it’s good for international office.More external info sources add chef and vagrant link
OUTLINE
Intro
60 + production servers ( 120 total )3 + environments
50 + repos15 + active contributors
Challenges
作業記録なし
Manual Environments = Unstable unscalable environments
バラバラな環境
CHALLENGE 1
テスト不可
単調な作業 の連続 → 人為的ミス
Devs and Devops not in syncChef meets Vagrant
CHALLENGE 2
開発者は実装にのみ集中しがち
Opsの作業時間がタスクに含まれていない
新メンバーが入った時、新しい技術を入れた時の環境構築が大変
Chef / Chef-Solo: configuration management tool
Chef Recipe/Cookbook: Chef configuration file
AWS EC2: Virtual Machine Cloud Service
VirtualBox: Virtual Machine for Local Environments
Vagrant: wrapper for creating VirtualMachines, delivering chef recipes and runs Chef remotely
Knife-solo: Delivers recipes and runs chef remotely.
Words and Terms
Workflow
Outline
Development Flow
Code Example
Let’s dip into the code and see some ways to create a dev vs production server.
Production/QAKnife-Solo
roles/api.rbrun_list(
"role[base]",
"recipe[nginx]",
"recipe[python]",
"recipe[repos::api]", "recipe[monit]",
"recipe[monit::nginx]",
"recipe[monit::api]"
)
LocalVagrant
Vagrantfileconfig.vm.provision :chef_solo do |chef|
chef.add_recipe "base::git"
chef.add_recipe "nginx"
chef.add_recipe "php_pack"
chef.add_recipe "python"
chef.add_recipe "repos::api" end
Sharing recipe on local and servers
Changing server configuration in a template
cookbooks/repos/templates/api.erb------<%- case node[‘environment'] %><%- when "live" %> api_url = 'http://api.gengo.com'<%- when "qa" %> api_url = 'http://yyy.api.gengo.com'<%- when "dev" %> api_url = 'http://xxx.api.gengo.com'<%- end %>------
Define in “node/xxx.json or Vagrantfile”
Changing server configuration via Attributes
cookbooks/repos/attributes/default.rb------if node['environment'] == 'live' default['repos']['gengo_database'] = "database_live" default[‘repos’][‘nginx_security_password’] = “true”elseif node['environment'] == 'qa' default['repos']['gengo_database'] = "database_qa" default[‘repos’][‘nginx_security_password’] = “false”------
cookbooks/repos/templates/api.erb------database = ‘<%= default['repos']['gengo_database'] %>’------
Define in “node/xxx.json”or“Vagrantfile”
Changing Resource in a Recipe.
cookbooks/repos/recipes/api
if node['environment'] == "dev" git "#{node['repos']['home']}/#{project}" do repository "[email protected]:gengo/api.git" ssh_wrapper "/tmp/private_code/wrap-ssh4git.sh" action :checkout notifies :restart, "service[#{project}]" endelse deploy "/mnt#{node['repos']['home']}/#{project}" do ssh_wrapper "/tmp/private_code/wrap-ssh4git.sh" repo '[email protected]:gengo/api' branch "#{node['repos']['branch']}" migrate false keep_releases 3 notifies :restart, "service[#{project}]" endend
Define in “node/xxx.json” or“Vagrantfile”
Hurdles
Chef and Vagrant Hurdles!
opsもコードに強くなる必要がある → Devと一緒にやると距離が縮まる
devになかなか使ってもらえない
様々な開発環境(Window, Mac, Ubuntu….)
バグを踏むこともある → コミュニティ
Bonus!
Any Questions?
Name 3 languages that Gengo has client library for?
@gengo, @gengo_ja
https://github.com/gengo
http://gengo.doorkeeper.jp