2. 自己紹介
describe Sonots do
its(:last_name} { should == ”瀬尾” }
its(:twitter) { should == ”@sonots” }
its(:company) { should == :DeNA }
its(:job_title) { should == ”Infra Engineer” }
it_should_behave_like ”DeNA employee”
end
shared_examples_for ”DeNA employee” do
it { should write(:perl) } #=> fail
end
8. Mina works really fast because it’s a
deploy Bash script generator.
It generates an entire procedure as a
Bash script and runs it remotely in the
server.
シェルスクリプトを生成して、
リモートサーバで実行する
9. Compare this to the likes of Vlad or
Capistrano, Mina only creates one SSH
session per deploy, minimizing the
SSH connection overhead.
Capistrano と違って、
1度しかSSHセッションを開かない
速い
10. サンプル
config/deploy.rb $ gem install mina
require 'mina/git' $ mina init
require 'mina/bundler' $ mina deploy
require 'mina/rails' $ mina restart
set :domain, 'your.server.com'
set :user, 'your_username'
set :repository, 'https://github.com/xxx/repo.git’
task :deploy do
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_path'
invoke :'bundle:install'
end
end
task :restart do
queue! %[sudo service restart nginx]
end
11. サンプル(2)
$ mina setup #=>
config/deploy.rb
!"" current
!"" releases
require 'mina/rbenv'
#"" shared
!"" config
task :environment do
$ #"" database.yml
invoke :'rbenv:load'
#"" log
# invoke :'rvm:use'
end
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/shared/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
queue! %[mkdir -p "#{deploy_to}/shared/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
queue! %[touch "#{deploy_to}/shared/config/database.yml"]
queue %[echo "-----> Be sure to edit 'shared/config/
database.yml'."]
end
22. コマンドオプション
• mina は rake ベース
task :deploy, :host, :hoge do |t, args|
set :domain, args[:host]
puts args[:hoge]
end \(^0^)/
$ mina ”deploy[localhost,foobar]”
環境変数で ※なんとかしたいとは思っている
task :deploy
set :domain, ENV[‘HOST’]
puts ENV[‘HOGE’]
end
$ HOST=localhost HOGE=foobar mina deploy
23. 複数サーバ
multi_invoke
def multi_invoke(task, domains, args = [])
isolate do
domains.each do |domain|
set :domain, domain
yield if block_given?
run! if commands.any?
Rake::Task.tasks.each {|t| t.reenable }
end
end
end
rake タスクは1度実行するとフラグが立って、実行できなくなる
複数ホストに対して実行できるようなメソッドを用意