yads 0.0.3.pre2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .DS_Store
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
- require 'bundler'
1
+ require "bundler"
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList["test/**/test_*.rb"]
8
+ t.verbose = true
9
+ end
data/bin/yads CHANGED
@@ -1,4 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
+ require "slop"
2
3
 
3
- require "yads"
4
- Yads::Deployer.new(STDOUT).deploy
4
+ opts = Slop.new(:strict => true)
5
+ opts.parse do |action|
6
+ require "yads"
7
+ deployer = Yads::Deployer.new(STDOUT)
8
+
9
+ action = action.to_sym
10
+ if !action.empty? && deployer.respond_to?(action)
11
+ deployer.send(action)
12
+ else
13
+ puts "Unknow command \"#{action}\""
14
+ puts "Usage: yads [setup|deploy]"
15
+ end
16
+ end
data/examples/deploy.yml CHANGED
@@ -3,10 +3,10 @@ user: username
3
3
  forward_agent: true/false
4
4
 
5
5
  path: /path/on/remote/server
6
+ repository: git@repohost.com:myproject.git
6
7
  commands:
7
- clone: git clone --depth 1 git@repohost.com:myproject.git . # mandatory, other commands below are optional
8
8
  reset: git reset --hard
9
9
  pull: git pull origin master
10
10
  bundle: bundle install --deployment --binstubs --without development test
11
- migrate: ENV=production bin/rake db:migrate --silent
11
+ migrate: RAILS_ENV=production bin/rake db:migrate --silent
12
12
  restart: touch tmp/restart.txt
@@ -0,0 +1,41 @@
1
+ require "yaml"
2
+
3
+ module Yads
4
+ class Deployer
5
+
6
+ def initialize(logger = STDOUT)
7
+ @logger = logger
8
+ end
9
+
10
+ def setup
11
+ command = "mkdir -p #{config["path"]} && cd #{config["path"]} && git clone --depth 1 #{config['repository']} ."
12
+ @logger.puts("> #{command}")
13
+ @logger.puts(connection.execute(command))
14
+ end
15
+
16
+ def deploy
17
+ commands = config["commands"].values
18
+ commands.unshift("cd #{config["path"]}")
19
+ commands = commands.join(" && ")
20
+
21
+ @logger.puts("> #{commands}")
22
+ connection.execute(commands) do |output|
23
+ @logger.print(output)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def config
30
+ @config ||= begin
31
+ YAML.load(File.open("config/deploy.yml"))
32
+ rescue Errno::ENOENT
33
+ raise Yads::ConfigNotFound, "config/deploy.yml not found"
34
+ end
35
+ end
36
+
37
+ def connection
38
+ @connection ||= SSH.new(:host => config["host"], :user => config["user"], :forward_agent => config["forward_agent"])
39
+ end
40
+ end
41
+ end
data/lib/yads/ssh.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "net/ssh"
2
+
3
+ module Yads
4
+
5
+ class SSH
6
+
7
+ def initialize(config)
8
+ @ssh = Net::SSH.start(config[:host], config[:user], :forward_agent => config[:forward_agent])
9
+ end
10
+
11
+ def execute(cmd)
12
+ if block_given?
13
+ @ssh.exec(cmd) do |ch, stream, data|
14
+ yield data
15
+ end
16
+ @ssh.loop
17
+ else
18
+ @ssh.exec!(cmd)
19
+ end
20
+ end
21
+
22
+ def close
23
+ @ssh.close
24
+ end
25
+ end
26
+ end
data/lib/yads/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yads
2
- VERSION = "0.0.3.pre2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/yads.rb CHANGED
@@ -1,54 +1,6 @@
1
- require "net/ssh"
2
- require "yaml"
3
-
4
1
  module Yads
5
-
6
2
  class ConfigNotFound < Errno::ENOENT; end
7
3
 
8
- class Deployer
9
- def initialize(logger = STDOUT)
10
- @logger = logger
11
- end
12
-
13
- def deploy
14
- begin
15
- config = YAML.load(File.open("config/deploy.yml"))
16
- rescue Errno::ENOENT
17
- raise Yads::ConfigNotFound, "config/deploy.yml not found"
18
- end
19
-
20
- Net::SSH.start(config["host"], config["user"], :forward_agent => config["forward_agent"]) do |ssh|
21
- check_path(ssh, config["path"], config["commands"].delete("clone"))
22
-
23
- commands = config["commands"].values.unshift("cd #{config['path']}").join(" && ")
24
- @logger.puts "> #{commands}"
25
- @logger.puts
26
-
27
- ssh.exec(commands) do |ch, stream, data|
28
- print data
29
- end
30
-
31
- ssh.loop
32
- end
33
- end
34
-
35
- def check_path(ssh, path, clone)
36
- @logger.puts "> cd #{path}/.git"
37
- ssh.exec("cd #{path}/.git") do |ch, stream, data|
38
- if stream == :stderr
39
- @logger.puts "> cd #{path}"
40
- ssh.exec("mkdir -p #{path}; cd #{path}") do |ch1, stream1, data1|
41
- @logger.puts "> #{clone}"
42
- ssh.exec(clone) do |ch1, stream1, data1|
43
- abort data1 if stream1 == :stderr
44
-
45
- @logger.puts "> cd #{path}"
46
- ssh.exec("cd #{path}")
47
- end
48
- end
49
- end
50
- end
51
- ssh.loop
52
- end
53
- end
4
+ autoload :SSH, "yads/ssh"
5
+ autoload :Deployer, "yads/deployer"
54
6
  end
