rake-deploy 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -4
- data/Rakefile +10 -0
- data/lib/rake/deploy.rb +12 -19
- data/lib/rake/deploy/deploy.rb +27 -5
- data/rake-deploy-0.1.gem +0 -0
- data/rake-deploy.gemspec +1 -1
- data/test/test_deploy.rb +33 -0
- metadata +5 -3
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A deploy system using rake. Maybe a light version of capistrano
|
4
4
|
|
5
|
+
You may prefer to see the [updated wiki](http://wiki.github.com/guillermo/rake-deploy/)
|
6
|
+
|
5
7
|
## Motivation
|
6
8
|
|
7
9
|
Capistrano is a great project, maybe a little big in some cases, but with one big problem: it aims to cover all possible use cases.
|
@@ -22,7 +24,6 @@ In your Rakefile add:
|
|
22
24
|
|
23
25
|
In any of your task files (for example, for rails: lib/tasks/deploy.rake)
|
24
26
|
|
25
|
-
deploy.application = "app_name"
|
26
27
|
deploy.deploy_to = "/apps/app_name"
|
27
28
|
deploy.repository = "ssh://user@github.com/myrepo.git"
|
28
29
|
deploy.host = "esther.cientifico.net"
|
@@ -45,9 +46,8 @@ Or you want to make a backup of your database in each deploy
|
|
45
46
|
deploy.run("db.my_company.com", "mysqldump -u root my_app_db_production | gzip > /var/backups/#{deploy.release_name}.db.sql.bz2")
|
46
47
|
end
|
47
48
|
|
48
|
-
You can see more recipes, that you most copy and paste and edit in your files in the wiki:
|
49
|
+
You can see more [recipes](http://wiki.github.com/guillermo/rake-deploy/recipes), that you most copy and paste and edit in your files in the wiki:
|
49
50
|
|
50
|
-
http://wiki.github.com/guillermo/rake-deploy/recipes
|
51
51
|
|
52
52
|
## Conventions
|
53
53
|
|
@@ -64,7 +64,7 @@ Guillermo Álvarez <guillermo@cientifico.net>
|
|
64
64
|
|
65
65
|
## Web
|
66
66
|
|
67
|
-
http://github.com/guillermo/rake-deploy
|
67
|
+
[Github rake-deploy](http://github.com/guillermo/rake-deploy)
|
68
68
|
|
69
69
|
## Date of writing
|
70
70
|
|
data/Rakefile
ADDED
data/lib/rake/deploy.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'net/ssh'
|
2
|
-
require 'ostruct'
|
3
1
|
require 'rake/hooks'
|
4
2
|
require 'rake/deploy/deploy'
|
5
3
|
require 'rake/deploy/object'
|
@@ -7,55 +5,50 @@ require 'rake/deploy/object'
|
|
7
5
|
desc 'Deploy the application'
|
8
6
|
task :deploy => ["deploy:symlink"]
|
9
7
|
|
10
|
-
|
11
8
|
namespace :deploy do
|
12
9
|
|
13
10
|
desc 'Generate timestamp for revision name'
|
14
11
|
task :generate_timestamp do
|
15
12
|
deploy.release_name ||= Time.now.utc.strftime("%Y%m%d%H%M.%S")
|
16
13
|
deploy.release_path ||= "#{deploy.deploy_to}/releases/#{deploy.release_name}"
|
14
|
+
deploy.current_path ||= "#{deploy.deploy_to}/current"
|
17
15
|
end
|
18
16
|
|
19
17
|
desc 'Update remote repo'
|
20
18
|
task :update_repo do
|
21
19
|
puts "=> update_repo"
|
22
|
-
deploy.run(
|
20
|
+
deploy.run("cd #{deploy.deploy_to}/shared/repo && git fetch")
|
23
21
|
end
|
24
22
|
|
25
23
|
desc 'Checkout newer version'
|
26
24
|
task :checkout => [:generate_timestamp,:update_repo] do
|
27
25
|
puts "=> checkout"
|
28
|
-
deploy.run(
|
29
|
-
deploy.run(
|
26
|
+
deploy.run("mkdir -p #{deploy.deploy_to}/releases/")
|
27
|
+
deploy.run("git clone -s #{deploy.deploy_to}/shared/repo #{deploy.release_path} && cd #{deploy.release_path} && git checkout #{deploy.branch}")
|
30
28
|
deploy.shared.each do |shared_path|
|
31
|
-
deploy.run(
|
32
|
-
deploy.run(
|
29
|
+
deploy.run("rm -rf #{deploy.release_path}#{shared_path}")
|
30
|
+
deploy.run("ln -s #{deploy.deploy_to}/shared/scaffold#{shared_path} #{deploy.release_path}#{shared_path}")
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
34
|
desc 'Symlink to new version'
|
37
35
|
task :symlink => [:checkout] do
|
38
36
|
puts "=> symlink"
|
39
|
-
deploy.run(
|
40
|
-
deploy.run(
|
37
|
+
deploy.run("unlink #{deploy.deploy_to}/current")
|
38
|
+
deploy.run("ln -s #{deploy.release_path} #{deploy.deploy_to}/current")
|
41
39
|
end
|
42
40
|
|
43
41
|
desc 'Setup'
|
44
42
|
task :setup do
|
45
43
|
puts "=> setup"
|
46
44
|
%w(/releases /shared/scaffold/tmp /shared/scaffold/log).each do |path|
|
47
|
-
deploy.run(
|
45
|
+
deploy.run("mkdir -p #{deploy.deploy_to}#{path}")
|
48
46
|
end
|
49
47
|
|
50
|
-
deploy.run(
|
51
|
-
deploy.run(
|
48
|
+
deploy.run("ln -s #{deploy.deploy_to}/shared/scaffold/tmp #{deploy.deploy_to}/shared/tmp ")
|
49
|
+
deploy.run("ln -s #{deploy.deploy_to}/shared/scaffold/log #{deploy.deploy_to}/shared/log ")
|
52
50
|
|
53
|
-
deploy.run(
|
51
|
+
deploy.run("git clone --bare #{deploy.repository} #{deploy.deploy_to}/shared/repo")
|
54
52
|
end
|
55
53
|
|
56
54
|
end
|
57
|
-
|
58
|
-
after :deploy do
|
59
|
-
puts "=> restart"
|
60
|
-
deploy.run(deploy.host, "touch #{deploy.deploy_to}/current/tmp/restart.txt")
|
61
|
-
end
|
data/lib/rake/deploy/deploy.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'ostruct'
|
3
|
+
|
1
4
|
class Deploy < OpenStruct
|
2
5
|
def initialize
|
3
6
|
super
|
@@ -8,11 +11,30 @@ class Deploy < OpenStruct
|
|
8
11
|
self.user = `who am i`.split(" ").first
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
# Run a command in a remote server:
|
15
|
+
# run("ls") Run ls in current deploy.host
|
16
|
+
# run("my_host.com", "ls") run ls in "my_host.com"
|
17
|
+
# run("my_host.com", "guillermo", "ls") run ls in "my_shot.com" as user "guillermo"
|
18
|
+
def run(*args)
|
19
|
+
case args.size
|
20
|
+
when 3
|
21
|
+
ssh_host, ssh_user, ssh_command = args
|
22
|
+
when 2
|
23
|
+
ssh_host, ssh_command = args
|
24
|
+
ssh_user = self.user
|
25
|
+
when 1
|
26
|
+
ssh_host, ssh_user = self.host, self.user
|
27
|
+
ssh_command = args.first
|
28
|
+
else
|
29
|
+
raise ArgumentError
|
30
|
+
end
|
31
|
+
return ssh_host.map{|host| run(host, ssh_user, ssh_command)} if ssh_host.is_a? Array
|
32
|
+
|
33
|
+
key = "#{ssh_user}@#{ssh_host}"
|
34
|
+
puts " #{key}$ #{ssh_command}"
|
35
|
+
@ssh_sessions[key] ||= Net::SSH.start(ssh_host, ssh_user)
|
36
|
+
output = @ssh_sessions[key].exec!(ssh_command)
|
37
|
+
puts output.split("\n").map{|l| " #{key}> #{l}"}.join("\n") if output
|
16
38
|
output
|
17
39
|
end
|
18
40
|
|
data/rake-deploy-0.1.gem
ADDED
Binary file
|
data/rake-deploy.gemspec
CHANGED
data/test/test_deploy.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rake/deploy/deploy'
|
4
|
+
|
5
|
+
# As you see this is a integration test as Net::SSH is not mocked.
|
6
|
+
# It was easy for me test in real machines.
|
7
|
+
# If you make a mock for Net::SSH fot this tests cases, please send it to me.
|
8
|
+
class TestDeployClass < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@deploy = Deploy.new
|
11
|
+
@deploy.host = 'esther'
|
12
|
+
@deploy.user = 'guillermo'
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_run_one_argument
|
16
|
+
assert_equal "wadus", @deploy.run("echo wadus").strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_with_host
|
20
|
+
assert_equal "superwadus", @deploy.run("yolanda","echo superwadus").strip
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_with_host_and_user
|
24
|
+
assert_equal "argh", @deploy.run("esther", "sessiondeo","echo argh").strip
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_with_more_than_one_host
|
28
|
+
assert_equal ["argh\n","argh\n"], @deploy.run(["esther","yolanda"], "guillermo","echo argh")
|
29
|
+
assert_equal ["toma\n","toma\n"], @deploy.run(["esther","yolanda"], "echo toma")
|
30
|
+
@deploy.host = ["esther","yolanda"]
|
31
|
+
assert_equal ["mola\n","mola\n"], @deploy.run("echo mola")
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Guillermo \xC3\x81lvarez"
|
@@ -72,11 +72,13 @@ extra_rdoc_files: []
|
|
72
72
|
files:
|
73
73
|
- LICENSE
|
74
74
|
- README.md
|
75
|
+
- Rakefile
|
75
76
|
- lib/rake/deploy/deploy.rb
|
76
77
|
- lib/rake/deploy/object.rb
|
77
78
|
- lib/rake/deploy.rb
|
78
79
|
- rake-deploy-0.1.gem
|
79
80
|
- rake-deploy.gemspec
|
81
|
+
- test/test_deploy.rb
|
80
82
|
has_rdoc: true
|
81
83
|
homepage: http://github.com/guillermo/rake-deploy
|
82
84
|
licenses: []
|