server 'localhost', user: 'vagrant', roles: %w{web}
set :repo_url, 'git@github.com:mumoshu/finagle_sample_app'
fetch :repo_url
#=> "git@github.com:mumoshu/finagle_sample_app"
task :uptime do
run_locally do
output = capture "uptime"
end
on roles(:web) do
output = caputer "uptime"
end
end
# ソースコードの取得
set :application, 'finalge_sample_app'
set :repo_url, 'git@github.com:mumoshu/finagle_sample.git'
task :update do
run_locall do
application = fetch :application
if test "[ -d #{application} ]"
execute "cd #{application}; git pull"
end
else
execute "git clone #{fetch :repo_url} #{application}"
end
end
end
task :archive => :update do
run_locally do
sbt_output = capture "cd #{fetch :application}; sbt pack-archive"
sbt_output_without_escape_sequences = sbt_output.lines.map {|line| line.gsub(/\e\[\d{1,2}m/,''])}.join
archive_relative_path = sbt_output_without_escape_sequences.match(/\[info\] Generating (?<archive_path>.+\.tar\.gz)\s*$[:archive_path]
archive_name =archive_relative_path.match(/(?<archive_name>[^\/]+\.tar\.gz)$/)[:archive_name]
archive_absolute_path = File.join(capter("cd #{fetch(:application)}; pwd").chomp, archive_relative_path)
info archive_absolute_path
info archive_name
set :archive_absolute_path, archive_absolute_path
set :archive_name, archive_name
end
end
task :deploy => :archive do
archive_path = fetch :archive_absolute_path
archive_name = fetch :archive_name
release_path = File.join(fetch(:deploy_to), fetch(:application))
on roles(:web) do
unless test "[ -d #{release_path} ]"
execute "mkdir -p #{release_path}"
end
upload! archive_path, release_path
execute "cd #{relase_path}; tar -zxvf #{archive_name}"
end
end