@@ -1,7 +1,8 @@
1
1
  host: rafaelss.com
2
2
  user: deploy
3
3
  forward_agent: true
4
- path: /Users/rafael/projects/yads/test/fixtures
4
+ path: /tmp/yads
5
+ repository: git@repohost.com:myrepo.git
5
6
  commands:
6
- chdir: cd /tmp/yads
7
+ migrate: rake db:migrate
7
8
  touch: touch test
@@ -0,0 +1,6 @@
1
+ require "bundler"
2
+ Bundler.require
3
+
4
+ require "minitest/autorun"
5
+ require "mocha"
6
+ require "net/ssh"
@@ -0,0 +1,54 @@
1
+ require "test_helper"
2
+
3
+ class TestYads < MiniTest::Unit::TestCase
4
+
5
+ def setup
6
+ @log_file = File.open("/dev/null", "w")
7
+ end
8
+
9
+ def test_try_loading_not_found_config_file_on_setup
10
+ assert_raises(Yads::ConfigNotFound) do
11
+ Dir.chdir("/tmp") do
12
+ deployer = Yads::Deployer.new(@log_file)
13
+ deployer.setup
14
+ end
15
+ end
16
+ end
17
+
18
+ def test_try_loading_not_found_config_file_on_deploy
19
+ assert_raises(Yads::ConfigNotFound) do
20
+ Dir.chdir("/tmp") do
21
+ deployer = Yads::Deployer.new(@log_file)
22
+ deployer.deploy
23
+ end
24
+ end
25
+ end
26
+
27
+ def test_setup
28
+ inside_project_root do
29
+ ssh = mock
30
+ ssh.expects(:execute).with("mkdir -p /tmp/yads && cd /tmp/yads && git clone --depth 1 git@repohost.com:myrepo.git .")
31
+ Yads::SSH.expects(:new).with(:host => "rafaelss.com", :user => "deploy", :forward_agent => true).returns(ssh)
32
+
33
+ deployer = Yads::Deployer.new(@log_file)
34
+ deployer.setup
35
+ end
36
+ end
37
+
38
+ def test_deploy
39
+ inside_project_root do
40
+ ssh = mock
41
+ ssh.expects(:execute).with("cd /tmp/yads && rake db:migrate && touch test")
42
+ Yads::SSH.expects(:new).with(:host => "rafaelss.com", :user => "deploy", :forward_agent => true).returns(ssh)
43
+
44
+ deployer = Yads::Deployer.new(@log_file)
45
+ deployer.deploy
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def inside_project_root(&block)
52
+ Dir.chdir(File.expand_path("../../fixtures", __FILE__), &block)
53
+ end
54
+ end
@@ -0,0 +1,46 @@
1
+ require "test_helper"
2
+
3
+ class TestSSH < MiniTest::Unit::TestCase
4
+
5
+ def test_connect
6
+ connection_mock
7
+
8
+ Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
9
+ end
10
+
11
+ def test_execute
12
+ session = mock
13
+ session.expects(:exec!).with("mkdir -p /tmp/yads")
14
+ connection_mock(session)
15
+
16
+ s = Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
17
+ s.execute("mkdir -p /tmp/yads")
18
+ end
19
+
20
+ def test_execute_with_block
21
+ session = mock
22
+ session.expects(:exec).with("echo $PATH").yields(nil, nil, "/usr/bin:/usr/local/bin")
23
+ session.expects(:loop)
24
+ connection_mock(session)
25
+
26
+ s = Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
27
+ s.execute("echo $PATH") do |output|
28
+ assert_equal "/usr/bin:/usr/local/bin", output
29
+ end
30
+ end
31
+
32
+ def test_close
33
+ session = mock
34
+ session.expects(:close)
35
+ connection_mock(session)
36
+
37
+ s = Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
38
+ s.close
39
+ end
40
+
41
+ private
42
+
43
+ def connection_mock(session = nil)
44
+ Net::SSH.expects(:start).with("example.org", "deploy", :forward_agent => true).returns(session)
45
+ end
46
+ end
data/yads.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Simple deployment tool that uses a single YAML file to put your code live}
14
14
 
15
15
  s.add_runtime_dependency "net-ssh", "~> 2.1.0"
16
+ s.add_runtime_dependency "slop", "~> 1.5.2"
16
17
  s.add_development_dependency "minitest", "~> 2.0.2"
