karo 2.1.1 → 2.1.2
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/karo/assets.rb +8 -20
- data/lib/karo/cache.rb +0 -4
- data/lib/karo/cli.rb +9 -23
- data/lib/karo/common.rb +29 -0
- data/lib/karo/db.rb +59 -59
- data/lib/karo/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57790c4a5e39d2f7216f9eacef0058efaca23650
|
4
|
+
data.tar.gz: 307d1ec8497c299eb3ca9acd9aa2c364b96079a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 010a486f89abd57065abf15d64ead832017dfdbe9ff6688e9afc52c619c33a2a72a8f10c02db4e5328c6f0d4a7b01ecb1fb1da0af30e3fbffdb24429a2079673
|
7
|
+
data.tar.gz: 5f4ca62a3594ec4312918014f20ce6d5ef4698ca8b42d95d50cfca0991d7d892dd5a588b593257e85f32185f38f203d8c410830370e31a209737191988bd6fe9
|
data/CHANGELOG.md
CHANGED
data/lib/karo/assets.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
|
-
require 'karo/
|
1
|
+
require 'karo/common'
|
2
2
|
require 'thor'
|
3
3
|
|
4
4
|
module Karo
|
5
5
|
|
6
6
|
class Assets < Thor
|
7
7
|
|
8
|
-
include
|
9
|
-
|
10
|
-
class_option :config_file, type: :string, default: Config.default_file_name,
|
11
|
-
aliases: "-c", desc: "name of the file containing server configuration"
|
12
|
-
class_option :environment, aliases: "-e", desc: "server environment", default: "production"
|
13
|
-
class_option :verbose, type: :boolean, lazy_default: true, aliases: "-v", desc: "verbose"
|
8
|
+
include Karo::Common
|
14
9
|
|
15
10
|
desc "pull", "syncs assets from server shared/system/dragonfly/<environment> directory into local system/dragonfly/development directory"
|
16
11
|
def pull
|
@@ -22,11 +17,9 @@ module Karo
|
|
22
17
|
path_server = File.join(configuration["path"], "shared/system/dragonfly/#{options[:environment]}")
|
23
18
|
|
24
19
|
host = "deploy@#{configuration["host"]}"
|
25
|
-
|
26
|
-
|
27
|
-
say cmd, :green if options[:verbose]
|
20
|
+
command = "rsync -az --progress #{host}:#{path_server}/ #{path_local}/"
|
28
21
|
|
29
|
-
|
22
|
+
run_it command, options[:verbose]
|
30
23
|
|
31
24
|
say "Assets sync complete", :green
|
32
25
|
end
|
@@ -44,17 +37,12 @@ module Karo
|
|
44
37
|
|
45
38
|
path_server = File.join(configuration["path"], "shared/system/dragonfly/#{options[:environment]}")
|
46
39
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if options[:verbose]
|
51
|
-
say cmd_1, :green
|
52
|
-
say cmd_2, :green
|
53
|
-
end
|
40
|
+
command_1 = "ssh #{host} 'mkdir -p #{path_server}'"
|
41
|
+
command_2 = "rsync -az --progress #{path_local}/ #{host}:#{path_server}/"
|
54
42
|
|
55
43
|
if yes?("Are you sure?", :yellow)
|
56
|
-
|
57
|
-
|
44
|
+
run_it command_1, options[:verbose]
|
45
|
+
run_it command_2, options[:verbose]
|
58
46
|
say "Assets sync complete", :green
|
59
47
|
else
|
60
48
|
say "Assets sync cancelled", :yellow
|
data/lib/karo/cache.rb
CHANGED
@@ -5,10 +5,6 @@ module Karo
|
|
5
5
|
|
6
6
|
class Cache < Thor
|
7
7
|
|
8
|
-
class_option :config_file, type: :string, default: Config.default_file_name,
|
9
|
-
aliases: "-c", desc: "name of the file containing server configuration"
|
10
|
-
class_option :environment, aliases: "-e", desc: "server environment", default: "production"
|
11
|
-
|
12
8
|
desc "search", "searches for any matching cache files from the shared/cache directory"
|
13
9
|
def search(name="")
|
14
10
|
configuration = Config.load_configuration(options)
|
data/lib/karo/cli.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
require 'karo/version'
|
2
|
-
require 'karo/
|
2
|
+
require 'karo/common'
|
3
3
|
require 'karo/assets'
|
4
4
|
require 'karo/cache'
|
5
5
|
require 'karo/db'
|
6
|
-
require 'thor'
|
7
6
|
require 'ap'
|
8
7
|
|
9
8
|
module Karo
|
10
9
|
|
11
10
|
class CLI < Thor
|
12
11
|
|
12
|
+
include Karo::Common
|
13
|
+
|
14
|
+
# FIXME: Duplicated in Karo::Common
|
15
|
+
# Is needed for the generate method
|
16
|
+
# Otherwise you get this error
|
17
|
+
# undefined method `source_paths_for_search' for Karo::CLI
|
13
18
|
include Thor::Actions
|
14
19
|
|
15
20
|
class_option :config_file, type: :string, default: Config.default_file_name,
|
@@ -23,7 +28,7 @@ module Karo
|
|
23
28
|
desc "assets [pull, push]", "syncs dragonfly assets between server shared/system/dragonfly/<environment> directory and local system/dragonfly/development directory"
|
24
29
|
subcommand "assets", Assets
|
25
30
|
|
26
|
-
desc "db [pull, push]", "syncs MySQL database between server and localhost"
|
31
|
+
desc "db [pull, push, console]", "syncs MySQL database between server and localhost"
|
27
32
|
subcommand "db", Db
|
28
33
|
|
29
34
|
desc "config", "displays server configuration stored in a config file"
|
@@ -144,7 +149,7 @@ module Karo
|
|
144
149
|
ssh << " -t" if options[:tty]
|
145
150
|
|
146
151
|
command = make_command configuration, "server", cmd, extras
|
147
|
-
run_it "#{ssh} #{command}", options[:verbose]
|
152
|
+
run_it "#{ssh} '#{command}'", options[:verbose]
|
148
153
|
end
|
149
154
|
map srv: :server
|
150
155
|
map remote: :server
|
@@ -204,25 +209,6 @@ module Karo
|
|
204
209
|
say Karo::VERSION
|
205
210
|
end
|
206
211
|
|
207
|
-
private
|
208
|
-
|
209
|
-
def make_command(configuration, namespace, command, extras)
|
210
|
-
commands = configuration["commands"]
|
211
|
-
|
212
|
-
if commands && commands[namespace] && commands[namespace][command]
|
213
|
-
command = commands[namespace][command]
|
214
|
-
end
|
215
|
-
|
216
|
-
extras = extras.flatten.uniq.join(" ")
|
217
|
-
|
218
|
-
"#{command} #{extras}"
|
219
|
-
end
|
220
|
-
|
221
|
-
def run_it(cmd, verbose=false)
|
222
|
-
say cmd, :green if verbose
|
223
|
-
system cmd
|
224
|
-
end
|
225
|
-
|
226
212
|
end
|
227
213
|
|
228
214
|
end
|
data/lib/karo/common.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'karo/config'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module Karo
|
5
|
+
|
6
|
+
module Common Thor
|
7
|
+
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
def make_command(configuration, namespace, command, extras)
|
11
|
+
commands = configuration["commands"]
|
12
|
+
|
13
|
+
if commands && commands[namespace] && commands[namespace][command]
|
14
|
+
command = commands[namespace][command]
|
15
|
+
end
|
16
|
+
|
17
|
+
extras = extras.flatten(1).uniq.join(" ").strip
|
18
|
+
|
19
|
+
"#{command} #{extras}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def run_it(cmd, verbose=false)
|
23
|
+
say cmd, :green if verbose
|
24
|
+
system cmd
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/karo/db.rb
CHANGED
@@ -1,26 +1,57 @@
|
|
1
|
-
require 'karo/
|
2
|
-
require 'thor'
|
3
|
-
require 'yaml'
|
1
|
+
require 'karo/common'
|
4
2
|
require 'erb'
|
5
|
-
require 'ap'
|
6
3
|
|
7
4
|
module Karo
|
8
5
|
|
9
6
|
class Db < Thor
|
10
7
|
|
11
|
-
include
|
12
|
-
|
13
|
-
class_option :config_file, type: :string, default: Config.default_file_name,
|
14
|
-
aliases: "-c", desc: "name of the file containing server configuration"
|
15
|
-
class_option :environment, aliases: "-e", desc: "server environment", default: "production"
|
16
|
-
class_option :verbose, type: :boolean, lazy_default: true, aliases: "-v", desc: "verbose"
|
8
|
+
include Karo::Common
|
17
9
|
|
18
10
|
method_option :migrate, aliases: "-m", desc: "run migrations after sync", default: true
|
19
11
|
desc "pull", "syncs MySQL database from server to localhost"
|
20
12
|
def pull
|
21
|
-
configuration = Config.load_configuration(options)
|
13
|
+
@configuration = Config.load_configuration(options)
|
14
|
+
|
15
|
+
local_db_config = load_local_db_config
|
16
|
+
server_db_config = load_server_db_config
|
17
|
+
|
18
|
+
drop_and_create_local_database(local_db_config)
|
22
19
|
|
20
|
+
sync_server_to_local_database(server_db_config, local_db_config)
|
21
|
+
|
22
|
+
if options[:migrate]
|
23
|
+
say "Running rake db:migrations", :green
|
24
|
+
run_it "bundle exec rake db:migrate", options[:verbose]
|
25
|
+
end
|
26
|
+
|
27
|
+
say "Database sync complete", :green
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "push", "syncs MySQL database from localhost to server"
|
31
|
+
def push
|
32
|
+
say "Pending Implementation...", :yellow
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "console", "open rails dbconsole for a given server environment"
|
36
|
+
method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
|
37
|
+
type: :boolean, default: true
|
38
|
+
def console
|
39
|
+
configuration = Config.load_configuration(options)
|
40
|
+
|
41
|
+
path = File.join(configuration["path"], "current")
|
42
|
+
ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
|
43
|
+
ssh << " -t" if options[:tty]
|
44
|
+
|
45
|
+
command = "cd #{path} && bundle exec rails dbconsole #{options[:environment]} -p"
|
46
|
+
|
47
|
+
run_it "#{ssh} '#{command}'", options[:verbose]
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def load_local_db_config
|
23
53
|
local_db_config_file = File.expand_path("config/database.yml")
|
54
|
+
|
24
55
|
unless File.exists?(local_db_config_file)
|
25
56
|
raise Thor::Error, "Please make sure that this file exists locally? '#{local_db_config_file}'"
|
26
57
|
end
|
@@ -31,14 +62,16 @@ module Karo
|
|
31
62
|
raise Thor::Error, "Please make sure MySQL development configuration exists within this file? '#{local_db_config_file}'"
|
32
63
|
end
|
33
64
|
|
34
|
-
local_db_config = local_db_config["development"]
|
35
|
-
|
36
65
|
say "Loading local database configuration", :green
|
37
66
|
|
38
|
-
|
67
|
+
local_db_config["development"]
|
68
|
+
end
|
39
69
|
|
40
|
-
|
41
|
-
|
70
|
+
def load_server_db_config
|
71
|
+
server_db_config_file = File.join(@configuration["path"], "shared/config/database.yml")
|
72
|
+
|
73
|
+
host = "deploy@#{@configuration["host"]}"
|
74
|
+
cmd = "ssh #{host} 'cat #{server_db_config_file}'"
|
42
75
|
|
43
76
|
server_db_config_output = `#{cmd}`
|
44
77
|
yaml_without_any_ruby = ERB.new(server_db_config_output).result
|
@@ -48,56 +81,23 @@ module Karo
|
|
48
81
|
raise Thor::Error, "Please make sure MySQL development configuration exists within this file? '#{server_db_config_file}'"
|
49
82
|
end
|
50
83
|
|
51
|
-
server_db_config = server_db_config[options[:environment]]
|
52
|
-
|
53
84
|
say "Loading #{options[:environment]} server database configuration", :green
|
54
85
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
say to_run, :green if options[:verbose]
|
59
|
-
|
60
|
-
system to_run
|
61
|
-
|
62
|
-
ssh = "ssh #{configuration["user"]}@#{configuration["host"]}"
|
63
|
-
|
64
|
-
to_run = "#{ssh} \"mysqldump --opt -C -u#{server_db_config["username"]} -p#{server_db_config["password"]} #{server_db_config["database"]}\" | mysql -v -h #{local_db_config["host"]} -C -u#{local_db_config["username"]} -p#{local_db_config["password"]} #{local_db_config["database"]}"
|
65
|
-
|
66
|
-
say to_run, :green if options[:verbose]
|
67
|
-
|
68
|
-
system to_run
|
69
|
-
|
70
|
-
if options[:migrate]
|
71
|
-
say "Running rake db:migrations", :green
|
72
|
-
system "bundle exec rake db:migrate"
|
73
|
-
end
|
74
|
-
|
75
|
-
say "Database sync complete", :green
|
76
|
-
end
|
77
|
-
|
78
|
-
desc "push", "syncs MySQL database from localhost to server"
|
79
|
-
def push
|
80
|
-
say "Pending Implementation...", :yellow
|
81
|
-
end
|
82
|
-
|
83
|
-
desc "console", "open rails dbconsole for a given server environment"
|
84
|
-
method_option :tty, aliases: "-t", desc: "force pseudo-tty allocation",
|
85
|
-
type: :boolean, default: true
|
86
|
-
def console
|
87
|
-
configuration = Config.load_configuration(options)
|
86
|
+
server_db_config[options[:environment]]
|
87
|
+
end
|
88
88
|
|
89
|
-
|
90
|
-
|
89
|
+
def drop_and_create_local_database(local_db_config)
|
90
|
+
command = "mysql -v -h #{local_db_config["host"]} -u#{local_db_config["username"]} -p#{local_db_config["password"]} -e 'DROP DATABASE IF EXISTS `#{local_db_config["database"]}`; CREATE DATABASE IF NOT EXISTS `#{local_db_config["database"]}`;'"
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
run_it command, options[:verbose]
|
93
|
+
end
|
94
94
|
|
95
|
-
|
95
|
+
def sync_server_to_local_database(server_db_config, local_db_config)
|
96
|
+
ssh = "ssh #{@configuration["user"]}@#{@configuration["host"]}"
|
96
97
|
|
97
|
-
|
98
|
+
command = "#{ssh} \"mysqldump --opt -C -u#{server_db_config["username"]} -p#{server_db_config["password"]} #{server_db_config["database"]}\" | mysql -v -h #{local_db_config["host"]} -C -u#{local_db_config["username"]} -p#{local_db_config["password"]} #{local_db_config["database"]}"
|
98
99
|
|
99
|
-
|
100
|
-
system to_run
|
100
|
+
run_it command, options[:verbose]
|
101
101
|
end
|
102
102
|
|
103
103
|
end
|
data/lib/karo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahul Trikha
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- lib/karo/assets.rb
|
148
148
|
- lib/karo/cache.rb
|
149
149
|
- lib/karo/cli.rb
|
150
|
+
- lib/karo/common.rb
|
150
151
|
- lib/karo/config.rb
|
151
152
|
- lib/karo/db.rb
|
152
153
|
- lib/karo/templates/karo.yml
|