This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Capfile
91 lines (71 loc) · 2.24 KB
/
Capfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# regular deploys are as easy as "cap deploy"
# this will do a git clone of the code, build a package, sftp the package to the machine.
# Command line arguments:
#
# key=/path/to/ec2.pem (default: ~/.ec2.pem)
# host=ec2-123-example-amazon.com (no default, must specify)
require 'deploy/strategy/build'
BEGIN {
KEY = ENV['key'] || "#{ENV['HOME']}/.ec2.pem"
system "ssh-add '#{KEY}'"
}
load 'deploy'
set :ssh_options, {:auth_methods => %w{ publickey }, :keys => [KEY] }
set :user, ENV['user'] || 'root'
set :application, File.basename(`git config --get remote.origin.url`.chomp, '.*')
# Remote paths
set :deploy_to, "/tmp/#{application}"
set :currentloc, "#{deploy_to}/current"
set :logloc, "#{deploy_to}/log"
set :log, "#{logloc}/#{application}.log"
set :repository, "git@github.com:twitter/#{application}.git"
set :branch, "master"
set :scm, :git
set :strategy, Capistrano::Deploy::Strategy::Build.new(self)
set :copy_cache, true
set :remote_unzip_dir, release_name
set :keep_releases, 3
set :build_task, "sbt clean update package-dist"
set :deploy_via, :copy
set :dist_path, "dist"
version = `git rev-parse HEAD`[0..7]
set :version, version
set :copy_compression, :zip
set :package_name, "#{application}-#{version}.#{copy_compression}"
hosts = [ENV['host'] || abort("You must specify a host with host=yourhost.com")]
role :app, *hosts
namespace :deploy do
[:finalize_update, :restart].each do |default_task|
task default_task do
# nothing
end
end
before 'deploy', 'deploy:setup'
after 'deploy', 'deploy:restart'
desc "Directory setup of remote machines."
task :setup, :roles => :app do
run "mkdir -p #{deploy_to}"
run "mkdir -p #{deploy_to}/releases"
run "mkdir -p #{logloc}"
run "mkdir -p /var/log/#{application}"
end
desc "Start"
task :start, :roles => :app do
run "cd #{currentloc}; nohup bash #{currentloc}/scripts/#{application}.sh -f config/production.conf &"
end
desc "Stop"
task :stop, :roles => :app do
run "pkill -f #{application} &>/dev/null || exit 0"
end
desc "Restart"
task :restart do
stop
start
end
task :update_code, :roles => :app do
on_rollback { run "rm -rf #{release_path}; true" }
run "mkdir -p #{release_path}"
strategy.deploy!
finalize_update
end
end