bard 2.0.0.beta → 2.0.1
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 +4 -4
- data/.github/workflows/ci.yml +6 -1
- data/CLAUDE.md +76 -0
- data/MIGRATION_GUIDE.md +24 -9
- data/PLUGINS.md +99 -0
- data/README.md +14 -6
- data/Rakefile +3 -1
- data/bard.gemspec +2 -1
- data/cucumber.yml +1 -0
- data/features/ci.feature +63 -0
- data/features/data.feature +13 -0
- data/features/deploy.feature +14 -0
- data/features/deploy_git_workflow.feature +89 -0
- data/features/run.feature +14 -0
- data/features/step_definitions/bard_steps.rb +136 -0
- data/features/support/bard-coverage +16 -0
- data/features/support/env.rb +14 -39
- data/features/support/test_server.rb +216 -0
- data/lib/bard/cli.rb +14 -31
- data/lib/bard/command.rb +10 -69
- data/lib/bard/config.rb +40 -183
- data/lib/bard/copy.rb +28 -103
- data/lib/bard/plugins/data.rb +56 -0
- data/lib/bard/{ci → plugins/deploy/ci}/github_actions.rb +3 -4
- data/lib/bard/plugins/deploy/ci/jenkins.rb +176 -0
- data/lib/bard/{ci → plugins/deploy/ci}/local.rb +7 -7
- data/lib/bard/{ci → plugins/deploy/ci}/runner.rb +38 -4
- data/lib/bard/plugins/deploy/ci.rb +38 -0
- data/lib/bard/plugins/deploy/ssh_strategy.rb +27 -0
- data/lib/bard/{deploy_strategy.rb → plugins/deploy/strategy.rb} +1 -1
- data/lib/bard/plugins/deploy.rb +240 -0
- data/lib/bard/{git.rb → plugins/git.rb} +6 -3
- data/lib/bard/{github.rb → plugins/github.rb} +4 -6
- data/lib/bard/{deploy_strategy/github_pages.rb → plugins/github_pages/strategy.rb} +41 -13
- data/lib/bard/plugins/github_pages.rb +30 -0
- data/lib/bard/plugins/hurt.rb +13 -0
- data/{install_files → lib/bard/plugins/install}/.github/dependabot.yml +2 -1
- data/{install_files → lib/bard/plugins/install}/.github/workflows/cache-ci.yml +1 -1
- data/{install_files → lib/bard/plugins/install}/.github/workflows/ci.yml +2 -2
- data/lib/bard/plugins/install.rb +9 -0
- data/lib/bard/plugins/open.rb +20 -0
- data/lib/bard/{ping.rb → plugins/ping/check.rb} +4 -4
- data/lib/bard/plugins/ping/target_methods.rb +23 -0
- data/lib/bard/plugins/ping.rb +10 -0
- data/lib/bard/plugins/run.rb +19 -0
- data/lib/bard/plugins/setup.rb +54 -0
- data/lib/bard/plugins/ssh/connection.rb +75 -0
- data/lib/bard/plugins/ssh/copy.rb +95 -0
- data/lib/bard/{ssh_server.rb → plugins/ssh/server.rb} +17 -42
- data/lib/bard/plugins/ssh/target_methods.rb +20 -0
- data/lib/bard/plugins/ssh.rb +10 -0
- data/lib/bard/plugins/url/target_methods.rb +23 -0
- data/lib/bard/plugins/url.rb +1 -0
- data/lib/bard/plugins/vim.rb +6 -0
- data/lib/bard/retryable.rb +25 -0
- data/lib/bard/secrets.rb +10 -0
- data/lib/bard/target.rb +27 -185
- data/lib/bard/version.rb +1 -1
- data/lib/bard.rb +1 -3
- data/spec/acceptance/docker/Dockerfile +3 -2
- data/spec/bard/capability_spec.rb +8 -50
- data/spec/bard/ci/github_actions_spec.rb +117 -14
- data/spec/bard/ci/jenkins_spec.rb +139 -0
- data/spec/bard/ci/runner_spec.rb +61 -0
- data/spec/bard/ci_spec.rb +1 -1
- data/spec/bard/cli/ci_spec.rb +34 -27
- data/spec/bard/cli/data_spec.rb +7 -26
- data/spec/bard/cli/deploy_spec.rb +87 -46
- data/spec/bard/cli/hurt_spec.rb +3 -9
- data/spec/bard/cli/install_spec.rb +5 -11
- data/spec/bard/cli/master_key_spec.rb +5 -19
- data/spec/bard/cli/open_spec.rb +14 -30
- data/spec/bard/cli/ping_spec.rb +8 -23
- data/spec/bard/cli/run_spec.rb +27 -21
- data/spec/bard/cli/setup_spec.rb +10 -27
- data/spec/bard/cli/ssh_spec.rb +10 -25
- data/spec/bard/cli/stage_spec.rb +28 -23
- data/spec/bard/cli/vim_spec.rb +3 -9
- data/spec/bard/command_spec.rb +1 -8
- data/spec/bard/config_spec.rb +78 -98
- data/spec/bard/copy_spec.rb +54 -18
- data/spec/bard/deploy_strategy/ssh_spec.rb +65 -7
- data/spec/bard/deploy_strategy_spec.rb +1 -1
- data/spec/bard/dynamic_dsl_spec.rb +18 -98
- data/spec/bard/git_spec.rb +9 -5
- data/spec/bard/github_spec.rb +2 -2
- data/spec/bard/ping_spec.rb +5 -5
- data/spec/bard/ssh_copy_spec.rb +44 -0
- data/spec/bard/ssh_server_spec.rb +8 -101
- data/spec/bard/target_spec.rb +66 -109
- data/spec/spec_helper.rb +6 -1
- metadata +79 -143
- data/README.rdoc +0 -15
- data/features/bard_check.feature +0 -94
- data/features/bard_deploy.feature +0 -18
- data/features/bard_pull.feature +0 -112
- data/features/bard_push.feature +0 -112
- data/features/podman_testcontainers.feature +0 -16
- data/features/step_definitions/check_steps.rb +0 -47
- data/features/step_definitions/git_steps.rb +0 -73
- data/features/step_definitions/global_steps.rb +0 -56
- data/features/step_definitions/podman_steps.rb +0 -23
- data/features/step_definitions/rails_steps.rb +0 -44
- data/features/step_definitions/submodule_steps.rb +0 -110
- data/features/support/grit_ext.rb +0 -13
- data/features/support/io.rb +0 -32
- data/features/support/podman.rb +0 -153
- data/lib/bard/ci/jenkins.rb +0 -105
- data/lib/bard/ci/retryable.rb +0 -27
- data/lib/bard/ci.rb +0 -50
- data/lib/bard/cli/ci.rb +0 -66
- data/lib/bard/cli/command.rb +0 -26
- data/lib/bard/cli/data.rb +0 -45
- data/lib/bard/cli/deploy.rb +0 -85
- data/lib/bard/cli/hurt.rb +0 -20
- data/lib/bard/cli/install.rb +0 -16
- data/lib/bard/cli/master_key.rb +0 -17
- data/lib/bard/cli/new.rb +0 -101
- data/lib/bard/cli/new_rails_template.rb +0 -197
- data/lib/bard/cli/open.rb +0 -22
- data/lib/bard/cli/ping.rb +0 -18
- data/lib/bard/cli/provision.rb +0 -34
- data/lib/bard/cli/run.rb +0 -24
- data/lib/bard/cli/setup.rb +0 -56
- data/lib/bard/cli/ssh.rb +0 -14
- data/lib/bard/cli/stage.rb +0 -27
- data/lib/bard/cli/vim.rb +0 -13
- data/lib/bard/default_config.rb +0 -35
- data/lib/bard/deploy_strategy/ssh.rb +0 -19
- data/lib/bard/github_pages.rb +0 -134
- data/lib/bard/provision/app.rb +0 -10
- data/lib/bard/provision/apt.rb +0 -16
- data/lib/bard/provision/authorizedkeys.rb +0 -25
- data/lib/bard/provision/data.rb +0 -27
- data/lib/bard/provision/deploy.rb +0 -10
- data/lib/bard/provision/http.rb +0 -16
- data/lib/bard/provision/logrotation.rb +0 -30
- data/lib/bard/provision/masterkey.rb +0 -18
- data/lib/bard/provision/mysql.rb +0 -22
- data/lib/bard/provision/passenger.rb +0 -37
- data/lib/bard/provision/repo.rb +0 -72
- data/lib/bard/provision/rvm.rb +0 -22
- data/lib/bard/provision/ssh.rb +0 -72
- data/lib/bard/provision/swapfile.rb +0 -21
- data/lib/bard/provision/user.rb +0 -42
- data/lib/bard/provision.rb +0 -16
- data/lib/bard/server.rb +0 -117
- data/spec/bard/cli/command_spec.rb +0 -50
- data/spec/bard/cli/new_spec.rb +0 -73
- data/spec/bard/cli/provision_spec.rb +0 -42
- data/spec/bard/github_pages_spec.rb +0 -143
- data/spec/bard/provision/app_spec.rb +0 -33
- data/spec/bard/provision/apt_spec.rb +0 -39
- data/spec/bard/provision/authorizedkeys_spec.rb +0 -40
- data/spec/bard/provision/data_spec.rb +0 -54
- data/spec/bard/provision/deploy_spec.rb +0 -33
- data/spec/bard/provision/http_spec.rb +0 -57
- data/spec/bard/provision/logrotation_spec.rb +0 -34
- data/spec/bard/provision/masterkey_spec.rb +0 -63
- data/spec/bard/provision/mysql_spec.rb +0 -55
- data/spec/bard/provision/passenger_spec.rb +0 -81
- data/spec/bard/provision/repo_spec.rb +0 -208
- data/spec/bard/provision/rvm_spec.rb +0 -49
- data/spec/bard/provision/ssh_spec.rb +0 -229
- data/spec/bard/provision/swapfile_spec.rb +0 -32
- data/spec/bard/provision/user_spec.rb +0 -103
- data/spec/bard/provision_spec.rb +0 -28
- data/spec/bard/server_spec.rb +0 -127
- /data/lib/bard/{ci → plugins/deploy/ci}/state.rb +0 -0
- /data/{install_files → lib/bard/plugins/install}/apt_dependencies.rb +0 -0
- /data/{install_files → lib/bard/plugins/install}/ci +0 -0
- /data/{install_files → lib/bard/plugins/install}/setup +0 -0
- /data/{install_files → lib/bard/plugins/install}/specified_bundler.rb +0 -0
- /data/{install_files → lib/bard/plugins/install}/specified_ruby.rb +0 -0
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/provision"
|
|
3
|
-
require "bard/provision/ssh"
|
|
4
|
-
|
|
5
|
-
describe Bard::Provision::SSH do
|
|
6
|
-
let(:ssh_uri) { double("ssh_uri", host: "example.com", port: 2222) }
|
|
7
|
-
let(:provision_ssh_uri) { double("provision_ssh_uri", host: "example.com", port: nil) }
|
|
8
|
-
let(:server) { double("server", ssh_uri: ssh_uri) }
|
|
9
|
-
let(:config) { { production: server } }
|
|
10
|
-
let(:ssh_url) { "user@example.com" }
|
|
11
|
-
let(:provision_server) { double("provision_server", ssh_uri: provision_ssh_uri) }
|
|
12
|
-
let(:ssh_provisioner) { Bard::Provision::SSH.new(config, ssh_url) }
|
|
13
|
-
|
|
14
|
-
before do
|
|
15
|
-
allow(ssh_provisioner).to receive(:server).and_return(server)
|
|
16
|
-
allow(ssh_provisioner).to receive(:provision_server).and_return(provision_server)
|
|
17
|
-
allow(ssh_provisioner).to receive(:print)
|
|
18
|
-
allow(ssh_provisioner).to receive(:puts)
|
|
19
|
-
allow(ssh_provisioner).to receive(:system)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "#call" do
|
|
23
|
-
context "when SSH is already available on target port" do
|
|
24
|
-
it "skips port reconfiguration but checks known hosts" do
|
|
25
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(false)
|
|
26
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(true)
|
|
27
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).with(provision_ssh_uri).and_return(true)
|
|
28
|
-
|
|
29
|
-
expect(provision_server).not_to receive(:run!)
|
|
30
|
-
|
|
31
|
-
ssh_provisioner.call
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "adds to known hosts if not present" do
|
|
35
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(false)
|
|
36
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(true)
|
|
37
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).with(provision_ssh_uri).and_return(false)
|
|
38
|
-
|
|
39
|
-
expect(ssh_provisioner).to receive(:add_ssh_known_host!).with(provision_ssh_uri)
|
|
40
|
-
|
|
41
|
-
ssh_provisioner.call
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context "when SSH is not available on target port but available on default port" do
|
|
46
|
-
it "reconfigures SSH port and adds to known hosts" do
|
|
47
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(false)
|
|
48
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(false)
|
|
49
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri).and_return(true)
|
|
50
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).with(provision_ssh_uri).and_return(false)
|
|
51
|
-
|
|
52
|
-
expect(ssh_provisioner).to receive(:add_ssh_known_host!).with(provision_ssh_uri).twice
|
|
53
|
-
expect(provision_server).to receive(:run!).with(
|
|
54
|
-
'echo "Port 2222" | sudo tee /etc/ssh/sshd_config.d/port_2222.conf; sudo service ssh restart',
|
|
55
|
-
home: true
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
ssh_provisioner.call
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "prints status messages during reconfiguration" do
|
|
62
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(false)
|
|
63
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(false)
|
|
64
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri).and_return(true)
|
|
65
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).and_return(false)
|
|
66
|
-
allow(ssh_provisioner).to receive(:add_ssh_known_host!)
|
|
67
|
-
allow(provision_server).to receive(:run!)
|
|
68
|
-
|
|
69
|
-
expect(ssh_provisioner).to receive(:print).with("SSH:")
|
|
70
|
-
expect(ssh_provisioner).to receive(:print).with(" Adding known host,")
|
|
71
|
-
expect(ssh_provisioner).to receive(:print).with(" Reconfiguring port to 2222,")
|
|
72
|
-
expect(ssh_provisioner).to receive(:print).with(" Adding known host,")
|
|
73
|
-
expect(ssh_provisioner).to receive(:puts).with(" ✓")
|
|
74
|
-
|
|
75
|
-
ssh_provisioner.call
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
context "when SSH is not available on either port" do
|
|
80
|
-
it "raises an error" do
|
|
81
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(false)
|
|
82
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(false)
|
|
83
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri).and_return(false)
|
|
84
|
-
|
|
85
|
-
expect { ssh_provisioner.call }.to raise_error("can't find SSH on port 2222 or 22")
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context "when password authentication is enabled" do
|
|
90
|
-
it "disables password authentication" do
|
|
91
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(true)
|
|
92
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(true)
|
|
93
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).and_return(true)
|
|
94
|
-
|
|
95
|
-
expect(ssh_provisioner).to receive(:disable_password_auth!)
|
|
96
|
-
|
|
97
|
-
ssh_provisioner.call
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "prints status message when disabling password authentication" do
|
|
101
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(true)
|
|
102
|
-
allow(ssh_provisioner).to receive(:disable_password_auth!)
|
|
103
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(true)
|
|
104
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).and_return(true)
|
|
105
|
-
|
|
106
|
-
expect(ssh_provisioner).to receive(:print).with("SSH:")
|
|
107
|
-
expect(ssh_provisioner).to receive(:print).with(" Disabling password authentication,")
|
|
108
|
-
expect(ssh_provisioner).to receive(:puts).with(" ✓")
|
|
109
|
-
|
|
110
|
-
ssh_provisioner.call
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
context "when password authentication is already disabled" do
|
|
115
|
-
it "skips disabling password authentication" do
|
|
116
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(false)
|
|
117
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(true)
|
|
118
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).and_return(true)
|
|
119
|
-
|
|
120
|
-
expect(ssh_provisioner).not_to receive(:disable_password_auth!)
|
|
121
|
-
|
|
122
|
-
ssh_provisioner.call
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "updates the SSH URL with the target port" do
|
|
127
|
-
allow(ssh_provisioner).to receive(:password_auth_enabled?).and_return(false)
|
|
128
|
-
allow(ssh_provisioner).to receive(:ssh_available?).with(provision_ssh_uri, port: 2222).and_return(true)
|
|
129
|
-
allow(ssh_provisioner).to receive(:ssh_known_host?).and_return(true)
|
|
130
|
-
|
|
131
|
-
ssh_provisioner.call
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
describe "private methods" do
|
|
136
|
-
describe "#target_port" do
|
|
137
|
-
it "returns the server's SSH port" do
|
|
138
|
-
expect(ssh_provisioner.send(:target_port)).to eq(2222)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it "defaults to 22 if no port is specified" do
|
|
142
|
-
allow(ssh_uri).to receive(:port).and_return(nil)
|
|
143
|
-
expect(ssh_provisioner.send(:target_port)).to eq(22)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
describe "#ssh_available?" do
|
|
148
|
-
it "tests SSH connectivity on specified port" do
|
|
149
|
-
expect(ssh_provisioner).to receive(:system).with("nc -zv example.com 2222 2>/dev/null")
|
|
150
|
-
|
|
151
|
-
ssh_provisioner.send(:ssh_available?, provision_ssh_uri, port: 2222)
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
it "uses SSH URI port if no port specified" do
|
|
155
|
-
allow(provision_ssh_uri).to receive(:port).and_return(2222)
|
|
156
|
-
expect(ssh_provisioner).to receive(:system).with("nc -zv example.com 2222 2>/dev/null")
|
|
157
|
-
|
|
158
|
-
ssh_provisioner.send(:ssh_available?, provision_ssh_uri)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
it "defaults to port 22 if no port in URI or parameter" do
|
|
162
|
-
expect(ssh_provisioner).to receive(:system).with("nc -zv example.com 22 2>/dev/null")
|
|
163
|
-
|
|
164
|
-
ssh_provisioner.send(:ssh_available?, provision_ssh_uri)
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
describe "#ssh_known_host?" do
|
|
169
|
-
it "checks if host is in known_hosts file" do
|
|
170
|
-
expected_command = 'grep -q "$(ssh-keyscan -t ed25519 -p22 example.com 2>/dev/null | cut -d \' \' -f 2-3)" ~/.ssh/known_hosts'
|
|
171
|
-
expect(ssh_provisioner).to receive(:system).with(expected_command)
|
|
172
|
-
|
|
173
|
-
ssh_provisioner.send(:ssh_known_host?, provision_ssh_uri)
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
describe "#add_ssh_known_host!" do
|
|
178
|
-
it "adds host to known_hosts file" do
|
|
179
|
-
expected_command = "ssh-keyscan -p22 -H example.com >> ~/.ssh/known_hosts 2>/dev/null"
|
|
180
|
-
expect(ssh_provisioner).to receive(:system).with(expected_command)
|
|
181
|
-
|
|
182
|
-
ssh_provisioner.send(:add_ssh_known_host!, provision_ssh_uri)
|
|
183
|
-
end
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
describe "#password_auth_enabled?" do
|
|
187
|
-
it "returns true when password authentication is enabled" do
|
|
188
|
-
expect(provision_server).to receive(:run!).with(
|
|
189
|
-
%q{grep -E '^\s*PasswordAuthentication\s+yes' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf 2>/dev/null || true},
|
|
190
|
-
home: true,
|
|
191
|
-
capture: true
|
|
192
|
-
).and_return("PasswordAuthentication yes\n")
|
|
193
|
-
|
|
194
|
-
expect(ssh_provisioner.send(:password_auth_enabled?)).to be true
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
it "returns false when password authentication is disabled" do
|
|
198
|
-
expect(provision_server).to receive(:run!).with(
|
|
199
|
-
%q{grep -E '^\s*PasswordAuthentication\s+yes' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf 2>/dev/null || true},
|
|
200
|
-
home: true,
|
|
201
|
-
capture: true
|
|
202
|
-
).and_return("")
|
|
203
|
-
|
|
204
|
-
expect(ssh_provisioner.send(:password_auth_enabled?)).to be false
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it "returns false when grep returns nil" do
|
|
208
|
-
expect(provision_server).to receive(:run!).with(
|
|
209
|
-
%q{grep -E '^\s*PasswordAuthentication\s+yes' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf 2>/dev/null || true},
|
|
210
|
-
home: true,
|
|
211
|
-
capture: true
|
|
212
|
-
).and_return(nil)
|
|
213
|
-
|
|
214
|
-
expect(ssh_provisioner.send(:password_auth_enabled?)).to be false
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
describe "#disable_password_auth!" do
|
|
219
|
-
it "creates sshd config file to disable password authentication and restarts ssh" do
|
|
220
|
-
expect(provision_server).to receive(:run!).with(
|
|
221
|
-
%q{echo "PasswordAuthentication no" | sudo tee /etc/ssh/sshd_config.d/disable_password_auth.conf; sudo service ssh restart},
|
|
222
|
-
home: true
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
ssh_provisioner.send(:disable_password_auth!)
|
|
226
|
-
end
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/provision"
|
|
3
|
-
require "bard/provision/swapfile"
|
|
4
|
-
|
|
5
|
-
describe Bard::Provision::Swapfile do
|
|
6
|
-
let(:config) { { production: double("production") } }
|
|
7
|
-
let(:ssh_url) { "user@example.com" }
|
|
8
|
-
let(:provision_server) { double("provision_server") }
|
|
9
|
-
let(:swapfile) { Bard::Provision::Swapfile.new(config, ssh_url) }
|
|
10
|
-
|
|
11
|
-
before do
|
|
12
|
-
allow(swapfile).to receive(:provision_server).and_return(provision_server)
|
|
13
|
-
allow(swapfile).to receive(:print)
|
|
14
|
-
allow(swapfile).to receive(:puts)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#call" do
|
|
18
|
-
it "sets up swapfile on the server" do
|
|
19
|
-
expect(provision_server).to receive(:run!).with(/if \[ ! -f \/swapfile \]/)
|
|
20
|
-
|
|
21
|
-
swapfile.call
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "prints status messages" do
|
|
25
|
-
allow(provision_server).to receive(:run!)
|
|
26
|
-
expect(swapfile).to receive(:print).with("Swapfile:")
|
|
27
|
-
expect(swapfile).to receive(:puts).with(" ✓")
|
|
28
|
-
|
|
29
|
-
swapfile.call
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/provision"
|
|
3
|
-
require "bard/provision/user"
|
|
4
|
-
|
|
5
|
-
describe Bard::Provision::User do
|
|
6
|
-
let(:old_ssh_uri) { double("old_ssh_uri", user: "root", host: "example.com", port: 22) }
|
|
7
|
-
let(:new_ssh_uri) { double("new_ssh_uri", user: "deploy", host: "example.com", port: 22) }
|
|
8
|
-
let(:server) { double("server", ssh_uri: new_ssh_uri) }
|
|
9
|
-
let(:config) { { production: server } }
|
|
10
|
-
let(:ssh_url) { "root@example.com" }
|
|
11
|
-
let(:provision_server) { double("provision_server", ssh_uri: old_ssh_uri) }
|
|
12
|
-
let(:user_provisioner) { Bard::Provision::User.new(config, ssh_url) }
|
|
13
|
-
|
|
14
|
-
before do
|
|
15
|
-
allow(user_provisioner).to receive(:server).and_return(server)
|
|
16
|
-
allow(user_provisioner).to receive(:provision_server).and_return(provision_server)
|
|
17
|
-
allow(user_provisioner).to receive(:print)
|
|
18
|
-
allow(user_provisioner).to receive(:puts)
|
|
19
|
-
allow(user_provisioner).to receive(:system)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "#call" do
|
|
23
|
-
context "when new user already exists" do
|
|
24
|
-
it "skips user creation" do
|
|
25
|
-
allow(user_provisioner).to receive(:ssh_with_user?).with(old_ssh_uri, user: "deploy").and_return(true)
|
|
26
|
-
|
|
27
|
-
expect(provision_server).not_to receive(:run!)
|
|
28
|
-
|
|
29
|
-
user_provisioner.call
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "when new user doesn't exist but old user works" do
|
|
34
|
-
it "creates the new user" do
|
|
35
|
-
allow(user_provisioner).to receive(:ssh_with_user?).with(old_ssh_uri, user: "deploy").and_return(false)
|
|
36
|
-
allow(user_provisioner).to receive(:ssh_with_user?).with(old_ssh_uri).and_return(true)
|
|
37
|
-
|
|
38
|
-
expected_commands = [
|
|
39
|
-
"sudo useradd -m -s /bin/bash deploy",
|
|
40
|
-
"sudo usermod -aG sudo deploy",
|
|
41
|
-
"echo \"deploy ALL=(ALL) NOPASSWD:ALL\" | sudo tee -a /etc/sudoers",
|
|
42
|
-
"sudo mkdir -p ~deploy/.ssh",
|
|
43
|
-
"sudo cp ~/.ssh/authorized_keys ~deploy/.ssh/authorized_keys",
|
|
44
|
-
"sudo chown -R deploy:deploy ~deploy/.ssh",
|
|
45
|
-
"sudo chmod +rx ~deploy"
|
|
46
|
-
].join("; ")
|
|
47
|
-
|
|
48
|
-
expect(provision_server).to receive(:run!).with(expected_commands, home: true)
|
|
49
|
-
|
|
50
|
-
user_provisioner.call
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "prints status messages during user creation" do
|
|
54
|
-
allow(user_provisioner).to receive(:ssh_with_user?).with(old_ssh_uri, user: "deploy").and_return(false)
|
|
55
|
-
allow(user_provisioner).to receive(:ssh_with_user?).with(old_ssh_uri).and_return(true)
|
|
56
|
-
allow(provision_server).to receive(:run!)
|
|
57
|
-
|
|
58
|
-
expect(user_provisioner).to receive(:print).with("User:")
|
|
59
|
-
expect(user_provisioner).to receive(:print).with(" Adding user deploy,")
|
|
60
|
-
expect(user_provisioner).to receive(:puts).with(" ✓")
|
|
61
|
-
|
|
62
|
-
user_provisioner.call
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
context "when neither old nor new user can SSH" do
|
|
67
|
-
it "raises an error" do
|
|
68
|
-
allow(user_provisioner).to receive(:ssh_with_user?).with(old_ssh_uri, user: "deploy").and_return(false)
|
|
69
|
-
allow(user_provisioner).to receive(:ssh_with_user?).with(old_ssh_uri).and_return(false)
|
|
70
|
-
|
|
71
|
-
expect { user_provisioner.call }.to raise_error("can't ssh in with user deploy or root")
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "#ssh_with_user?" do
|
|
77
|
-
it "tests SSH connection with specified user" do
|
|
78
|
-
expect(user_provisioner).to receive(:system).with("ssh -o ConnectTimeout=2 -p22 deploy@example.com : >/dev/null 2>&1")
|
|
79
|
-
|
|
80
|
-
user_provisioner.send(:ssh_with_user?, old_ssh_uri, user: "deploy")
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "uses default user from SSH URI if not specified" do
|
|
84
|
-
expect(user_provisioner).to receive(:system).with("ssh -o ConnectTimeout=2 -p22 root@example.com : >/dev/null 2>&1")
|
|
85
|
-
|
|
86
|
-
user_provisioner.send(:ssh_with_user?, old_ssh_uri)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
describe "private methods" do
|
|
91
|
-
describe "#new_user" do
|
|
92
|
-
it "returns the target user from server SSH URI" do
|
|
93
|
-
expect(user_provisioner.send(:new_user)).to eq("deploy")
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
describe "#old_user" do
|
|
98
|
-
it "returns the current user from provision server SSH URI" do
|
|
99
|
-
expect(user_provisioner.send(:old_user)).to eq("root")
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
data/spec/bard/provision_spec.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
require "bard/provision"
|
|
3
|
-
|
|
4
|
-
describe Bard::Provision do
|
|
5
|
-
let(:config) { { production: double("production", key: :production) } }
|
|
6
|
-
let(:ssh_url) { "user@example.com" }
|
|
7
|
-
let(:provision) { Bard::Provision.new(config, ssh_url) }
|
|
8
|
-
|
|
9
|
-
describe ".call" do
|
|
10
|
-
it "creates a new instance and calls it" do
|
|
11
|
-
expect_any_instance_of(Bard::Provision).to receive(:call)
|
|
12
|
-
Bard::Provision.call(config, ssh_url)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "#server" do
|
|
17
|
-
it "returns the production server from config" do
|
|
18
|
-
expect(provision.send(:server)).to eq(config[:production])
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
describe "#provision_server" do
|
|
23
|
-
it "returns server with ssh_url" do
|
|
24
|
-
expect(config[:production]).to receive(:with).with(ssh: ssh_url)
|
|
25
|
-
provision.send(:provision_server)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
data/spec/bard/server_spec.rb
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|