solutious-rudy 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +20 -6
- data/README.rdoc +3 -3
- data/Rudyfile +27 -41
- data/bin/rudy +8 -3
- data/lib/rudy.rb +2 -2
- data/lib/rudy/cli/routines.rb +4 -20
- data/lib/rudy/config.rb +1 -0
- data/lib/rudy/config/objects.rb +29 -33
- data/lib/rudy/huxtable.rb +9 -1
- data/lib/rudy/routines.rb +121 -104
- data/lib/rudy/routines/helper.rb +26 -5
- data/lib/rudy/routines/helpers/scripthelper.rb +56 -31
- data/lib/rudy/routines/helpers/userhelper.rb +2 -2
- data/lib/rudy/routines/passthrough.rb +11 -11
- data/lib/rudy/routines/reboot.rb +1 -1
- data/lib/rudy/routines/startup.rb +1 -1
- data/rudy.gemspec +5 -16
- metadata +4 -24
- data/examples/README.md +0 -10
- data/examples/debian-sinatra-passenger/commands.rb +0 -19
- data/examples/debian-sinatra-passenger/machines.rb +0 -32
- data/examples/debian-sinatra-passenger/routines.rb +0 -30
- data/examples/debian-sinatra-thin/commands.rb +0 -17
- data/examples/debian-sinatra-thin/machines.rb +0 -35
- data/examples/debian-sinatra-thin/routines.rb +0 -72
- data/lib/rudy/scm.rb +0 -75
- data/lib/rudy/scm/git.rb +0 -217
- data/lib/rudy/scm/svn.rb +0 -110
data/lib/rudy/scm/git.rb
DELETED
@@ -1,217 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
|
5
|
-
module Rudy
|
6
|
-
module SCM
|
7
|
-
class GIT
|
8
|
-
require 'grit'
|
9
|
-
include Rudy::SCM::ObjectBase
|
10
|
-
include Grit
|
11
|
-
|
12
|
-
attr_accessor :base_uri
|
13
|
-
attr_accessor :remote
|
14
|
-
attr_accessor :branch
|
15
|
-
attr_reader :repo
|
16
|
-
attr_reader :rbox
|
17
|
-
attr_reader :rtag
|
18
|
-
attr_reader :user
|
19
|
-
attr_reader :pkey
|
20
|
-
attr_reader :changes
|
21
|
-
|
22
|
-
# * +args+ a hash of params from the git block in the routines config
|
23
|
-
#
|
24
|
-
def initialize(args={})
|
25
|
-
args = {
|
26
|
-
:privatekey => nil,
|
27
|
-
:remote => :origin,
|
28
|
-
:branch => :master,
|
29
|
-
:user => :root,
|
30
|
-
:changes => :enforce,
|
31
|
-
:path => nil
|
32
|
-
}.merge(args)
|
33
|
-
@remote, @branch, @path = args[:remote], args[:branch], args[:path]
|
34
|
-
@user, @pkey, @changes = args[:user], args[:privatekey], args[:changes]
|
35
|
-
@repo = Repo.new(Dir.pwd) if GIT.working_copy?
|
36
|
-
end
|
37
|
-
|
38
|
-
def engine; :git; end
|
39
|
-
|
40
|
-
def liner_note
|
41
|
-
"%-40s (git:%s:%s)" % [@rtag, @remote, @branch]
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_release(username=nil, msg=nil)
|
45
|
-
@rtag = find_next_rtag(username)
|
46
|
-
msg ||= 'Another Release by Rudy!'
|
47
|
-
msg.tr!("'", "''")
|
48
|
-
ret = Rye.shell(:git, "tag", @rtag) # Use annotated? -a -m '#{msg}'
|
49
|
-
raise ret.stderr.join($/) if ret.exit_code > 0
|
50
|
-
ret = Rye.shell(:git, "push") if @remote
|
51
|
-
raise ret.stderr.join($/) if ret.exit_code > 0
|
52
|
-
ret = Rye.shell(:git, "push #{@remote} #{rtag}") if @remote
|
53
|
-
raise ret.stderr.join($/) if ret.exit_code > 0
|
54
|
-
@rtag
|
55
|
-
end
|
56
|
-
|
57
|
-
# rel-2009-03-05-user-rev
|
58
|
-
def find_next_rtag(username=nil)
|
59
|
-
now = Time.now
|
60
|
-
mon = now.mon.to_s.rjust(2, '0')
|
61
|
-
day = now.day.to_s.rjust(2, '0')
|
62
|
-
rev = "01"
|
63
|
-
criteria = ['rel', now.year, mon, day, rev]
|
64
|
-
criteria.insert(-2, username) if username
|
65
|
-
rev.succ! while valid_rtag?(criteria.join(Rudy::DELIM)) && rev.to_i < 50
|
66
|
-
raise TooManyTags if rev.to_i >= 50
|
67
|
-
criteria.join(Rudy::DELIM)
|
68
|
-
end
|
69
|
-
|
70
|
-
def delete_rtag(rtag=nil)
|
71
|
-
rtag ||= @rtag
|
72
|
-
ret = trap_rbox_errors { Rye.shell(:git, 'tag', :d, rtag) }
|
73
|
-
raise ret.stderr.join($/) if ret.exit_code > 0 # TODO: retest
|
74
|
-
# Equivalent to: "git push origin :tag-name" which deletes a remote tag
|
75
|
-
ret = trap_rbox_errors { Rye.shell(:git, "push #{@remote} :#{rtag}") } if @remote
|
76
|
-
raise ret.stderr.join($/) if ret.exit_code > 0
|
77
|
-
true
|
78
|
-
end
|
79
|
-
|
80
|
-
def create_remote_checkout(rbox)
|
81
|
-
|
82
|
-
# Make sure the directory above the clone path exists
|
83
|
-
# and that it's owned by the request user.
|
84
|
-
rbox.mkdir(:p, File.dirname(@path))
|
85
|
-
rbox.chown(@user, File.dirname(@path))
|
86
|
-
|
87
|
-
begin
|
88
|
-
original_user = rbox.user
|
89
|
-
rbox.switch_user(@user)
|
90
|
-
|
91
|
-
if @pkey
|
92
|
-
# Try when debugging: ssh -vi path/2/pkey git@github.com
|
93
|
-
key = File.basename(@pkey)
|
94
|
-
homedir = rbox.getenv['HOME']
|
95
|
-
rbox.mkdir(:p, :m, '700', '.ssh') rescue nil # :p says keep quiet if it exists
|
96
|
-
if rbox.file_exists?(".ssh/#{key}")
|
97
|
-
puts " Remote private key #{key} already exists".colour(:red)
|
98
|
-
else
|
99
|
-
rbox.upload(@pkey, ".ssh/#{key}")
|
100
|
-
end
|
101
|
-
|
102
|
-
## NOTE: The following are two attempts at telling git which
|
103
|
-
## private key to use. Both fail. The only thing I could get
|
104
|
-
## to work is modifying the ~/.ssh/config file.
|
105
|
-
##
|
106
|
-
## This runs fine, but "git clone" doesn't care.
|
107
|
-
## git config --global --replace-all http.sslKey /home/delano/.ssh/id_rsa
|
108
|
-
## rbox.git('config', '--global', '--replace-all', 'http.sslKey', "#{homedir}/.ssh/#{key}")
|
109
|
-
##
|
110
|
-
## "git clone" doesn't care about this either. Note that both these
|
111
|
-
## config attempts come directly from the git-config man page:
|
112
|
-
## http://www.kernel.org/pub/software/scm/git/docs/git-config.html
|
113
|
-
## export GIT_SSL_KEY=/home/delano/.ssh/id_rsa
|
114
|
-
## rbox.setenv("GIT_SSL_KEY", "#{homedir}/.ssh/#{key}")
|
115
|
-
|
116
|
-
if rbox.file_exists?('.ssh/config')
|
117
|
-
rbox.cp('.ssh/config', ".ssh/config-previous")
|
118
|
-
ssh_config = rbox.download('.ssh/config')
|
119
|
-
end
|
120
|
-
|
121
|
-
ssh_config ||= StringIO.new
|
122
|
-
ssh_config.puts $/, "IdentityFile #{homedir}/.ssh/#{key}"
|
123
|
-
puts " Adding IdentityFile #{key} to #{homedir}/.ssh/config"
|
124
|
-
|
125
|
-
rbox.upload(ssh_config, '.ssh/config')
|
126
|
-
rbox.chmod('0600', '.ssh/config')
|
127
|
-
|
128
|
-
end
|
129
|
-
|
130
|
-
# We need to add the host keys to the user's known_hosts file
|
131
|
-
# to prevent the git commands from failing when it raises the
|
132
|
-
# "Host key verification failed." messsage.
|
133
|
-
if rbox.file_exists?('.ssh/known_hosts')
|
134
|
-
rbox.cp('.ssh/known_hosts', ".ssh/known_hosts-previous")
|
135
|
-
known_hosts = rbox.download('.ssh/known_hosts')
|
136
|
-
end
|
137
|
-
known_hosts ||= StringIO.new
|
138
|
-
remote = get_remote_uri
|
139
|
-
host = URI.parse(remote).host rescue nil
|
140
|
-
host ||= remote.scan(/\A.+?@(.+?)\:/).flatten.first
|
141
|
-
known_hosts.puts $/, Rye.remote_host_keys(host)
|
142
|
-
puts " Adding host key for #{host} to .ssh/known_hosts"
|
143
|
-
|
144
|
-
rbox.upload(known_hosts, '.ssh/known_hosts')
|
145
|
-
rbox.chmod('0600', '.ssh/known_hosts')
|
146
|
-
|
147
|
-
trap_rbox_errors {
|
148
|
-
rbox.git('clone', get_remote_uri, @path)
|
149
|
-
}
|
150
|
-
rbox.cd(@path)
|
151
|
-
trap_rbox_errors {
|
152
|
-
rbox.git('checkout', :b, @rtag)
|
153
|
-
}
|
154
|
-
rescue Rye::CommandError => ex
|
155
|
-
puts ex.message
|
156
|
-
ensure
|
157
|
-
# Return to the original user and directory
|
158
|
-
rbox.switch_user(original_user)
|
159
|
-
rbox.cd
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
|
165
|
-
def get_remote_uri
|
166
|
-
ret = Rye.shell(:git, "config", "remote.#{@remote}.url")
|
167
|
-
ret.stdout.first
|
168
|
-
end
|
169
|
-
|
170
|
-
# Check if the given remote is valid.
|
171
|
-
#def has_remote?(remote)
|
172
|
-
# success = false
|
173
|
-
# (@repo.remotes || []).each do |r|
|
174
|
-
# end
|
175
|
-
# success
|
176
|
-
#end
|
177
|
-
|
178
|
-
def valid_rtag?(tag)
|
179
|
-
# git tag -l tagname returns a 0 exit code and stdout is empty
|
180
|
-
# when a tag does not exit. When it does exist, the exit code
|
181
|
-
# is 0 and stdout contains the tagname.
|
182
|
-
ret = Rye.shell(:git, 'tag', :l, tag)
|
183
|
-
# change :l to :d for quick deleting above and return true
|
184
|
-
# OR: just change to :d to always recreate the same tag
|
185
|
-
(ret.exit_code == 0 && ret.stdout.to_s == tag)
|
186
|
-
end
|
187
|
-
|
188
|
-
# Are all local changes committed?
|
189
|
-
def self.clean_working_copy?(path=Dir.pwd)
|
190
|
-
Rye.shell(:git, 'diff').stdout == []
|
191
|
-
end
|
192
|
-
def clean_working_copy?; GIT.clean_working_copy?; end
|
193
|
-
|
194
|
-
def self.working_copy?(path=Dir.pwd)
|
195
|
-
(File.exists?(File.join(path, '.git')))
|
196
|
-
end
|
197
|
-
def working_copy?; GIT.working_copy?; end
|
198
|
-
|
199
|
-
def raise_early_exceptions
|
200
|
-
raise NotAWorkingCopy, :git unless working_copy?
|
201
|
-
raise DirtyWorkingCopy, :git unless @changes.to_s == 'ignore' || clean_working_copy?
|
202
|
-
raise NoRemoteURI, "remote.#{@remote}.url not set" if get_remote_uri.nil?
|
203
|
-
raise NoRemotePath, :git if @path.nil?
|
204
|
-
raise PrivateKeyNotFound, @pkey if @pkey && !File.exists?(@pkey)
|
205
|
-
find_next_rtag # will raise exception is there's a problem
|
206
|
-
|
207
|
-
# We can't check stuff that requires access to the machine b/c the
|
208
|
-
# machine may not be running yet. These include:
|
209
|
-
# * Remote checkout path already exists
|
210
|
-
# * No git available
|
211
|
-
# ...
|
212
|
-
# If create_remote_checkout should fail, it should print a message
|
213
|
-
# about the release that was created and how to install it manually
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
data/lib/rudy/scm/svn.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
module Rudy
|
5
|
-
module SCM
|
6
|
-
class SVN
|
7
|
-
attr_accessor :base_uri
|
8
|
-
|
9
|
-
attr_reader :changes
|
10
|
-
|
11
|
-
def initialize(args={})
|
12
|
-
args = {
|
13
|
-
:privatekey => nil,
|
14
|
-
:base_uri => nil,
|
15
|
-
:user => :root,
|
16
|
-
:changes => :enforce,
|
17
|
-
:path => nil
|
18
|
-
}.merge(args)
|
19
|
-
@base_uri, @path = args[:base_uri], args[:path]
|
20
|
-
@user, @pkey, @changes = args[:user], args[:privatekey], args[:changes]
|
21
|
-
end
|
22
|
-
|
23
|
-
def engine; :svn; end
|
24
|
-
|
25
|
-
def liner_note
|
26
|
-
"%-40s (svn:%s:%s)" % [@rtag, @base_uri, @branch]
|
27
|
-
end
|
28
|
-
|
29
|
-
def create_release(username=nil, msg=nil)
|
30
|
-
local_uri, local_revision = local_info
|
31
|
-
rtag = find_next_rtag(username)
|
32
|
-
release_uri = "#{@base_uri}/#{rtag}"
|
33
|
-
msg ||= 'Another Release by Rudy!'
|
34
|
-
msg.tr!("'", "\\'")
|
35
|
-
cmd = "svn copy -m '#{msg}' #{local_uri} #{release_uri}"
|
36
|
-
|
37
|
-
`#{cmd} 2>&1`
|
38
|
-
|
39
|
-
release_uri
|
40
|
-
end
|
41
|
-
|
42
|
-
def switch_working_copy(tag)
|
43
|
-
raise "Invalid release tag (#{tag})." unless valid_rtag?(tag)
|
44
|
-
`svn switch #{tag}`
|
45
|
-
end
|
46
|
-
|
47
|
-
# rel-2009-03-05-user-rev
|
48
|
-
def find_next_rtag(username=nil)
|
49
|
-
now = Time.now
|
50
|
-
mon = now.mon.to_s.rjust(2, '0')
|
51
|
-
day = now.day.to_s.rjust(2, '0')
|
52
|
-
rev = "01"
|
53
|
-
criteria = ['rel', now.year, mon, day, rev]
|
54
|
-
criteria.insert(-2, username) if username
|
55
|
-
tag = criteria.join(Rudy::DELIM)
|
56
|
-
# Keep incrementing the revision number until we find the next one.
|
57
|
-
tag.succ! while (valid_rtag?("#{@base_uri}/#{tag}"))
|
58
|
-
tag
|
59
|
-
end
|
60
|
-
|
61
|
-
def local_info
|
62
|
-
ret = Rye.shell(:svn, "info").join
|
63
|
-
# URL: http://some/uri/path
|
64
|
-
# Repository Root: http://some/uri
|
65
|
-
# Repository UUID: c5abe49d-53e4-4ea3-9314-89e1e25aa7e1
|
66
|
-
# Revision: 921
|
67
|
-
ret.scan(/URL: (http:.+?)\s*\n.+Revision: (\d+)/m).flatten
|
68
|
-
end
|
69
|
-
|
70
|
-
def working_copy?(path)
|
71
|
-
(File.exists?(File.join(path, '.svn')))
|
72
|
-
end
|
73
|
-
|
74
|
-
def valid_rtag?(uri)
|
75
|
-
ret = `svn info #{uri} 2>&1` || '' # Valid SVN URIs will return some info
|
76
|
-
(ret =~ /Repository UUID/) ? true : false
|
77
|
-
end
|
78
|
-
|
79
|
-
# Are all local changes committed?
|
80
|
-
def self.clean_working_copy?(path=Dir.pwd)
|
81
|
-
Rye.shell(:svn, 'diff', '.').stdout == []
|
82
|
-
end
|
83
|
-
def clean_working_copy?; SVN.clean_working_copy?; end
|
84
|
-
|
85
|
-
def self.working_copy?(path=Dir.pwd)
|
86
|
-
(File.exists?(File.join(path, '.svn')))
|
87
|
-
end
|
88
|
-
def working_copy?; SVN.working_copy?; end
|
89
|
-
|
90
|
-
|
91
|
-
def raise_early_exceptions
|
92
|
-
raise NotAWorkingCopy, :svn unless working_copy?
|
93
|
-
raise DirtyWorkingCopy, :svn unless @changes.to_s == 'ignore' || clean_working_copy?
|
94
|
-
#raise NoRemoteURI, "remote.#{@remote}.url not set" if get_remote_uri.nil?
|
95
|
-
raise NoRemotePath, :svn if @path.nil?
|
96
|
-
raise PrivateKeyNotFound, @pkey if @pkey && !File.exists?(@pkey)
|
97
|
-
find_next_rtag # will raise exception is there's a problem
|
98
|
-
|
99
|
-
# We can't check stuff that requires access to the machine b/c the
|
100
|
-
# machine may not be running yet. These include:
|
101
|
-
# * Remote checkout path already exists
|
102
|
-
# * No git available
|
103
|
-
# ...
|
104
|
-
# If create_remote_checkout should fail, it should print a message
|
105
|
-
# about the release that was created and how to install it manually
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|