yads 0.0.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/bin/yads +4 -0
- data/examples/deploy.yml +12 -0
- data/lib/yads/version.rb +3 -0
- data/lib/yads.rb +54 -0
- data/test/fixtures/config/deploy.yml +7 -0
- data/test/test_yads.rb +53 -0
- data/yads.gemspec +23 -0
- metadata +100 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## Yads
|
2
|
+
|
3
|
+
Yet Another Deploy Solution is a simple gem to deploy applications using a single YAML file.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
group :deploy do
|
8
|
+
gem "yads"
|
9
|
+
end
|
10
|
+
|
11
|
+
and
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
- Create the [deploy.yml](http://github.com/rafaelss/yads/blob/examples/deploy.yml) file inside config directory.
|
18
|
+
|
19
|
+
- Configure deploy.yml
|
20
|
+
|
21
|
+
- Run `yads` on root directory
|
22
|
+
|
23
|
+
Done. Your application is deployed.
|
24
|
+
|
25
|
+
## TODO
|
26
|
+
|
27
|
+
- Let run commands by name: `yads migrate && yads restart` or `yads migrate restart` like rake tasks
|
28
|
+
- Improve test suite
|
29
|
+
|
30
|
+
## Maintainer
|
31
|
+
|
32
|
+
* Rafael Souza - [rafaelss.com](http://rafaelss.com)
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
(The MIT License)
|
37
|
+
|
38
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/yads
ADDED
data/examples/deploy.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
host: example.org
|
2
|
+
user: username
|
3
|
+
forward_agent: true/false
|
4
|
+
|
5
|
+
path: /path/on/remote/server
|
6
|
+
commands:
|
7
|
+
clone: git clone --depth 1 git@repohost.com:myproject.git . # mandatory, other commands below are optional
|
8
|
+
reset: git reset --hard
|
9
|
+
pull: git pull origin master
|
10
|
+
bundle: bundle install --deployment --binstubs --without development test
|
11
|
+
migrate: ENV=production bin/rake db:migrate --silent
|
12
|
+
restart: touch tmp/restart.txt
|
data/lib/yads/version.rb
ADDED
data/lib/yads.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "net/ssh"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
module Yads
|
5
|
+
|
6
|
+
class ConfigNotFound < Errno::ENOENT; end
|
7
|
+
|
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("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
|
54
|
+
end
|
data/test/test_yads.rb
ADDED
@@ -0,0 +1,53 @@
|
|
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
|
data/yads.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yads/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yads"
|
7
|
+
s.version = Yads::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rafael Souza"]
|
10
|
+
s.email = ["me@rafaelss.com"]
|
11
|
+
s.homepage = "http://github.com/rafaelss/yads"
|
12
|
+
s.summary = %q{Deploy your code using a YAML file}
|
13
|
+
s.description = %q{Simple deployment tool that uses a single YAML file to put your code live}
|
14
|
+
|
15
|
+
s.add_runtime_dependency "net-ssh", "~> 2.1.0"
|
16
|
+
s.add_development_dependency "minitest", "~> 2.0.2"
|
17
|
+
s.add_development_dependency "mocha", "~> 0.9.10"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yads
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.0.3.pre
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rafael Souza
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-04 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: net-ssh
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.1.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.0.2
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: mocha
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.10
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Simple deployment tool that uses a single YAML file to put your code live
|
50
|
+
email:
|
51
|
+
- me@rafaelss.com
|
52
|
+
executables:
|
53
|
+
- yads
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- bin/yads
|
64
|
+
- examples/deploy.yml
|
65
|
+
- lib/yads.rb
|
66
|
+
- lib/yads/version.rb
|
67
|
+
- test/fixtures/config/deploy.yml
|
68
|
+
- test/test_yads.rb
|
69
|
+
- yads.gemspec
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/rafaelss/yads
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.3.1
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.6.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Deploy your code using a YAML file
|
98
|
+
test_files:
|
99
|
+
- test/fixtures/config/deploy.yml
|
100
|
+
- test/test_yads.rb
|