bard 0.58.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bec1a5bcbd8b152ccc72b55a93301567f5e412c4dc5c3d23b247b490bf29f2fa
4
- data.tar.gz: 8eccda32ab7e8f9948c49041d1bcccda7937eeb4a84d04f5531f2a9d52470baa
3
+ metadata.gz: b89c9ca0ee7b64e04e0b04063bc8b24d8d46785f2bd445b8755971812a54607a
4
+ data.tar.gz: 0bb3e4a76f0220ae5116215a19ad3a68172eca16185cb4e7e43d431dc95e9984
5
5
  SHA512:
6
- metadata.gz: 5addafcaa1d4841dceac9aea355f84dc0637e930e85928dabd9f1e0cf4d0edebfa863a91a98035a327bce1c34a22123ec9c19c1ef4b55759982eeb5bd87c9e35
7
- data.tar.gz: 8b964f9e5461e4dd9424579ca811d3f90111406c2ddcb0087875938f76b07c0d85d294263e74e88bbec311d9cba086e617dc59d8d2f1b1eb1bf135415de56ab9
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
- "http://#{uri.host}"
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
- end
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
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "0.58.0"
2
+ VERSION = "0.59.0"
3
3
  end
4
4
 
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.58.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-02-05 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubygems_version: 3.5.3
183
+ rubygems_version: 3.5.4
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: CLI to automate common development tasks.