karo 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of karo might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 661301b756abdfa7df216b4c5f887524d90059dd
4
- data.tar.gz: 41b21803c8685a67fa3b3ab022e1373c4dda0cbf
3
+ metadata.gz: 742fafe45e1d1395f8f579a88b3fb4c537481c91
4
+ data.tar.gz: c85269a286f75601dfeb54083bc2bad8319b8a2a
5
5
  SHA512:
6
- metadata.gz: d33e07d1eca2b3743834b7c7c1a727097ed306f7eeb2f5c3e8a99eb3461693302a81020324900dbee6fefbdbcfb518fb5dff95cf837f0ee9930b30b96457bebe
7
- data.tar.gz: 45a8b1d2c40f93ebf045de657080c5c5e4b1b922fb83ee01aa5b6ce33872870d1dc6ca21a693a26bac0499495323daa20f176ee11122321f6f1b2e36079175ad
6
+ metadata.gz: 90bddb90a979c4a9cf146197f04c62d8839f1f1c73e3e89cc2afc776ad10d3820349fdbdd4ae32a76c927fe786b922c7f521598ede759234972be9c25955c4a2
7
+ data.tar.gz: 46b8df075a2839bd684d6879aa7c5244a1cb1715d07c3e6cae22c6fc68f958b7d3fc2dd74a3f95bc2d17e4611b720d4a38ed661744668263dfda30a625b5490e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.4.0
4
+
5
+ ### Features
6
+
7
+ - Added command 'command' to supercede 'on' command and deprecated 'on'
8
+ - Added options to store custom commands for an environment within .karo.yml file
9
+
3
10
  ## v1.3.0
4
11
 
5
12
  ### Features
data/lib/karo/cli.rb CHANGED
@@ -8,29 +8,29 @@ require 'ap'
8
8
 
9
9
  module Karo
10
10
 
11
- class CLI < Thor
11
+ class CLI < Thor
12
12
 
13
- include Thor::Actions
13
+ include Thor::Actions
14
14
 
15
- class_option :config_file, type: :string, default: Config.default_file_name,
16
- aliases: "-c", desc: "name of the file containing server configuration"
17
- class_option :environment, aliases: "-e", desc: "server environment", default: "production"
15
+ class_option :config_file, type: :string, default: Config.default_file_name,
16
+ aliases: "-c", desc: "name of the file containing server configuration"
17
+ class_option :environment, aliases: "-e", desc: "server environment", default: "production"
18
18
 
19
- desc "log", "displays server log for a given environment"
20
- def log(name="")
21
- configuration = Config.load_configuration(options)
19
+ desc "log", "displays server log for a given environment"
20
+ def log(name="")
21
+ configuration = Config.load_configuration(options)
22
22
 
23
- path = File.join(configuration["path"], "shared/log/#{options["environment"]}.log")
24
- ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
23
+ path = File.join(configuration["path"], "shared/log/#{options["environment"]}.log")
24
+ ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
25
25
 
26
- if name.eql?("")
27
- cmd = "tail -f #{path}"
28
- else
29
- cmd = "tail #{path} | grep -A 10 -B 10 #{name}"
30
- end
26
+ if name.eql?("")
27
+ cmd = "tail -f #{path}"
28
+ else
29
+ cmd = "tail #{path} | grep -A 10 -B 10 #{name}"
30
+ end
31
31
 
32
- system "#{ssh} '#{cmd}'"
33
- end
32
+ system "#{ssh} '#{cmd}'"
33
+ end
34
34
 
35
35
  desc "cache [search, remove]", "find or clears a specific or all cache from shared/cache directory on the server"
36
36
  subcommand "cache", Cache
@@ -41,68 +41,130 @@ module Karo
41
41
  desc "db [pull, push]", "syncs MySQL database between server and localhost"
42
42
  subcommand "db", Db
43
43
 