17
18
  s.add_development_dependency "mocha", "~> 0.9.10"
18
19
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yads
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 0.0.3.pre2
4
+ prerelease:
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rafael Souza
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-06 00:00:00 -03:00
13
+ date: 2011-04-21 00:00:00 -03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -25,27 +25,38 @@ dependencies:
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: minitest
28
+ name: slop
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 1.5.2
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: minitest
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
31
42
  none: false
32
43
  requirements:
33
44
  - - ~>
34
45
  - !ruby/object:Gem::Version
35
46
  version: 2.0.2
36
47
  type: :development
37
- version_requirements: *id002
48
+ version_requirements: *id003
38
49
  - !ruby/object:Gem::Dependency
39
50
  name: mocha
40
51
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirement: &id004 !ruby/object:Gem::Requirement
42
53
  none: false
43
54
  requirements:
44
55
  - - ~>
45
56
  - !ruby/object:Gem::Version
46
57
  version: 0.9.10
47
58
  type: :development
48
- version_requirements: *id003
59
+ version_requirements: *id004
49
60
  description: Simple deployment tool that uses a single YAML file to put your code live
50
61
  email:
51
62
  - me@rafaelss.com
@@ -63,9 +74,13 @@ files:
63
74
  - bin/yads
64
75
  - examples/deploy.yml
65
76
  - lib/yads.rb
77
+ - lib/yads/deployer.rb
78
+ - lib/yads/ssh.rb
66
79
  - lib/yads/version.rb
67
80
  - test/fixtures/config/deploy.yml
68
- - test/test_yads.rb
81
+ - test/test_helper.rb
82
+ - test/yads/test_deployer.rb
83
+ - test/yads/test_ssh.rb
69
84
  - yads.gemspec
70
85
  has_rdoc: true
71
86
  homepage: http://github.com/rafaelss/yads
@@ -85,16 +100,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
100
  required_rubygems_version: !ruby/object:Gem::Requirement
86
101
  none: false
87
102
  requirements:
88
- - - ">"
103
+ - - ">="
89
104
  - !ruby/object:Gem::Version
90
- version: 1.3.1
105
+ version: "0"
91
106
  requirements: []
92
107
 
93
108
  rubyforge_project:
94
- rubygems_version: 1.6.1
109
+ rubygems_version: 1.6.2
95
110
  signing_key:
96
111
  specification_version: 3
97
112
  summary: Deploy your code using a YAML file
98
113
  test_files:
99
114
  - test/fixtures/config/deploy.yml
100
- - test/test_yads.rb
115
+ - test/test_helper.rb
116
+ - test/yads/test_deployer.rb
117
+ - test/yads/test_ssh.rb
data/test/test_yads.rb DELETED
@@ -1,53 +0,0 @@
1
- require "bundler"
2
- Bundler.require
3
-
4
- require "minitest/autorun"
5
- require "mocha"
6
-
7
- class TestYads < MiniTest::Unit::TestCase
8
-
9
- def setup
10
- @deployer = Yads::Deployer.new(File.open("/dev/null", "w"))
11
- end
12
-
13
- def test_check_path_abort
14
- ssh = mock
15
- ssh.expects(:exec).with("cd /tmp/yads/.git").yields("ch", :stderr, "data")
16
- ssh.expects(:exec).with("git clone git@repohost.com:myrepo.git .").yields("ch1", :stderr, "data1")
17
-
18
- assert_raises(SystemExit) do
19
- @deployer.check_path(ssh, "/tmp/yads", "git clone git@repohost.com:myrepo.git .")
20
- end
21
- end
22
-
23
- def test_check_path
24
- ssh = mock
25
- ssh.expects(:exec).with("cd /tmp/yads/.git").yields("ch", :stderr, "data")
26
- ssh.expects(:exec).with("git clone git@repohost.com:myrepo.git .").yields("ch1", :stdout, "data1")
27
- ssh.expects(:exec).with("cd /tmp/yads")
28
- ssh.expects(:loop)
29
-
30
- @deployer.check_path(ssh, "/tmp/yads", "git clone git@repohost.com:myrepo.git .")
31
- end
32
-
33
- def test_load_not_found_config_file
34
- assert_raises(Yads::ConfigNotFound) do
35
- Dir.chdir("/tmp") do
36
- @deployer.deploy
37
- end
38
- end
39
- end
40
-
41
- def test_load_config_file
42
- Dir.chdir(File.expand_path("../fixtures", __FILE__)) do
43
- ssh = mock
44
- ssh.expects(:exec).with("cd /tmp/yads && touch test")
45
- ssh.expects(:loop)
46
-
47
- @deployer.expects(:check_path).with(ssh)
48
- Net::SSH.expects(:start).with("rafaelss.com", "deploy", :forward_agent => true).yields(ssh)
49
-
50
- @deployer.deploy
51
- end
52
- end
53
- end