do 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md ADDED
@@ -0,0 +1,6 @@
1
+ ## 0.0.2 - August 9, 2011
2
+
3
+ * Added `doit do:setup` task that generate a template in `~./do/dorc`
4
+ * Improved support of plugins
5
+ * Added `doit download[http://raw.github...]` task which download and update for you a given rake task
6
+ * Improved output messages
data/README.md CHANGED
@@ -2,35 +2,37 @@
2
2
 
3
3
  DO is a thin framework useful to manage remote servers through ssh.
4
4
 
5
- There are many other alternative, once of them is [capistrano](https://github.com/capistrano/capistrano)
5
+ There are many other alternatives, once of them is
6
+ [capistrano](https://github.com/capistrano/capistrano).
6
7
 
7
8
  So why another one? Basically I need:
8
9
 
9
10
  * easy creation of my recipes
10
11
  * see perfectly what's happening on my remote servers
11
12
  * highly focus on smart actions, upload, download, sudo, replace.
12
- * manage more than one server each
13
- * use same behaviour for manage local tasks
13
+ * manage easily more than one server at same time
14
+ * use same syntax to manage local tasks
14
15
 
15
- ## Installation
16
+ ## DO - Installation and Setup
16
17
 
17
18
  ```sh
18
19
  $ sudo gem install do
19
- $ doit do:setup
20
+ $ doit setup # setup DO directory
21
+ $ doit -T # show DO tasks
20
22
  ```
21
23
 
22
- Now start to edit your `~/do/dorc` file and have fun!
24
+ Now you can edit your `~/.do/dorc` adding your **servers** or **plugins**.
23
25
 
24
- ## Files
26
+ ## DO - Files
25
27
 
26
28
  There are some way to generate **DO** tasks, you can:
27
29
 
28
- * Create a file called `Do` in your project directory
29
- * Create a file called `Dofile` in your project directory
30
- * Create `*.rake` files in `~/.do` directory, aka **home dir**
31
- * Create a file called `dorc` in `~/.do` directory
30
+ * Create a file called `Do` or `Dofile` in your project directory (_project wide_)
31
+ * Create `*.rake` files in `~/.do` directory (_system wide_)
32
+ * Create a file called `dorc` in `~/.do` directory (_system wide_)
32
33
 
33
- You can change your **do home directory** with:
34
+ You can change the *DO* home directory (default: `~/.do`) with these
35
+ commands:
34
36
 
35
37
  ```
36
38
  DO_PATH='/my/new/.do/path'
@@ -38,7 +40,9 @@ ENV['DO_PATH']='/my/new/.do/path'
38
40
  export DO_PATH='/my/new/.do/path'
39
41
  ```
40
42
 
41
- ## Features
43
+ In this guide we assume that your `DO_PATH` is `~/.do`.
44
+
45
+ ## DO - Features
42
46
 
43
47
  * Easily server logging
44
48
  * SSH connections
@@ -59,7 +63,7 @@ server.run 'uname', '-a'
59
63
  # root@srv1 ~ # uname -a
60
64
  # Linux srv1.lipsiasoft.net 2.6.18-194.32.1.el5 x86_64 x86_64 x86_64 GNU/Linux
61
65
 
62
- server.run 'mysqladmin -u root -p password 'oldone', 'newpassword'
66
+ server.run 'mysqladmin -u root -p password "oldone"', 'newpassword'
63
67
  # root@srv1 ~ # mysqladmin -u root -p password 'oldone'
64
68
  # Enter password: oldone
65
69
  # mysqladmin: connect to server at 'localhost' failed
@@ -119,29 +123,67 @@ server.wait
119
123
  # Press ENTER to continue...
120
124
  ```
121
125
 
126
+ ## DO - Plugins
127
+
128
+ DO, support plugins, you can manually add new one in your `~/.do/dorc`
129
+ with a simple line:
130
+
131
+ ```rb
132
+ plugin :vim, 'https://raw.github.com/DAddYE/.do/master/vim.rake'
133
+ ```
134
+
135
+ However we have a `doit` command for that:
136
+
137
+ ```sh
138
+ $ doit download[https://raw.github.com/DAddYE/.do/master/l.rake]
139
+ ```
140
+
141
+ This command add for you a new line in your `~/.do/dorc` and perform:
142
+
143
+ ```sh
144
+ $ doit plugin:vim
145
+ ```
146
+
147
+ which download and install in your `~/.do/dorc` directory a new rake
148
+ file.
149
+
150
+ Once this happen you are be able to see new tasks:
151
+
152
+ ```sh
153
+ $ doit -T
154
+
155
+ ************************************************************
156
+ * DO - IT! *
157
+ ************************************************************
158
+
159
+ doit plugin:vim # install vim plugin
160
+ doit setup # setup a working home directory
161
+ doit vim:configure # configure with a janus custom template
162
+ doit vim:install # install vim with python and ruby support
163
+ ```
164
+
122
165
  ## Scenario and examples
123
166
 
124
- I'm porting my custom recipes to do, you can found my dot files
125
- [here](https://github.com/daddye/.do)
167
+ I'm porting my custom recipes to *DO*, you can find my dot files
168
+ [here](https://github.com/daddye/.do).
126
169
 
127
- I've server config in `~/.do/dorc`:
170
+ Here servers definitions:
128
171
 
129
172
  ```rb
173
+ # ~/.do/dorc
130
174
  keys = %w(/keys/master.pem /keys/instances.pem /keys/stage.pem)
131
175
  server :sho0, 'sho0.lipsiasoft.biz', 'root', :keys => keys
132
176
  server :srv0, 'srv0.lipsiasoft.biz', 'root', :keys => keys
133
177
  server :srv1, 'srv1.lipsiasoft.biz', 'root', :keys => keys
134
178
  server :srv2, 'srv2.lipsiasoft.biz', 'root', :keys => keys
135
-
136
- plugin "configure-server", "https://raw.github.com/gist/112..."
137
179
  ```
138
180
 
139
- Then I've some recipes in my `~/.do` path where I do common tasks.
181
+ I've also some recipes in my `~/.do` path:
140
182
 
141
183
  ```rb
142
- # ~/.do/configure.
184
+ # ~/.do/configure.rake
143
185
  namespace :configure
144
- desc "upgrade rubygems and install usefull gems"
186
+ desc "upgrade rubygems and install useful gems"
145
187
  task :gems => :ree do
146
188
  run "gem update --system" if yes?("Do you want to update rubygems?")
147
189
  run "gem install rake"
@@ -174,7 +216,7 @@ namespace :configure
174
216
  ...
175
217
  ```
176
218
 
177
- I call those with:
219
+ I call these task with:
178
220
 
179
221
  ```sh
180
222
  $ doit configure:gems
@@ -182,8 +224,8 @@ $ doit configure:motd
182
224
  $ doit configure:mysql
183
225
  ```
184
226
 
185
- **NOTE** that like rake tasks you are be able to add prerequisites to
186
- any task, in this case:
227
+ **NOTE** like rake tasks you are be able to add prerequisites to
228
+ any task, ex:
187
229
 
188
230
  ```rb
189
231
  task :mysql => :yum do; ...; end
@@ -220,31 +262,33 @@ namespace :l do
220
262
  end
221
263
  ```
222
264
 
223
- When I need to setup a new project I do:
265
+ When I need to setup a new project:
224
266
 
225
267
  ``` sh
226
268
  $ doit l:setup
227
269
  $ doit l:commit # to make a fast commit and push
228
270
  ```
229
271
 
230
- As you can see define remote and local task is simple like making common
231
- rake tasks, infact this gem handle rake.
272
+ As you can see, define remote and local task, is simple like making
273
+ standard rake tasks. *DO* extend `Rake`.
232
274
 
233
- ## Filtering
275
+ ## DO - Filtering
234
276
 
235
- Sometimes you want to perform a task only on one or some servers:
277
+ Sometimes you want to perform a task only on some servers:
236
278
 
237
279
  ```sh
238
280
  $ doit configure:new --only-srv1 --only-srv2
239
281
  $ doit configure:new --except-srv1
240
282
  ```
241
283
 
242
- ## Awesome output
284
+ ## DO - Output (Awesome...)
243
285
 
244
- What I really need is a great understandable, colored output that clarify
286
+ What I really wanted was a great understandable, colored output that clarify
245
287
  me what's happen on my remote servers.
246
288
 
247
- ```
289
+ Here a example output of my tasks:
290
+
291
+ ```sh
248
292
  root@sho0 ~ # touch /root/.bashrc
249
293
  root@sho0 ~ # replace all in '/root/.bashrc'
250
294
  root@sho0 ~ # replace all in '/etc/motd'
data/Rakefile CHANGED
@@ -11,9 +11,12 @@ end
11
11
 
12
12
  desc "Bump version on github"
13
13
  task :bump do
14
- puts "\e[31mNothing to commit (working directory clean)\e[0m" and return unless `git status -s`.chomp == ""
15
- version = Bundler.load_gemspec(Dir[File.expand_path('../*.gemspec', __FILE__)].first).version
16
- sh "git add .; git commit -a -m \"Bump to version #{version}\""
14
+ if `git status -s`.chomp == ""
15
+ puts "\e[31mNothing to commit (working directory clean)\e[0m"
16
+ else
17
+ version = Bundler.load_gemspec(Dir[File.expand_path('../*.gemspec', __FILE__)].first).version
18
+ sh "git add .; git commit -a -m \"Bump to version #{version}\""
19
+ end
17
20
  end
18
21
 
19
22
  task :release => :bump
data/bin/doit CHANGED
@@ -14,7 +14,7 @@ ARGV.delete_if { |a| a =~ /--(only|except)/ }
14
14
 
15
15
  puts "\e[32m"
16
16
  puts "*" * 60
17
- puts "*" + "DO".center(58) + "*"
17
+ puts "*" + "DO - IT!".center(58) + "*"
18
18
  puts "*" * 60
19
19
  puts "\e[0m"
20
20
 
data/do.gemspec CHANGED
@@ -18,4 +18,8 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency "net-ssh", "~>2.1.4"
19
19
  gem.add_dependency "net-sftp", "~>2.0.5"
20
20
  gem.add_development_dependency "rspec"
21
+
22
+ gem.post_install_message = "\e[32m" + ("*" * 60) + "\n"
23
+ gem.post_install_message += "*" + "DO - IT! $ doit setup".center(58) + "*" + "\n"
24
+ gem.post_install_message += ("*" * 60) + "\n\e[0m"
21
25
  end
data/lib/do/commands.rb CHANGED
@@ -51,10 +51,11 @@ module DO
51
51
  # plugin "configuration", "https://gist.github.com/raw/xys.rake"
52
52
  #
53
53
  def plugin(name, repo)
54
- desc "Install #{name} plugin"
55
- local("plugin:#{name}" => "do:setup") do
54
+ desc "install #{name} plugin"
55
+ local("plugin:#{name}" => :setup) do
56
+ log "\e[36m## Installing plugin %s\e[0m" % name
56
57
  Dir.mkdir(DO_PATH) unless File.exist?(DO_PATH)
57
- sh "curl --location --progress-bar #{repo} > #{File.join(DO_PATH, name + '.rake')}"
58
+ sh "curl --location --progress-bar #{repo} > #{File.join(DO_PATH, '%s.rake' % name)}"
58
59
  end
59
60
  end
60
61
 
@@ -129,7 +130,7 @@ module DO
129
130
  ##
130
131
  # Log text under current_server if available
131
132
  #
132
- def log(text, new_line=true)
133
+ def log(text="", new_line=true)
133
134
  if current_server
134
135
  current_server.log(text, new_line)
135
136
  else
@@ -142,15 +143,4 @@ end # DO
142
143
 
143
144
  self.extend DO::Commands
144
145
 
145
- local :servers do
146
- servers_selected.replace(servers)
147
- end
148
-
149
- namespace :do do
150
- desc "setup a working home directory"
151
- local :setup do
152
- File.mkdir(DO_PATH) unless File.exist?(DO_PATH)
153
- sh 'touch %s' % File.join(DO_PATH, 'dorc')
154
- sh 'ln -s %s %s' % [File.join(DO_PATH, 'dorc'), File.expand_path("~/.dorc")]
155
- end
156
- end
146
+ load(File.expand_path('../common.rb', __FILE__))
data/lib/do/common.rb ADDED
@@ -0,0 +1,56 @@
1
+ ##
2
+ # Common tasks performed by doit
3
+ #
4
+
5
+ local :servers do
6
+ servers_selected.replace(servers)
7
+ end
8
+
9
+ local :download, [:recipe] => :setup do |t, options|
10
+ if options[:recipe]
11
+ name = File.basename(options[:recipe], '.rake')
12
+ rc = File.join(DO_PATH, 'dorc')
13
+ buf = File.read(rc)
14
+
15
+ if buf.include?(options[:recipe])
16
+ log "\e[31mYour '\e[1m%s\e[31m' already has the plugin '\e[1m%s\e[0m'" % [rc, options[:recipe]]
17
+ log "Please run: $ doit plugin:%s" % name
18
+ exit
19
+ else
20
+ plugin = "plugin :%s, '%s'\n" % [name, options[:recipe]]
21
+ File.open(rc, 'a') { |f| f.write plugin }
22
+ load(rc)
23
+ Rake::Task['plugin:%s' % name].invoke
24
+ end
25
+ else
26
+ log "\e[31mYou must provide a recipe path ex:\e[0m"
27
+ log
28
+ log " $ doit download[https://raw.github.com/DAddYE/.do/master/l.rake]"
29
+ log
30
+ end
31
+ end
32
+
33
+ desc "setup a working home directory"
34
+ local :setup do
35
+ File.mkdir(DO_PATH) unless File.exist?(DO_PATH)
36
+ hrc = File.expand_path("~/.dorc")
37
+ orc = File.join(DO_PATH, 'dorc')
38
+ unless File.exist?(orc)
39
+ template = <<-RUBY.gsub(/^ {6}/, '')
40
+ ##
41
+ # Server definitions
42
+ #
43
+ # keys = %w(/path/to/key1.pem /path/to/key2.pem)
44
+ # server :srv1, 'srv1.domain.local', 'root', :keys => keys
45
+ # server :srv2, 'srv2.domain.local', 'root', :keys => keys
46
+ #
47
+
48
+ ##
49
+ # Here my plugins
50
+ #
51
+ RUBY
52
+ File.open(orc, 'w') { |f| f.write template }
53
+ log "\e[36mGenerated template, now you can add your config to: '%s'\e[0m" % orc
54
+ end
55
+ sh 'ln -s %s %s' % [orc, hrc] unless File.exist?(hrc)
56
+ end
data/lib/do/server.rb CHANGED
@@ -39,7 +39,7 @@ module DO
39
39
  # ==== Examples:
40
40
  # DO::Server::LOG_FORMAT = "%s@%s$ %s"
41
41
  #
42
- def log(text, new_line=true)
42
+ def log(text="", new_line=true)
43
43
  text += "\n" if new_line && text[-1] != ?\n
44
44
  logger.print LOG_FORMAT % [user, name, text]
45
45
  end
data/lib/do/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DO
2
- VERSION = "0.0.1" unless defined?(DO::VERSION)
2
+ VERSION = "0.0.2" unless defined?(DO::VERSION)
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Davide D'Agostino
@@ -91,6 +91,7 @@ extra_rdoc_files: []
91
91
 
92
92
  files:
93
93
  - .gitignore
94
+ - CHANGES.md
94
95
  - Gemfile
95
96
  - README.md
96
97
  - Rakefile
@@ -98,10 +99,10 @@ files:
98
99
  - do.gemspec
99
100
  - lib/do.rb
100
101
  - lib/do/commands.rb
102
+ - lib/do/common.rb
101
103
  - lib/do/server.rb
102
104
  - lib/do/utils.rb
103
105
  - lib/do/version.rb
104
- - recipes/.servorc
105
106
  - spec/fixtures/sample
106
107
  - spec/server_spec.rb
107
108
  - spec/spec_helper.rb
@@ -109,7 +110,10 @@ has_rdoc: true
109
110
  homepage: https://github.com/daddye/do
110
111
  licenses: []
111
112
 
112
- post_install_message:
113
+ post_install_message: "\e[32m************************************************************\n\
114
+ * DO - IT! $ doit setup *\n\
115
+ ************************************************************\n\
116
+ \e[0m"
113
117
  rdoc_options: []
114
118
 
115
119
  require_paths:
data/recipes/.servorc DELETED
@@ -1,14 +0,0 @@
1
- keys = %w(/Developer/src/LipsiaSoft/lipsiahosting/lib/lipsiarec/recipes/servers/resources/keys/Lipsiasoft.pem)
2
- server :srv1, 'srv1.lipsiasoft.biz', 'root', :keys => keys
3
- server :srv2, 'srv2.lipsiasoft.biz', 'root', :keys => keys
4
-
5
- plugin "configure-server", "https://raw.github.com/gist/112..."
6
-
7
- namespace :status do
8
-
9
- desc "Show processes"
10
- task :ps do
11
- run "ps aux --sort -rss"
12
- wait
13
- end
14
- end