bard 1.4.8 → 1.4.9
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 +22 -0
- data/Gemfile +4 -0
- data/bard.gemspec +3 -2
- data/lib/bard/git.rb +5 -1
- data/lib/bard/provision/repo.rb +21 -0
- data/lib/bard/provision/ssh.rb +21 -0
- data/lib/bard/server.rb +2 -2
- data/lib/bard/version.rb +1 -1
- data/spec/bard/cli/ci_spec.rb +139 -0
- data/spec/bard/cli/command_spec.rb +50 -0
- data/spec/bard/cli/data_spec.rb +77 -0
- data/spec/bard/cli/deploy_spec.rb +202 -0
- data/spec/bard/cli/hurt_spec.rb +23 -0
- data/spec/bard/cli/install_spec.rb +25 -0
- data/spec/bard/cli/master_key_spec.rb +52 -0
- data/spec/bard/cli/new_spec.rb +60 -0
- data/spec/bard/cli/open_spec.rb +67 -0
- data/spec/bard/cli/ping_spec.rb +47 -0
- data/spec/bard/cli/provision_spec.rb +42 -0
- data/spec/bard/cli/run_spec.rb +51 -0
- data/spec/bard/cli/setup_spec.rb +76 -0
- data/spec/bard/cli/ssh_spec.rb +55 -0
- data/spec/bard/cli/stage_spec.rb +77 -0
- data/spec/bard/cli/vim_spec.rb +34 -0
- data/spec/bard/command_spec.rb +37 -0
- data/spec/bard/copy_spec.rb +33 -0
- data/spec/bard/git_spec.rb +61 -0
- data/spec/bard/github_pages_spec.rb +80 -0
- data/spec/bard/github_spec.rb +45 -0
- data/spec/bard/ping_spec.rb +31 -0
- data/spec/bard/provision/app_spec.rb +33 -0
- data/spec/bard/provision/apt_spec.rb +39 -0
- data/spec/bard/provision/authorizedkeys_spec.rb +40 -0
- data/spec/bard/provision/data_spec.rb +54 -0
- data/spec/bard/provision/deploy_spec.rb +33 -0
- data/spec/bard/provision/http_spec.rb +57 -0
- data/spec/bard/provision/logrotation_spec.rb +34 -0
- data/spec/bard/provision/masterkey_spec.rb +63 -0
- data/spec/bard/provision/mysql_spec.rb +55 -0
- data/spec/bard/provision/passenger_spec.rb +81 -0
- data/spec/bard/provision/repo_spec.rb +208 -0
- data/spec/bard/provision/rvm_spec.rb +49 -0
- data/spec/bard/provision/ssh_spec.rb +229 -0
- data/spec/bard/provision/swapfile_spec.rb +32 -0
- data/spec/bard/provision/user_spec.rb +103 -0
- data/spec/bard/provision_spec.rb +28 -0
- data/spec/spec_helper.rb +6 -1
- metadata +96 -9
@@ -0,0 +1,61 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/git"
|
3
|
+
|
4
|
+
describe Bard::Git do
|
5
|
+
describe ".current_branch" do
|
6
|
+
it "should return the current branch" do
|
7
|
+
allow(Bard::Git).to receive(:`).with("git symbolic-ref HEAD 2>&1").and_return("refs/heads/master\n")
|
8
|
+
expect(Bard::Git.current_branch).to eq("master")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return false if not on a branch" do
|
12
|
+
allow(Bard::Git).to receive(:`).with("git symbolic-ref HEAD 2>&1").and_return("fatal: ref HEAD is not a symbolic ref\n")
|
13
|
+
expect(Bard::Git.current_branch).to be_falsey
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".fast_forward_merge?" do
|
18
|
+
it "should return true if the root is an ancestor of the branch" do
|
19
|
+
allow(Bard::Git).to receive(:sha_of).with("root").and_return("root_sha")
|
20
|
+
allow(Bard::Git).to receive(:sha_of).with("branch").and_return("branch_sha")
|
21
|
+
allow(Bard::Git).to receive(:`).with("git merge-base root_sha branch_sha").and_return("root_sha\n")
|
22
|
+
expect(Bard::Git.fast_forward_merge?("root", "branch")).to be_truthy
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return false if the root is not an ancestor of the branch" do
|
26
|
+
allow(Bard::Git).to receive(:sha_of).with("root").and_return("root_sha")
|
27
|
+
allow(Bard::Git).to receive(:sha_of).with("branch").and_return("branch_sha")
|
28
|
+
allow(Bard::Git).to receive(:`).with("git merge-base root_sha branch_sha").and_return("other_sha\n")
|
29
|
+
expect(Bard::Git.fast_forward_merge?("root", "branch")).to be_falsey
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".up_to_date_with_remote?" do
|
34
|
+
it "should return true if the local branch is up to date with the remote" do
|
35
|
+
allow(Bard::Git).to receive(:sha_of).with("branch").and_return("sha")
|
36
|
+
allow(Bard::Git).to receive(:sha_of).with("origin/branch").and_return("sha")
|
37
|
+
expect(Bard::Git.up_to_date_with_remote?("branch")).to be_truthy
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return false if the local branch is not up to date with the remote" do
|
41
|
+
allow(Bard::Git).to receive(:sha_of).with("branch").and_return("sha1")
|
42
|
+
allow(Bard::Git).to receive(:sha_of).with("origin/branch").and_return("sha2")
|
43
|
+
expect(Bard::Git.up_to_date_with_remote?("branch")).to be_falsey
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".sha_of" do
|
48
|
+
it "should return the sha of a ref" do
|
49
|
+
allow(Bard::Git).to receive(:`).with("git rev-parse ref 2>/dev/null").and_return("sha\n")
|
50
|
+
allow(Bard::Git).to receive(:command_succeeded?).and_return(true)
|
51
|
+
expect(Bard::Git.sha_of("ref")).to eq("sha")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return nil if the ref does not exist" do
|
55
|
+
allow(Bard::Git).to receive(:`).with("git rev-parse ref 2>/dev/null").and_return("ref: fatal: ambiguous argument 'ref': unknown revision or path not in the working tree.\n")
|
56
|
+
allow(Bard::Git).to receive(:command_succeeded?).and_return(false)
|
57
|
+
expect(Bard::Git.sha_of("ref")).to be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/github_pages"
|
3
|
+
|
4
|
+
describe Bard::GithubPages do
|
5
|
+
let(:server) { double("server", ping: ["https://example.com"]) }
|
6
|
+
let(:github_pages) { Bard::GithubPages.new(double) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(Bard::Git).to receive(:sha_of).and_return("abc123")
|
10
|
+
allow(Bard::Git).to receive(:current_branch).and_return("main")
|
11
|
+
allow(github_pages).to receive(:system)
|
12
|
+
allow(github_pages).to receive(:run!)
|
13
|
+
allow(github_pages).to receive(:puts)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#deploy" do
|
17
|
+
it "performs the deployment steps" do
|
18
|
+
expect(github_pages).to receive(:build_site)
|
19
|
+
expect(github_pages).to receive(:create_tree_from_build).and_return("tree123")
|
20
|
+
expect(github_pages).to receive(:create_commit).with("tree123").and_return("commit123")
|
21
|
+
expect(github_pages).to receive(:commit_and_push).with("commit123")
|
22
|
+
|
23
|
+
github_pages.deploy(server)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets instance variables" do
|
27
|
+
allow(github_pages).to receive(:build_site)
|
28
|
+
allow(github_pages).to receive(:create_tree_from_build).and_return("tree123")
|
29
|
+
allow(github_pages).to receive(:create_commit).and_return("commit123")
|
30
|
+
allow(github_pages).to receive(:commit_and_push)
|
31
|
+
|
32
|
+
github_pages.deploy(server)
|
33
|
+
|
34
|
+
expect(github_pages.instance_variable_get(:@sha)).to eq("abc123")
|
35
|
+
expect(github_pages.instance_variable_get(:@build_dir)).to eq("tmp/github-build-abc123")
|
36
|
+
expect(github_pages.instance_variable_get(:@branch)).to eq("gh-pages")
|
37
|
+
expect(github_pages.instance_variable_get(:@domain)).to eq("example.com")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#get_parent_commit" do
|
42
|
+
it "returns the sha of the gh-pages branch" do
|
43
|
+
github_pages.instance_variable_set(:@branch, "gh-pages")
|
44
|
+
expect(Bard::Git).to receive(:sha_of).with("gh-pages^{commit}")
|
45
|
+
github_pages.send(:get_parent_commit)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#branch_exists?" do
|
50
|
+
it "checks if branch exists using git show-ref" do
|
51
|
+
github_pages.instance_variable_set(:@branch, "gh-pages")
|
52
|
+
expect(github_pages).to receive(:system).with("git show-ref --verify --quiet refs/heads/gh-pages")
|
53
|
+
github_pages.send(:branch_exists?)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#commit_and_push" do
|
58
|
+
before do
|
59
|
+
github_pages.instance_variable_set(:@branch, "gh-pages")
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when branch exists" do
|
63
|
+
it "updates the ref and pushes" do
|
64
|
+
allow(github_pages).to receive(:branch_exists?).and_return(true)
|
65
|
+
expect(github_pages).to receive(:run!).with("git update-ref refs/heads/gh-pages commit123")
|
66
|
+
expect(github_pages).to receive(:run!).with("git push -f origin gh-pages:refs/heads/gh-pages")
|
67
|
+
github_pages.send(:commit_and_push, "commit123")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when branch doesn't exist" do
|
72
|
+
it "creates the branch and pushes" do
|
73
|
+
allow(github_pages).to receive(:branch_exists?).and_return(false)
|
74
|
+
expect(github_pages).to receive(:run!).with("git branch gh-pages commit123")
|
75
|
+
expect(github_pages).to receive(:run!).with("git push -f origin gh-pages:refs/heads/gh-pages")
|
76
|
+
github_pages.send(:commit_and_push, "commit123")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/github"
|
3
|
+
|
4
|
+
describe Bard::Github do
|
5
|
+
let(:github) { Bard::Github.new("test-project") }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(github).to receive(:`).with("git ls-remote -t git@github.com:botandrose/bard").and_return("github-apikey|12345")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#get" do
|
12
|
+
it "should make a GET request to the GitHub API" do
|
13
|
+
stub_request(:get, "https://api.github.com/repos/botandrosedesign/test-project/path").to_return(body: "{}")
|
14
|
+
github.get("path")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#post" do
|
19
|
+
it "should make a POST request to the GitHub API" do
|
20
|
+
stub_request(:post, "https://api.github.com/repos/botandrosedesign/test-project/path").with(body: "{\"foo\":\"bar\"}").to_return(body: "{}")
|
21
|
+
github.post("path", { foo: "bar" })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#put" do
|
26
|
+
it "should make a PUT request to the GitHub API" do
|
27
|
+
stub_request(:put, "https://api.github.com/repos/botandrosedesign/test-project/path").with(body: "{\"foo\":\"bar\"}").to_return(body: "{}")
|
28
|
+
github.put("path", { foo: "bar" })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#patch" do
|
33
|
+
it "should make a PATCH request to the GitHub API" do
|
34
|
+
stub_request(:patch, "https://api.github.com/repos/botandrosedesign/test-project/path").with(body: "{\"foo\":\"bar\"}").to_return(body: "{}")
|
35
|
+
github.patch("path", { foo: "bar" })
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#delete" do
|
40
|
+
it "should make a DELETE request to the GitHub API" do
|
41
|
+
stub_request(:delete, "https://api.github.com/repos/botandrosedesign/test-project").with(body: "{\"foo\":\"bar\"}").to_return(body: "{}")
|
42
|
+
github.delete(nil, { foo: "bar" })
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/ping"
|
3
|
+
|
4
|
+
describe Bard::Ping do
|
5
|
+
let(:server) { double("server", ping: ["http://example.com"]) }
|
6
|
+
|
7
|
+
context "when the server is reachable" do
|
8
|
+
it "should return an empty array" do
|
9
|
+
allow(Net::HTTP).to receive(:get_response).and_return(Net::HTTPSuccess.new(1.0, "200", "OK"))
|
10
|
+
expect(Bard::Ping.call(server)).to be_empty
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when the server is not reachable" do
|
15
|
+
it "should return the url" do
|
16
|
+
allow(Net::HTTP).to receive(:get_response).and_return(Net::HTTPNotFound.new(1.0, "404", "Not Found"))
|
17
|
+
expect(Bard::Ping.call(server)).to eq(["http://example.com"])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when there is a redirect" do
|
22
|
+
it "should follow the redirect and return an empty array" do
|
23
|
+
redirect_response = Net::HTTPRedirection.new(1.0, "301", "Moved Permanently")
|
24
|
+
redirect_response["location"] = "http://example.com/new"
|
25
|
+
success_response = Net::HTTPSuccess.new(1.0, "200", "OK")
|
26
|
+
allow(Net::HTTP).to receive(:get_response).with(URI("http://example.com")).and_return(redirect_response)
|
27
|
+
allow(Net::HTTP).to receive(:get_response).with(URI("http://example.com/new")).and_return(success_response)
|
28
|
+
expect(Bard::Ping.call(server)).to be_empty
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/app"
|
4
|
+
|
5
|
+
describe Bard::Provision::App do
|
6
|
+
let(:config) { { production: double("production") } }
|
7
|
+
let(:ssh_url) { "user@example.com" }
|
8
|
+
let(:provision_server) { double("provision_server") }
|
9
|
+
let(:app) { Bard::Provision::App.new(config, ssh_url) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(app).to receive(:provision_server).and_return(provision_server)
|
13
|
+
allow(app).to receive(:print)
|
14
|
+
allow(app).to receive(:puts)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#call" do
|
18
|
+
it "runs bin/setup on the server" do
|
19
|
+
expect(provision_server).to receive(:run!).with("bin/setup")
|
20
|
+
|
21
|
+
app.call
|
22
|
+
end
|
23
|
+
|
24
|
+
it "prints status messages" do
|
25
|
+
allow(provision_server).to receive(:run!)
|
26
|
+
|
27
|
+
expect(app).to receive(:print).with("App:")
|
28
|
+
expect(app).to receive(:puts).with(" ✓")
|
29
|
+
|
30
|
+
app.call
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/apt"
|
4
|
+
|
5
|
+
describe Bard::Provision::Apt do
|
6
|
+
let(:config) { { production: double("production") } }
|
7
|
+
let(:ssh_url) { "user@example.com" }
|
8
|
+
let(:provision_server) { double("provision_server") }
|
9
|
+
let(:apt) { Bard::Provision::Apt.new(config, ssh_url) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(apt).to receive(:provision_server).and_return(provision_server)
|
13
|
+
allow(apt).to receive(:print)
|
14
|
+
allow(apt).to receive(:puts)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#call" do
|
18
|
+
it "updates and installs packages on the server" do
|
19
|
+
expected_commands = [
|
20
|
+
%(echo "\\$nrconf{restart} = \\"a\\";" | sudo tee /etc/needrestart/conf.d/90-autorestart.conf),
|
21
|
+
"sudo apt-get update -y",
|
22
|
+
"sudo apt-get upgrade -y",
|
23
|
+
"sudo apt-get install -y curl"
|
24
|
+
].join("; ")
|
25
|
+
|
26
|
+
expect(provision_server).to receive(:run!).with(expected_commands, home: true)
|
27
|
+
|
28
|
+
apt.call
|
29
|
+
end
|
30
|
+
|
31
|
+
it "prints status messages" do
|
32
|
+
allow(provision_server).to receive(:run!)
|
33
|
+
expect(apt).to receive(:print).with("Apt:")
|
34
|
+
expect(apt).to receive(:puts).with(" ✓")
|
35
|
+
|
36
|
+
apt.call
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/authorizedkeys"
|
4
|
+
|
5
|
+
describe Bard::Provision::AuthorizedKeys do
|
6
|
+
let(:config) { { production: double("production") } }
|
7
|
+
let(:ssh_url) { "user@example.com" }
|
8
|
+
let(:provision_server) { double("provision_server") }
|
9
|
+
let(:authorized_keys) { Bard::Provision::AuthorizedKeys.new(config, ssh_url) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(authorized_keys).to receive(:provision_server).and_return(provision_server)
|
13
|
+
allow(authorized_keys).to receive(:print)
|
14
|
+
allow(authorized_keys).to receive(:puts)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#call" do
|
18
|
+
it "adds authorized keys to the server" do
|
19
|
+
expect(provision_server).to receive(:run!).at_least(:once).with(/grep -F -q/, home: true)
|
20
|
+
|
21
|
+
authorized_keys.call
|
22
|
+
end
|
23
|
+
|
24
|
+
it "prints status messages" do
|
25
|
+
allow(provision_server).to receive(:run!)
|
26
|
+
expect(authorized_keys).to receive(:print).with("Authorized Keys:")
|
27
|
+
expect(authorized_keys).to receive(:puts).with(" ✓")
|
28
|
+
|
29
|
+
authorized_keys.call
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "KEYS constant" do
|
34
|
+
it "should have predefined SSH keys" do
|
35
|
+
expect(Bard::Provision::AuthorizedKeys::KEYS).to be_a(Hash)
|
36
|
+
expect(Bard::Provision::AuthorizedKeys::KEYS).not_to be_empty
|
37
|
+
expect(Bard::Provision::AuthorizedKeys::KEYS.keys.first).to match(/@/)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/data"
|
4
|
+
|
5
|
+
describe Bard::Provision::Data do
|
6
|
+
let(:server) { double("server", key: :production) }
|
7
|
+
let(:config) { double("config", data: ["uploads", "assets"]) }
|
8
|
+
let(:ssh_url) { "user@example.com" }
|
9
|
+
let(:provision_server) { double("provision_server") }
|
10
|
+
let(:data_provisioner) { Bard::Provision::Data.new(config, ssh_url) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(data_provisioner).to receive(:server).and_return(server)
|
14
|
+
allow(data_provisioner).to receive(:config).and_return(config)
|
15
|
+
allow(data_provisioner).to receive(:provision_server).and_return(provision_server)
|
16
|
+
allow(data_provisioner).to receive(:print)
|
17
|
+
allow(data_provisioner).to receive(:puts)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#call" do
|
21
|
+
it "dumps, transfers, and loads database data" do
|
22
|
+
expect(server).to receive(:run!).with("bin/rake db:dump")
|
23
|
+
expect(server).to receive(:copy_file).with("db/data.sql.gz", to: provision_server, verbose: false)
|
24
|
+
expect(provision_server).to receive(:run!).with("bin/rake db:load")
|
25
|
+
|
26
|
+
allow(server).to receive(:copy_dir)
|
27
|
+
|
28
|
+
data_provisioner.call
|
29
|
+
end
|
30
|
+
|
31
|
+
it "synchronizes configured data directories" do
|
32
|
+
allow(server).to receive(:run!)
|
33
|
+
allow(server).to receive(:copy_file)
|
34
|
+
allow(provision_server).to receive(:run!)
|
35
|
+
|
36
|
+
expect(server).to receive(:copy_dir).with("uploads", to: provision_server, verbose: false)
|
37
|
+
expect(server).to receive(:copy_dir).with("assets", to: provision_server, verbose: false)
|
38
|
+
|
39
|
+
data_provisioner.call
|
40
|
+
end
|
41
|
+
|
42
|
+
it "prints status messages" do
|
43
|
+
allow(server).to receive(:run!)
|
44
|
+
allow(server).to receive(:copy_file)
|
45
|
+
allow(server).to receive(:copy_dir)
|
46
|
+
allow(provision_server).to receive(:run!)
|
47
|
+
|
48
|
+
expect(data_provisioner).to receive(:print).with("Data:")
|
49
|
+
expect(data_provisioner).to receive(:puts).with(" ✓")
|
50
|
+
|
51
|
+
data_provisioner.call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/deploy"
|
4
|
+
|
5
|
+
describe Bard::Provision::Deploy do
|
6
|
+
let(:config) { { production: double("production") } }
|
7
|
+
let(:ssh_url) { "user@example.com" }
|
8
|
+
let(:provision_server) { double("provision_server") }
|
9
|
+
let(:deploy) { Bard::Provision::Deploy.new(config, ssh_url) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(deploy).to receive(:provision_server).and_return(provision_server)
|
13
|
+
allow(deploy).to receive(:print)
|
14
|
+
allow(deploy).to receive(:puts)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#call" do
|
18
|
+
it "runs bin/setup on the server" do
|
19
|
+
expect(provision_server).to receive(:run!).with("bin/setup")
|
20
|
+
|
21
|
+
deploy.call
|
22
|
+
end
|
23
|
+
|
24
|
+
it "prints status messages" do
|
25
|
+
allow(provision_server).to receive(:run!)
|
26
|
+
|
27
|
+
expect(deploy).to receive(:print).with("Deploy:")
|
28
|
+
expect(deploy).to receive(:puts).with(" ✓")
|
29
|
+
|
30
|
+
deploy.call
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/http"
|
4
|
+
|
5
|
+
describe Bard::Provision::HTTP do
|
6
|
+
let(:server) { double("server", ping: ["https://example.com"]) }
|
7
|
+
let(:config) { { production: server } }
|
8
|
+
let(:ssh_url) { "user@example.com" }
|
9
|
+
let(:provision_server) { double("provision_server") }
|
10
|
+
let(:http) { Bard::Provision::HTTP.new(config, ssh_url) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(http).to receive(:server).and_return(server)
|
14
|
+
allow(http).to receive(:provision_server).and_return(provision_server)
|
15
|
+
allow(provision_server).to receive_message_chain(:ssh_uri, :host).and_return("192.168.1.100")
|
16
|
+
allow(http).to receive(:print)
|
17
|
+
allow(http).to receive(:puts)
|
18
|
+
allow(http).to receive(:system)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#call" do
|
22
|
+
context "when HTTP test passes" do
|
23
|
+
it "shows success message" do
|
24
|
+
allow(http).to receive(:system).and_return(true)
|
25
|
+
|
26
|
+
expect(http).to receive(:puts).with(" ✓")
|
27
|
+
|
28
|
+
http.call
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when HTTP test fails" do
|
33
|
+
it "shows failure message" do
|
34
|
+
allow(http).to receive(:system).and_return(false)
|
35
|
+
|
36
|
+
expect(http).to receive(:puts).with(" !!! not serving a rails app from 192.168.1.100")
|
37
|
+
|
38
|
+
http.call
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "prints status header" do
|
43
|
+
allow(http).to receive(:system).and_return(true)
|
44
|
+
|
45
|
+
expect(http).to receive(:print).with("HTTP:")
|
46
|
+
|
47
|
+
http.call
|
48
|
+
end
|
49
|
+
|
50
|
+
it "tests the correct URL" do
|
51
|
+
expected_command = /curl -s --resolve example\.com:80:192\.168\.1\.100 http:\/\/example\.com/
|
52
|
+
expect(http).to receive(:system).with(expected_command)
|
53
|
+
|
54
|
+
http.call
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/logrotation"
|
4
|
+
|
5
|
+
describe Bard::Provision::LogRotation do
|
6
|
+
let(:server) { double("server", project_name: "test_app") }
|
7
|
+
let(:config) { { production: server } }
|
8
|
+
let(:ssh_url) { "user@example.com" }
|
9
|
+
let(:provision_server) { double("provision_server") }
|
10
|
+
let(:logrotation) { Bard::Provision::LogRotation.new(config, ssh_url) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(logrotation).to receive(:server).and_return(server)
|
14
|
+
allow(logrotation).to receive(:provision_server).and_return(provision_server)
|
15
|
+
allow(logrotation).to receive(:print)
|
16
|
+
allow(logrotation).to receive(:puts)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#call" do
|
20
|
+
it "sets up log rotation config on the server" do
|
21
|
+
expect(provision_server).to receive(:run!).with(/file=\/etc\/logrotate\.d\/test_app/, quiet: true)
|
22
|
+
|
23
|
+
logrotation.call
|
24
|
+
end
|
25
|
+
|
26
|
+
it "prints status messages" do
|
27
|
+
allow(provision_server).to receive(:run!)
|
28
|
+
expect(logrotation).to receive(:print).with("Log Rotation:")
|
29
|
+
expect(logrotation).to receive(:puts).with(" ✓")
|
30
|
+
|
31
|
+
logrotation.call
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/masterkey"
|
4
|
+
|
5
|
+
describe Bard::Provision::MasterKey do
|
6
|
+
let(:config) { { production: double("production") } }
|
7
|
+
let(:ssh_url) { "user@example.com" }
|
8
|
+
let(:provision_server) { double("provision_server") }
|
9
|
+
let(:master_key) { Bard::Provision::MasterKey.new(config, ssh_url) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(master_key).to receive(:provision_server).and_return(provision_server)
|
13
|
+
allow(master_key).to receive(:print)
|
14
|
+
allow(master_key).to receive(:puts)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#call" do
|
18
|
+
context "when master.key exists locally" do
|
19
|
+
before do
|
20
|
+
allow(File).to receive(:exist?).with("config/master.key").and_return(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "uploads master.key if not present on server" do
|
24
|
+
allow(provision_server).to receive(:run).with("[ -f config/master.key ]", quiet: true).and_return(false)
|
25
|
+
|
26
|
+
copy_double = double("copy")
|
27
|
+
expect(Bard::Copy).to receive(:new).with("config/master.key").and_return(copy_double)
|
28
|
+
expect(copy_double).to receive(:scp_using_local).with(:to, provision_server)
|
29
|
+
|
30
|
+
master_key.call
|
31
|
+
end
|
32
|
+
|
33
|
+
it "skips upload if master.key already exists on server" do
|
34
|
+
allow(provision_server).to receive(:run).with("[ -f config/master.key ]", quiet: true).and_return(true)
|
35
|
+
|
36
|
+
expect(Bard::Copy).not_to receive(:new)
|
37
|
+
|
38
|
+
master_key.call
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when master.key doesn't exist locally" do
|
43
|
+
before do
|
44
|
+
allow(File).to receive(:exist?).with("config/master.key").and_return(false)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "skips the upload" do
|
48
|
+
expect(Bard::Copy).not_to receive(:new)
|
49
|
+
|
50
|
+
master_key.call
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "prints status messages" do
|
55
|
+
allow(File).to receive(:exist?).and_return(false)
|
56
|
+
|
57
|
+
expect(master_key).to receive(:print).with("Master Key:")
|
58
|
+
expect(master_key).to receive(:puts).with(" ✓")
|
59
|
+
|
60
|
+
master_key.call
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bard/provision"
|
3
|
+
require "bard/provision/mysql"
|
4
|
+
|
5
|
+
describe Bard::Provision::MySQL do
|
6
|
+
let(:config) { { production: double("production") } }
|
7
|
+
let(:ssh_url) { "user@example.com" }
|
8
|
+
let(:provision_server) { double("provision_server") }
|
9
|
+
let(:mysql) { Bard::Provision::MySQL.new(config, ssh_url) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(mysql).to receive(:provision_server).and_return(provision_server)
|
13
|
+
allow(mysql).to receive(:print)
|
14
|
+
allow(mysql).to receive(:puts)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#call" do
|
18
|
+
context "when MySQL is not responding" do
|
19
|
+
it "installs MySQL" do
|
20
|
+
allow(mysql).to receive(:mysql_responding?).and_return(false)
|
21
|
+
|
22
|
+
expect(provision_server).to receive(:run!).with(/sudo apt-get install -y mysql-server/, home: true)
|
23
|
+
|
24
|
+
mysql.call
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when MySQL is already responding" do
|
29
|
+
it "skips installation" do
|
30
|
+
allow(mysql).to receive(:mysql_responding?).and_return(true)
|
31
|
+
|
32
|
+
expect(provision_server).not_to receive(:run!)
|
33
|
+
|
34
|
+
mysql.call
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "prints status messages" do
|
39
|
+
allow(mysql).to receive(:mysql_responding?).and_return(true)
|
40
|
+
|
41
|
+
expect(mysql).to receive(:print).with("MySQL:")
|
42
|
+
expect(mysql).to receive(:puts).with(" ✓")
|
43
|
+
|
44
|
+
mysql.call
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#mysql_responding?" do
|
49
|
+
it "checks if MySQL service is active" do
|
50
|
+
expect(provision_server).to receive(:run).with("sudo systemctl is-active --quiet mysql", home: true, quiet: true)
|
51
|
+
|
52
|
+
mysql.mysql_responding?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|