bard 0.65.0 → 0.67.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 +2 -10
- data/lib/bard/config.rb +13 -2
- data/lib/bard/remote_command.rb +22 -0
- data/lib/bard/version.rb +1 -1
- data/lib/bard.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4170341bba5f3a124381a496820b362c93c2ea3c446c9bfbeaa2278ecee747b5
|
4
|
+
data.tar.gz: 30a958dfa912b143f6985eb97f8a47935e62a208a084729840d0d7504719e764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19098e1641726805f743f38780b55733aaf65d7b4c95457f978303d09421e0caa90d36819310f521c6cac28f69c0440092caf9d23fe8b6641953a47e10a08570
|
7
|
+
data.tar.gz: bf75c63be5037270cdad29f60ebc4b6d1025342ab3db10359a7200a592552b21d9ccfb7fa52b8162ba4ddc710b0e5ede4bd4541efab7f366b16aa2c571bed62d
|
data/lib/bard/base.rb
CHANGED
@@ -2,6 +2,7 @@ require "thor"
|
|
2
2
|
require "term/ansicolor"
|
3
3
|
require "open3"
|
4
4
|
require "uri"
|
5
|
+
require "bard/remote_command"
|
5
6
|
|
6
7
|
class Bard::CLI < Thor
|
7
8
|
include Term::ANSIColor
|
@@ -34,16 +35,7 @@ class Bard::CLI < Thor
|
|
34
35
|
|
35
36
|
def ssh_command server_name, command, home: false
|
36
37
|
server = @config.servers.fetch(server_name.to_sym)
|
37
|
-
|
38
|
-
ssh_key = server.ssh_key ? "-i #{server.ssh_key} " : ""
|
39
|
-
command = "#{server.env} #{command}" if server.env
|
40
|
-
command = "cd #{server.path} && #{command}" unless home
|
41
|
-
command = "ssh -tt #{ssh_key}#{"-p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} '#{command}'"
|
42
|
-
if server.gateway
|
43
|
-
uri = URI.parse("ssh://#{server.gateway}")
|
44
|
-
command = "ssh -tt #{" -p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} \"#{command}\""
|
45
|
-
end
|
46
|
-
command
|
38
|
+
Bard::RemoteCommand.new(server, command, home).local_command
|
47
39
|
end
|
48
40
|
|
49
41
|
def copy direction, server_name, path, verbose: false
|
data/lib/bard/config.rb
CHANGED
@@ -45,10 +45,10 @@ module Bard
|
|
45
45
|
instance_eval source
|
46
46
|
end
|
47
47
|
|
48
|
-
attr_reader :servers
|
48
|
+
attr_reader :project_name, :servers
|
49
49
|
|
50
50
|
def server key, &block
|
51
|
-
@servers[key] ||= Server.new(
|
51
|
+
@servers[key] ||= Server.new(project_name, key)
|
52
52
|
@servers[key].instance_eval &block if block_given?
|
53
53
|
@servers[key]
|
54
54
|
end
|
@@ -61,6 +61,17 @@ module Bard
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
def backup *args
|
65
|
+
if args.length == 1
|
66
|
+
@backup = args.first
|
67
|
+
elsif args.length == 0
|
68
|
+
return @backup if defined?(@backup)
|
69
|
+
@backup = true
|
70
|
+
else
|
71
|
+
raise ArgumentError
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
64
75
|
private
|
65
76
|
|
66
77
|
class Server < Struct.new(:project_name, :key, :ssh, :path, :ping, :gateway, :ssh_key, :env)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Bard
|
2
|
+
class RemoteCommand < Struct.new(:server, :command, :home)
|
3
|
+
def local_command
|
4
|
+
uri = URI.parse("ssh://#{server.ssh}")
|
5
|
+
ssh_key = server.ssh_key ? "-i #{server.ssh_key} " : ""
|
6
|
+
cmd = command
|
7
|
+
if server.env
|
8
|
+
cmd = "#{server.env} #{command}"
|
9
|
+
end
|
10
|
+
unless home
|
11
|
+
cmd = "cd #{server.path} && #{cmd}"
|
12
|
+
end
|
13
|
+
cmd = "ssh -tt #{ssh_key}#{"-p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} '#{cmd}'"
|
14
|
+
if server.gateway
|
15
|
+
uri = URI.parse("ssh://#{server.gateway}")
|
16
|
+
cmd = "ssh -tt #{" -p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} \"#{cmd}\""
|
17
|
+
end
|
18
|
+
cmd
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/lib/bard/version.rb
CHANGED
data/lib/bard.rb
CHANGED
@@ -7,6 +7,7 @@ require "bard/data"
|
|
7
7
|
require "bard/github"
|
8
8
|
require "bard/ping"
|
9
9
|
require "bard/config"
|
10
|
+
require "bard/remote_command"
|
10
11
|
|
11
12
|
class Bard::CLI < Thor
|
12
13
|
include Thor::Actions
|
@@ -213,6 +214,16 @@ class Bard::CLI < Thor
|
|
213
214
|
exit 1 if down_urls.any?
|
214
215
|
end
|
215
216
|
|
217
|
+
desc "command <command> --on=production", "run the given command on the remote server"
|
218
|
+
method_options %w[on] => :string
|
219
|
+
def command command
|
220
|
+
default_from = @config.servers.key?(:production) ? "production" : "staging"
|
221
|
+
on = options.fetch(:on, default_from)
|
222
|
+
server = @config.servers[on.to_sym]
|
223
|
+
remote_command = Bard::RemoteCommand.new(server, command).local_command
|
224
|
+
run_crucial remote_command, verbose: true
|
225
|
+
end
|
226
|
+
|
216
227
|
desc "master_key --from=production --to=local", "copy master key from from to to"
|
217
228
|
method_options %w[from] => :string, %w[to] => :string
|
218
229
|
def master_key
|
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.67.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-08-
|
11
|
+
date: 2024-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/bard/git.rb
|
158
158
|
- lib/bard/github.rb
|
159
159
|
- lib/bard/ping.rb
|
160
|
+
- lib/bard/remote_command.rb
|
160
161
|
- lib/bard/version.rb
|
161
162
|
- spec/bard/ci/github_actions_spec.rb
|
162
163
|
- spec/bard_spec.rb
|