44
- desc "config", "displays server configuration stored in a config file"
45
- def config
46
- configuration = Config.load_configuration(options)
47
-
48
- ap configuration if configuration
49
- end
50
-
51
- def self.source_root
52
- File.dirname(__FILE__)
53
- end
54
-
55
- desc "generate", "generate a sample configuration file to be used by karo [default is .karo.yml]"
56
- def generate
57
- config_file = File.expand_path(options[:config_file])
58
- copy_file 'templates/karo.yml', config_file
59
- end
60
-
61
- desc "ssh", "open ssh console for a given server environment"
62
- def ssh
63
- configuration = Config.load_configuration(options)
64
-
65
- path = File.join(configuration["path"], "current")
66
- ssh = "ssh #{configuration["user"]}@#{configuration["host"]} -t"
67
- cmd = "cd #{path} && $SHELL"
68
- system "#{ssh} '#{cmd}'"
69
- end
70
-
71
- desc "console", "open rails console for a given server environment"
72
- def console
73
- configuration = Config.load_configuration(options)
74
-
75
- path = File.join(configuration["path"], "current")
76
- ssh = "ssh #{configuration["user"]}@#{configuration["host"]} -t"
77
- cmd = "cd #{path} && bundle exec rails console #{options[:environment]}"
78
- system "#{ssh} '#{cmd}'"
79
- end
80
-
81
- desc "top", "run top command on a given server environment"
82
- def top
83
- configuration = Config.load_configuration(options)
84
-
85
- path = File.join(configuration["path"], "current")
86
- ssh = "ssh #{configuration["user"]}@#{configuration["host"]} -t"
87
- cmd = "top"
88
- system "#{ssh} '#{cmd}'"
89
- end
90
-
91
- desc "on", "run any command within a given server environment"
92
- def on(*tokens)
93
- configuration = Config.load_configuration(options)
94
-
95
- path = File.join(configuration["path"], "current")
96
- ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
97
- cmd = tokens.join(" ")
98
- system "#{ssh} '#{cmd}'"
99
- end
100
-
101
- desc "version", "displays karo's current version"
102
- def version
103
- say Karo::VERSION
104
- end
105
-
106
- end
44
+ desc "config", "displays server configuration stored in a config file"
45
+ def config
46
+ configuration = Config.load_configuration(options)
47
+
48
+ ap configuration if configuration
49
+ end
50
+
51
+ def self.source_root
52
+ File.dirname(__FILE__)
53
+ end
54
+
55
+ desc "generate", "generate a sample configuration file to be used by karo [default is .karo.yml]"
56
+ def generate
57
+ config_file = File.expand_path(options[:config_file])
58
+ copy_file 'templates/karo.yml', config_file
59
+ end
60
+
61
+ desc "ssh", "open ssh console for a given server environment"
62
+ def ssh
63
+ configuration = Config.load_configuration(options)
64
+
65
+ path = File.join(configuration["path"], "current")
66
+ ssh = "ssh #{configuration["user"]}@#{configuration["host"]} -t"
67
+ cmd = "cd #{path} && $SHELL"
68
+ system "#{ssh} '#{cmd}'"
69
+ end
70
+
71
+ desc "console", "open rails console for a given server environment"
72
+ def console
73
+ configuration = Config.load_configuration(options)
74
+
75
+ path = File.join(configuration["path"], "current")
76
+ ssh = "ssh #{configuration["user"]}@#{configuration["host"]} -t"
77
+ cmd = "cd #{path} && bundle exec rails console #{options[:environment]}"
78
+ system "#{ssh} '#{cmd}'"
79
+ end
80
+
81
+ desc "command [COMMAND]", "run any command within a given server environment"
82
+ method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
83
+ type: :boolean, default: true
84
+ long_desc <<-LONGDESC
85
+ `karo command [command]` or `karo cmd [command]`
86
+
87
+ will run the [COMMAND] passed on the server.
88
+
89
+ You can optionally pass --no-tty to disable ssh force pseudo-tty allocation
90
+
91
+ e.g. Display list of files on the staging server
92
+
93
+ > $ karo command ls -e staging --no-tty
94
+
95
+ CHANGELOG.md Gemfile.lock README.md
96
+
97
+ e.g. Run top command on the production server
98
+
99
+ > $ karo command top
100
+
101
+ > top - 17:14:06 up 219 days, 11:30, 1 user, load average: 0.28, 0.49, 0.47
102
+
103
+ You can also store custom commands for a given environment in the configuration file
104
+
105
+ e.g. .karo.yml
106
+
107
+ production:
108
+
109
+ --host: example.com
110
+
111
+ --user: deploy
112
+
113
+ --path: /data/app_name
114
+
115
+ --commands:
116
+
117
+ ----memory: watch vmstat -sSM
118
+
119
+ ----top_5_memory: ps aux | sort -nk +4 | tail
120
+
121
+ > $ karo cmd memory
122
+
123
+ > Every 2.0s: vmstat -sSM Tue Jul 2 17:18:16 2013
124
+
125
+ > 35840140 total memory
126
+
127
+ > 35308456 used memory
128
+
129
+ > 25224800 active memory
130
+ LONGDESC
131
+ def command(cmd)
132
+ configuration = Config.load_configuration(options)
133
+
134
+ ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
135
+
136
+ # Forces pseudo-tty allocation
137
+ ssh << " -t" if options[:tty]
138
+
139
+ if configuration["commands"] && configuration["commands"][cmd]
140
+ cmd = configuration["commands"][cmd]
141
+ end
142
+
143
+ system "#{ssh} '#{cmd}'"
144
+ end
145
+ map cmd: :command
146
+
147
+ desc "on [COMMAND]", "run any command within a given server environment"
148
+ method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
149
+ type: :boolean, default: true
150
+ def on(cmd)
151
+ say "Deprecated and will be removed in version 2.0", :yellow
152
+ say "Please use 'command' instead", :yellow
153
+ invoke :command
154
+ end
155
+
156
+ desc "top", "run top command on a given server environment"
157
+ method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
158
+ type: :boolean, default: true
159
+ def top
160
+ invoke :command, ["top"]
161
+ end
162
+
163
+ desc "version", "displays karo's current version"
164
+ def version
165
+ say Karo::VERSION
166
+ end
167
+
168
+ end
107
169
 
108
170
  end
data/lib/karo/config.rb CHANGED
@@ -22,7 +22,9 @@ module Karo
22
22
  configuration
23
23
  end
24
24
  rescue Karo::NoConfigFileFoundError
25
- raise Thor::Error, "Please make sure that this configuration file exists? '#{config_file}'"
25
+ puts "You can use 'karo generate' to generate a skeleton .karo.yml file"
26
+ puts "Please make sure that this configuration file exists? '#{config_file}'"
27
+ raise Thor::Error, "and run the command again"
26
28
  end
27
29
  end
28
30
 
@@ -2,7 +2,12 @@ production:
2
2
  host: example.com
3
3
  user: deploy
4
4
  path: /data/app_name
5
+ commands:
6
+ memory: watch vmstat -sSM
7
+ top_5_memory: ps aux | sort -nk +4 | tail
5
8
  staging:
6
9
  host: example.com
7
10
  user: deploy
8
11
  path: /data/app_name
12
+ commands:
13
+ memory: vmstat -sSM
data/lib/karo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Karo
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: karo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rahul Trikha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-02 00:00:00.000000000 Z
11
+ date: 2013-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry