bard 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -0
- data/features/bard_check.feature +1 -1
- data/features/bard_push.feature +1 -1
- data/features/step_definitions/global_steps.rb +4 -4
- data/features/support/env.rb +1 -1
- data/features/support/io.rb +1 -1
- data/lib/bard/ci/github_actions.rb +3 -6
- data/lib/bard/ci/local.rb +0 -2
- data/lib/bard/ci.rb +10 -12
- data/lib/bard/cli/ci.rb +51 -0
- data/lib/bard/cli/data.rb +45 -0
- data/lib/bard/cli/deploy.rb +64 -0
- data/lib/bard/cli/hurt.rb +20 -0
- data/lib/bard/cli/install.rb +16 -0
- data/lib/bard/cli/master_key.rb +17 -0
- data/lib/bard/cli/open.rb +13 -0
- data/lib/bard/cli/ping.rb +18 -0
- data/lib/bard/cli/provision.rb +15 -0
- data/lib/bard/cli/run.rb +24 -0
- data/lib/bard/cli/setup.rb +45 -0
- data/lib/bard/cli/ssh.rb +14 -0
- data/lib/bard/cli/stage.rb +27 -0
- data/lib/bard/cli/vim.rb +13 -0
- data/lib/bard/cli.rb +21 -246
- data/lib/bard/command.rb +8 -6
- data/lib/bard/config.rb +2 -11
- data/lib/bard/copy.rb +15 -40
- data/lib/bard/git.rb +2 -4
- data/lib/bard/ping.rb +0 -1
- data/lib/bard/provision/apt.rb +16 -0
- data/lib/bard/provision/http.rb +1 -15
- data/lib/bard/provision/mysql.rb +0 -2
- data/lib/bard/provision/passenger.rb +2 -4
- data/lib/bard/provision/repo.rb +2 -2
- data/lib/bard/provision/rvm.rb +3 -2
- data/lib/bard/provision/ssh.rb +17 -10
- data/lib/bard/provision/user.rb +1 -0
- data/lib/bard/provision.rb +4 -21
- data/lib/bard/server.rb +29 -7
- data/lib/bard/version.rb +1 -1
- data/spec/bard/ci_spec.rb +10 -0
- data/spec/bard/config_spec.rb +83 -0
- data/spec/bard/server_spec.rb +127 -0
- metadata +24 -3
- /data/lib/bard/provision/{master_key.rb → masterkey.rb} +0 -0
data/lib/bard/provision.rb
CHANGED
@@ -3,16 +3,10 @@ module Bard
|
|
3
3
|
def self.call(...) = new(...).call
|
4
4
|
|
5
5
|
def call
|
6
|
-
SSH.
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
MasterKey.call(*values)
|
11
|
-
RVM.call(*values)
|
12
|
-
App.call(*values)
|
13
|
-
Passenger.call(*values)
|
14
|
-
Data.call(*values)
|
15
|
-
HTTP.call(*values)
|
6
|
+
%w[SSH User Apt MySQL Repo MasterKey RVM App Passenger Data HTTP].each do |step|
|
7
|
+
require "bard/provision/#{step.downcase}"
|
8
|
+
self.class.const_get(step).call(*values)
|
9
|
+
end
|
16
10
|
end
|
17
11
|
|
18
12
|
private
|
@@ -27,14 +21,3 @@ module Bard
|
|
27
21
|
end
|
28
22
|
end
|
29
23
|
|
30
|
-
require "bard/provision/ssh"
|
31
|
-
require "bard/provision/user"
|
32
|
-
require "bard/provision/mysql"
|
33
|
-
require "bard/provision/passenger"
|
34
|
-
require "bard/provision/repo"
|
35
|
-
require "bard/provision/master_key"
|
36
|
-
require "bard/provision/rvm"
|
37
|
-
require "bard/provision/app"
|
38
|
-
require "bard/provision/data"
|
39
|
-
require "bard/provision/http"
|
40
|
-
|
data/lib/bard/server.rb
CHANGED
@@ -3,7 +3,13 @@ require "bard/command"
|
|
3
3
|
require "bard/copy"
|
4
4
|
|
5
5
|
module Bard
|
6
|
-
class Server < Struct.new(:project_name, :key, :ssh, :path, :ping, :gateway, :ssh_key, :env
|
6
|
+
class Server < Struct.new(:project_name, :key, :ssh, :path, :ping, :gateway, :ssh_key, :env)
|
7
|
+
def self.define project_name, key, &block
|
8
|
+
new(project_name, key).tap do |server|
|
9
|
+
server.instance_eval &block
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
7
13
|
def self.setting *fields
|
8
14
|
fields.each do |field|
|
9
15
|
define_method field do |*args|
|
@@ -18,20 +24,19 @@ module Bard
|
|
18
24
|
end
|
19
25
|
end
|
20
26
|
|
21
|
-
setting :ssh, :path, :ping, :gateway, :ssh_key, :env
|
27
|
+
setting :ssh, :path, :ping, :gateway, :ssh_key, :env
|
22
28
|
|
23
29
|
def ping(*args)
|
24
30
|
if args.length == 0
|
25
|
-
(super() || [nil]).map(&method(:normalize_ping))
|
31
|
+
(super() || [nil]).map(&method(:normalize_ping)).flatten
|
26
32
|
else
|
27
33
|
self.ping = args
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
37
|
private def normalize_ping value
|
32
|
-
return
|
33
|
-
|
34
|
-
normalized = "https://#{uri.host}" # default if none specified
|
38
|
+
return [] if value == false
|
39
|
+
normalized = "https://#{ssh_uri.host}" # default if none specified
|
35
40
|
if value =~ %r{^/}
|
36
41
|
normalized += value
|
37
42
|
elsif value.to_s.length > 0
|
@@ -55,7 +60,24 @@ module Bard
|
|
55
60
|
|
56
61
|
def ssh_uri which=:ssh
|
57
62
|
value = send(which)
|
58
|
-
URI
|
63
|
+
URI("ssh://#{value}")
|
64
|
+
end
|
65
|
+
|
66
|
+
def scp_uri file_path=nil
|
67
|
+
ssh_uri.dup.tap do |uri|
|
68
|
+
uri.scheme = "scp"
|
69
|
+
uri.path = "/#{path}"
|
70
|
+
uri.path += "/#{file_path}" if file_path
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def rsync_uri file_path=nil
|
75
|
+
ssh_uri.dup.tap do |uri|
|
76
|
+
uri.scheme = nil
|
77
|
+
uri.port = nil
|
78
|
+
uri.path = ":#{path}"
|
79
|
+
uri.path += "/#{file_path}" if file_path
|
80
|
+
end.to_s[2..]
|
59
81
|
end
|
60
82
|
|
61
83
|
def with(attrs)
|
data/lib/bard/version.rb
CHANGED
@@ -0,0 +1,83 @@
|
|
1
|
+
require "bard/config"
|
2
|
+
|
3
|
+
describe Bard::Config do
|
4
|
+
context "empty" do
|
5
|
+
subject { described_class.new("tracker") }
|
6
|
+
|
7
|
+
describe "#project_name" do
|
8
|
+
it "returns the project_name setting" do
|
9
|
+
expect(subject.project_name).to eq "tracker"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#servers" do
|
14
|
+
it "is prefilled with many servers" do
|
15
|
+
expect(subject.servers.keys).to eq %i[local gubs ci staging]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#[]" do
|
20
|
+
it "promotes staging to production when production doesn't exist" do
|
21
|
+
expect(subject[:production]).to eq subject[:staging]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#data" do
|
26
|
+
it "return an empty array" do
|
27
|
+
expect(subject.data).to eq []
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#backup" do
|
32
|
+
it "returns true" do
|
33
|
+
expect(subject.backup).to eq true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with production definition" do
|
39
|
+
subject { described_class.new("tracker", source: <<~SOURCE) }
|
40
|
+
server :production do
|
41
|
+
ssh "www@ssh.botandrose.com:22022"
|
42
|
+
ping "tracker.botandrose.com"
|
43
|
+
end
|
44
|
+
|
45
|
+
data "public/system", "public/ckeditor"
|
46
|
+
backup false
|
47
|
+
SOURCE
|
48
|
+
|
49
|
+
describe "#project_name" do
|
50
|
+
it "returns the project_name setting" do
|
51
|
+
expect(subject.project_name).to eq "tracker"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#servers" do
|
56
|
+
it "contains the defined server" do
|
57
|
+
expect(subject.servers.keys).to eq %i[local gubs ci staging production]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#server" do
|
62
|
+
it "can overwrite existing definition" do
|
63
|
+
subject.server :staging do
|
64
|
+
ssh "www@tracker-staging.botandrose.com:22022"
|
65
|
+
end
|
66
|
+
expect(subject[:staging].ssh).to eq "www@tracker-staging.botandrose.com:22022"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#data" do
|
71
|
+
it "returns the data setting" do
|
72
|
+
expect(subject.data).to eq ["public/system", "public/ckeditor"]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#backup" do
|
77
|
+
it "returns the backup setting" do
|
78
|
+
expect(subject.backup).to eq false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require "bard/server"
|
2
|
+
|
3
|
+
describe Bard::Server do
|
4
|
+
subject do
|
5
|
+
described_class.define("tracker", :production) do
|
6
|
+
ssh "www@tracker.botandrose.com:22022"
|
7
|
+
path "work/tracker"
|
8
|
+
ping "tracker.botandrose.com", "www.tracker.botandrose.com"
|
9
|
+
gateway "www@staging.botandrose.com:22022"
|
10
|
+
ssh_key "~/.ssh/id_rsa.pub"
|
11
|
+
env "RAILS_ENV=production"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#ssh" do
|
16
|
+
it "returns the ssh setting" do
|
17
|
+
expect(subject.ssh).to eq "www@tracker.botandrose.com:22022"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#ssh_uri" do
|
22
|
+
it "exposes the host" do
|
23
|
+
expect(subject.ssh_uri.host).to eq "tracker.botandrose.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "exposes the user" do
|
27
|
+
expect(subject.ssh_uri.user).to eq "www"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "exposes the port" do
|
31
|
+
expect(subject.ssh_uri.port).to eq 22022
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has no path" do
|
35
|
+
expect(subject.ssh_uri.path).to be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can specify another field to read from" do
|
39
|
+
expect(subject.ssh_uri(:gateway).host).to eq "staging.botandrose.com"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has no path" do
|
43
|
+
expect(subject.ssh_uri.path).to be_empty
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#scp_uri" do
|
48
|
+
it "exposes the host" do
|
49
|
+
expect(subject.scp_uri.host).to eq "tracker.botandrose.com"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "exposes the user" do
|
53
|
+
expect(subject.scp_uri.user).to eq "www"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "exposes the port" do
|
57
|
+
expect(subject.scp_uri.port).to eq 22022
|
58
|
+
end
|
59
|
+
|
60
|
+
it "includes the path to the project" do
|
61
|
+
expect(subject.scp_uri.path).to eq "/work/tracker"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "compiles to an scp:// string" do
|
65
|
+
expect(subject.scp_uri.to_s).to eq "scp://www@tracker.botandrose.com:22022/work/tracker"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#rsync_uri" do
|
70
|
+
it "works" do
|
71
|
+
expect(subject.rsync_uri("public/assets")).to eq "www@tracker.botandrose.com:work/tracker/public/assets"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#path" do
|
76
|
+
it "returns the path setting" do
|
77
|
+
expect(subject.path).to eq "work/tracker"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "defaults to the project name" do
|
81
|
+
subject.path nil
|
82
|
+
expect(subject.path).to eq "tracker"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#ping" do
|
87
|
+
it "returns the ping urls, normalized" do
|
88
|
+
expect(subject.ping).to eq [
|
89
|
+
"https://tracker.botandrose.com",
|
90
|
+
"https://www.tracker.botandrose.com",
|
91
|
+
]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "accepts paths" do
|
95
|
+
subject.ping "/ping"
|
96
|
+
expect(subject.ping).to eq ["https://tracker.botandrose.com/ping"]
|
97
|
+
end
|
98
|
+
|
99
|
+
it "defaults to the ssh value" do
|
100
|
+
subject.ping nil
|
101
|
+
expect(subject.ping).to eq ["https://tracker.botandrose.com"]
|
102
|
+
end
|
103
|
+
|
104
|
+
it "accepts false to disable pings" do
|
105
|
+
subject.ping false
|
106
|
+
expect(subject.ping).to eq []
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#gateway" do
|
111
|
+
it "returns the gateway setting" do
|
112
|
+
expect(subject.gateway).to eq "www@staging.botandrose.com:22022"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#ssh_key" do
|
117
|
+
it "returns the ssh_key setting" do
|
118
|
+
expect(subject.ssh_key).to eq "~/.ssh/id_rsa.pub"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#env" do
|
123
|
+
it "returns the env setting" do
|
124
|
+
expect(subject.env).to eq "RAILS_ENV=production"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -138,6 +138,20 @@ files:
|
|
138
138
|
- lib/bard/ci/jenkins.rb
|
139
139
|
- lib/bard/ci/local.rb
|
140
140
|
- lib/bard/cli.rb
|
141
|
+
- lib/bard/cli/ci.rb
|
142
|
+
- lib/bard/cli/data.rb
|
143
|
+
- lib/bard/cli/deploy.rb
|
144
|
+
- lib/bard/cli/hurt.rb
|
145
|
+
- lib/bard/cli/install.rb
|
146
|
+
- lib/bard/cli/master_key.rb
|
147
|
+
- lib/bard/cli/open.rb
|
148
|
+
- lib/bard/cli/ping.rb
|
149
|
+
- lib/bard/cli/provision.rb
|
150
|
+
- lib/bard/cli/run.rb
|
151
|
+
- lib/bard/cli/setup.rb
|
152
|
+
- lib/bard/cli/ssh.rb
|
153
|
+
- lib/bard/cli/stage.rb
|
154
|
+
- lib/bard/cli/vim.rb
|
141
155
|
- lib/bard/command.rb
|
142
156
|
- lib/bard/config.rb
|
143
157
|
- lib/bard/copy.rb
|
@@ -146,9 +160,10 @@ files:
|
|
146
160
|
- lib/bard/ping.rb
|
147
161
|
- lib/bard/provision.rb
|
148
162
|
- lib/bard/provision/app.rb
|
163
|
+
- lib/bard/provision/apt.rb
|
149
164
|
- lib/bard/provision/data.rb
|
150
165
|
- lib/bard/provision/http.rb
|
151
|
-
- lib/bard/provision/
|
166
|
+
- lib/bard/provision/masterkey.rb
|
152
167
|
- lib/bard/provision/mysql.rb
|
153
168
|
- lib/bard/provision/passenger.rb
|
154
169
|
- lib/bard/provision/repo.rb
|
@@ -158,6 +173,9 @@ files:
|
|
158
173
|
- lib/bard/server.rb
|
159
174
|
- lib/bard/version.rb
|
160
175
|
- spec/bard/ci/github_actions_spec.rb
|
176
|
+
- spec/bard/ci_spec.rb
|
177
|
+
- spec/bard/config_spec.rb
|
178
|
+
- spec/bard/server_spec.rb
|
161
179
|
- spec/bard_spec.rb
|
162
180
|
- spec/spec_helper.rb
|
163
181
|
- spec/support/fixtures/job.json
|
@@ -199,6 +217,9 @@ test_files:
|
|
199
217
|
- features/support/grit_ext.rb
|
200
218
|
- features/support/io.rb
|
201
219
|
- spec/bard/ci/github_actions_spec.rb
|
220
|
+
- spec/bard/ci_spec.rb
|
221
|
+
- spec/bard/config_spec.rb
|
222
|
+
- spec/bard/server_spec.rb
|
202
223
|
- spec/bard_spec.rb
|
203
224
|
- spec/spec_helper.rb
|
204
225
|
- spec/support/fixtures/job.json
|
File without changes
|