bard 0.57.0 → 0.59.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bard/base.rb +36 -0
- data/lib/bard/config.rb +7 -1
- data/lib/bard/data.rb +37 -2
- data/lib/bard/version.rb +1 -1
- data/lib/bard.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b89c9ca0ee7b64e04e0b04063bc8b24d8d46785f2bd445b8755971812a54607a
|
4
|
+
data.tar.gz: 0bb3e4a76f0220ae5116215a19ad3a68172eca16185cb4e7e43d431dc95e9984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd28186f63c5e0e3e0a77c94d2756c622477f164e0fae220642e5ebd03ca3aa4d04858ee3ec1fb1efb9eb2ed189a93314c89b8d1d44310d249bb6d1064cdc0ad
|
7
|
+
data.tar.gz: b3b71f60070f6cdefa1c7d733188130f2a6e2f4c6ea236878d17e064a35dc9558ba05ca889b4a761fa311538736f3fcfb2276c5a4d5a1872a66772cdfe2b661c
|
data/lib/bard/base.rb
CHANGED
@@ -65,6 +65,22 @@ class Bard::CLI < Thor
|
|
65
65
|
run_crucial command, verbose: verbose
|
66
66
|
end
|
67
67
|
|
68
|
+
def move from, to, path, verbose: false
|
69
|
+
from = @config.servers[from.to_sym]
|
70
|
+
to = @config.servers[to.to_sym]
|
71
|
+
raise NotImplementedError if from.gateway || to.gateway || from.ssh_key || to.ssh_key
|
72
|
+
|
73
|
+
from_uri = URI.parse("ssh://#{from.ssh}")
|
74
|
+
from_str = "scp://#{from_uri.user}@#{from_uri.host}:#{from_uri.port || 22}/#{from.path}/#{path}"
|
75
|
+
|
76
|
+
to_uri = URI.parse("ssh://#{to.ssh}")
|
77
|
+
to_str = "scp://#{to_uri.user}@#{to_uri.host}:#{to_uri.port || 22}/#{to.path}/#{path}"
|
78
|
+
|
79
|
+
command = "scp -o ForwardAgent=yes #{from_str} #{to_str}"
|
80
|
+
|
81
|
+
run_crucial command, verbose: verbose
|
82
|
+
end
|
83
|
+
|
68
84
|
def rsync direction, server, path, verbose: false
|
69
85
|
server = @config.servers[server.to_sym]
|
70
86
|
|
@@ -87,5 +103,25 @@ class Bard::CLI < Thor
|
|
87
103
|
|
88
104
|
run_crucial command, verbose: verbose
|
89
105
|
end
|
106
|
+
|
107
|
+
def rsync_remote from, to, path, verbose: false
|
108
|
+
from = @config.servers[from.to_sym]
|
109
|
+
to = @config.servers[to.to_sym]
|
110
|
+
raise NotImplementedError if from.gateway || to.gateway || from.ssh_key || to.ssh_key
|
111
|
+
|
112
|
+
dest_path = path.dup
|
113
|
+
dest_path = "./#{dest_path}"
|
114
|
+
|
115
|
+
from_uri = URI.parse("ssh://#{from.ssh}")
|
116
|
+
from_str = "-p#{from_uri.port || 22} #{from_uri.user}@#{from_uri.host}"
|
117
|
+
|
118
|
+
to_uri = URI.parse("ssh://#{to.ssh}")
|
119
|
+
to_str = "#{to_uri.user}@#{to_uri.host}:#{to.path}/#{path}"
|
120
|
+
to_str.sub! %r(/[^/]+$), '/'
|
121
|
+
|
122
|
+
command = %(ssh -A #{from_str} 'rsync -e \"ssh -A -p#{to_uri.port || 22} -o StrictHostKeyChecking=no\" --delete --info=progress2 -az #{from.path}/#{path} #{to_str}')
|
123
|
+
|
124
|
+
run_crucial command, verbose: verbose
|
125
|
+
end
|
90
126
|
end
|
91
127
|
|
data/lib/bard/config.rb
CHANGED
@@ -83,7 +83,13 @@ class Bard::CLI < Thor
|
|
83
83
|
|
84
84
|
def default_ping
|
85
85
|
uri = URI.parse("ssh://#{ssh}")
|
86
|
-
"
|
86
|
+
"https://#{uri.host}"
|
87
|
+
end
|
88
|
+
|
89
|
+
def normalized_ping
|
90
|
+
normalized = ping || default_ping
|
91
|
+
normalized = "https://#{normalized}" unless normalized =~ /^http/
|
92
|
+
normalized
|
87
93
|
end
|
88
94
|
|
89
95
|
def path(*args)
|
data/lib/bard/data.rb
CHANGED
@@ -1,13 +1,26 @@
|
|
1
1
|
class Bard::CLI < Thor
|
2
2
|
class Data < Struct.new(:bard, :from, :to)
|
3
3
|
def call
|
4
|
+
if to == "production"
|
5
|
+
server = bard.instance_variable_get(:@config).servers[to.to_sym]
|
6
|
+
url = server.normalized_ping
|
7
|
+
puts bard.yellow("WARNING: You are about to push data to production, overwriting everything that is there!")
|
8
|
+
answer = bard.ask("If you really want to do this, please type in the full HTTPS url of the production server:")
|
9
|
+
if answer != url
|
10
|
+
puts bard.red("!!! ") + "Failed! We expected #{url}. Is this really where you want to overwrite all the data?"
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
4
15
|
if to == "local"
|
5
16
|
data_pull_db from.to_sym
|
6
17
|
data_pull_assets from.to_sym
|
7
|
-
|
8
|
-
if from == "local"
|
18
|
+
elsif from == "local"
|
9
19
|
data_push_db to.to_sym
|
10
20
|
data_push_assets to.to_sym
|
21
|
+
else
|
22
|
+
data_move_db from.to_sym, to.to_sym
|
23
|
+
data_move_assets from.to_sym, to.to_sym
|
11
24
|
end
|
12
25
|
end
|
13
26
|
|
@@ -39,6 +52,19 @@ class Bard::CLI < Thor
|
|
39
52
|
end
|
40
53
|
end
|
41
54
|
|
55
|
+
def data_move_db from, to
|
56
|
+
bard.instance_eval do
|
57
|
+
puts "Dumping local database to file..."
|
58
|
+
run_crucial ssh_command(from, "bin/rake db:load")
|
59
|
+
|
60
|
+
puts "Uploading file..."
|
61
|
+
move from, to, "db/data.sql.gz", verbose: true
|
62
|
+
|
63
|
+
puts "Loading file into remote database..."
|
64
|
+
run_crucial ssh_command(to, "bin/rake db:load")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
42
68
|
def data_pull_assets server
|
43
69
|
bard.instance_eval do
|
44
70
|
@config.data.each do |path|
|
@@ -56,6 +82,15 @@ class Bard::CLI < Thor
|
|
56
82
|
end
|
57
83
|
end
|
58
84
|
end
|
85
|
+
|
86
|
+
def data_move_assets from, to
|
87
|
+
bard.instance_eval do
|
88
|
+
@config.data.each do |path|
|
89
|
+
puts "Copying files..."
|
90
|
+
rsync_remote from, to, path, verbose: true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
59
94
|
end
|
60
95
|
end
|
61
96
|
|
data/lib/bard/version.rb
CHANGED
data/lib/bard.rb
CHANGED
@@ -13,9 +13,12 @@ class Bard::CLI < Thor
|
|
13
13
|
@config = Config.new(project_name, "bard.rb")
|
14
14
|
end
|
15
15
|
|
16
|
-
desc "data
|
17
|
-
|
18
|
-
|
16
|
+
desc "data --from=production --to=local", "copy database and assets from from to to"
|
17
|
+
method_options %w[from] => :string, %w[to] => :string
|
18
|
+
def data
|
19
|
+
default_from = @config.servers.key?(:production) ? "production" : "staging"
|
20
|
+
from = options.fetch(:from, default_from)
|
21
|
+
to = options.fetch(:to, "local")
|
19
22
|
Data.new(self, from, to).call
|
20
23
|
end
|
21
24
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.59.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|