bard 1.9.1 → 1.9.2

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: 9d66092e3bc2b19b6010e668ead98981db7d41ce14434be33b02caa7c7c23e97
4
- data.tar.gz: bbe41031b2b9c5974069bae36a5606063d3d4a75f43bf86ac61787b60e12eb9b
3
+ metadata.gz: '09960cdea14d636cd11c29d1f88114783daf97c144b379645daee11077f58815'
4
+ data.tar.gz: 52089e9a96cd8aacb4e49bb075b03199e18f138bffdb6bc6e86d5f8262a017a3
5
5
  SHA512:
6
- metadata.gz: d13c12fc322c9cdcfa2ae0c8a6a5fd9c4e033e026ef423823494d02f63eec55a5bd1a7268689017b56bf7e4243ece08f2b041d41958b751f2808d5403529d745
7
- data.tar.gz: 26a9703810bc8c2063803a8efc8720ca2bb9e9f6cb82667e18b00297b76256a745434a453cabd1bb6f1966337a6b1b27e6bcd62674671922d300ccdad53e25e3
6
+ metadata.gz: 564cb4579c1a1451c2281e03f6541f621fc82e5be5e9ac2170e3c06838382d84bb860e02ada2670f444bf319ab62f5a42ff50a574b48c582a9dd304bf5075122
7
+ data.tar.gz: b20e398b8b8e87b177c365944c157f40083231f9478da9555a324eb9f60a929abe4995ba52e421107e8ff501aebc497232ada569fc3aa53647d21537c1c4fb31
@@ -22,7 +22,7 @@ class Bard::CLI::Provision < Bard::CLI::Command
22
22
 
23
23
  desc "provision [ssh_url] --steps=all", "takes an optional ssh url to a raw ubuntu 22.04 install, and readies it in the shape of :production"
24
24
  option :steps, type: :array, default: STEPS
25
- def provision ssh_url=config[:production].ssh
25
+ def provision ssh_url=config[:production].ssh&.to_s
26
26
  # unfreeze the string for later mutation
27
27
  ssh_url = ssh_url.dup
28
28
  options[:steps].each do |step|
data/lib/bard/command.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "open3"
2
+ require "shellwords"
2
3
 
3
4
  module Bard
4
5
  class Command < Struct.new(:command, :on, :home)
@@ -100,7 +101,7 @@ module Bard
100
101
  end
101
102
  end
102
103
 
103
- cmd = "ssh #{ssh_opts.join(' ')} #{ssh_target} '#{cmd}'"
104
+ cmd = "ssh #{ssh_opts.join(' ')} #{ssh_target} #{Shellwords.shellescape(cmd)}"
104
105
 
105
106
  cmd += " 2>&1" if quiet
106
107
  cmd
@@ -5,7 +5,7 @@ class Bard::Provision::LogRotation < Bard::Provision
5
5
  print "Log Rotation:"
6
6
 
7
7
  provision_server.run! <<~SH, quiet: true
8
- file=/etc/logrotate.d/#{server.project_name}
8
+ file=/etc/logrotate.d/#{config.project_name}
9
9
  if [ ! -f $file ]; then
10
10
  sudo tee $file > /dev/null <<EOF
11
11
  $(pwd)/log/*.log {
@@ -9,7 +9,7 @@ class Bard::Provision::Passenger < Bard::Provision
9
9
  %(grep -qxF "RAILS_ENV=production" /etc/environment || echo "RAILS_ENV=production" | sudo tee -a /etc/environment),
10
10
  %(grep -qxF "EDITOR=vim" /etc/environment || echo "EDITOR=vim" | sudo tee -a /etc/environment),
11
11
  "sudo apt-get install -y vim dirmngr gnupg apt-transport-https ca-certificates",
12
- "curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null",
12
+ "curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key-2025.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null",
13
13
  %(echo "deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main" | sudo tee /etc/apt/sources.list.d/passenger.list),
14
14
  "sudo apt-get update -y",
15
15
  "sudo apt-get install -y nginx libnginx-mod-http-passenger",
@@ -30,7 +30,7 @@ class Bard::Provision::Passenger < Bard::Provision
30
30
  end
31
31
 
32
32
  def app_configured?
33
- provision_server.run "[ -f /etc/nginx/sites-enabled/#{server.project_name} ]", quiet: true
33
+ provision_server.run "[ -f /etc/nginx/sites-enabled/#{config.project_name} ]", quiet: true
34
34
  end
35
35
  end
36
36
 
@@ -16,7 +16,7 @@ class Bard::Provision::Repo < Bard::Provision
16
16
  print " Add public key to GitHub repo deploy keys,"
17
17
  title = "#{server.ssh_uri.user}@#{server.ssh_uri.host}"
18
18
  key = provision_server.run "cat ~/.ssh/id_rsa.pub", home: true
19
- Bard::Github.new(server.project_name).add_deploy_key title:, key:
19
+ Bard::Github.new(config.project_name).add_deploy_key title:, key:
20
20
  end
21
21
  print " Cloning repo,"
22
22
  provision_server.run! "git clone git@github.com:botandrosedesign/#{project_name}", home: true
@@ -50,7 +50,7 @@ class Bard::Provision::Repo < Bard::Provision
50
50
  end
51
51
 
52
52
  def project_name
53
- server.project_name
53
+ config.project_name
54
54
  end
55
55
 
56
56
  def on_latest_master?
@@ -4,7 +4,7 @@ class Bard::Provision::Swapfile < Bard::Provision
4
4
  def call
5
5
  print "Swapfile:"
6
6
 
7
- provision_server.run! <<~SH
7
+ provision_server.run! <<~SH, home: true
8
8
  if [ ! -f /swapfile ]; then
9
9
  sudo fallocate -l $(grep MemTotal /proc/meminfo | awk '{print $2}')K /swapfile
10
10
  fi
@@ -14,6 +14,8 @@ class Bard::Provision::Swapfile < Bard::Provision
14
14
  grep -q '/swapfile none swap sw 0 0' /etc/fstab || echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
15
15
  SH
16
16
 
17
+ provision_server.run! "sudo swapon --show | grep -q /swapfile", home: true
18
+
17
19
  puts " ✓"
18
20
  end
19
21
  end
@@ -1,4 +1,5 @@
1
1
  require "uri"
2
+ require "shellwords"
2
3
  require "bard/command"
3
4
 
4
5
  module Bard
@@ -30,6 +31,12 @@ module Bard
30
31
  host
31
32
  end
32
33
 
34
+ def to_s
35
+ str = "#{user}@#{host}"
36
+ str += ":#{port}" if port && port != "22"
37
+ str
38
+ end
39
+
33
40
  def connection_string
34
41
  "#{user}@#{host}"
35
42
  end
@@ -93,7 +100,7 @@ module Bard
93
100
  remote_cmd += "cd #{path} && " if path
94
101
  remote_cmd += command
95
102
 
96
- cmd += " '#{remote_cmd}'"
103
+ cmd += " #{Shellwords.shellescape(remote_cmd)}"
97
104
  cmd
98
105
  end
99
106
  end
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "1.9.1"
2
+ VERSION = "1.9.2"
3
3
  end
4
4
 
@@ -1,5 +1,6 @@
1
1
  require "spec_helper"
2
2
  require "bard/command"
3
+ require "shellwords"
3
4
 
4
5
  describe Bard::Command do
5
6
  let(:remote) { double("remote", to_sym: :remote, ssh: true, env: nil, path: "/path/to", ssh_key: nil, ssh_uri: "user@example.com", gateway: nil) }
@@ -11,7 +12,8 @@ describe Bard::Command do
11
12
  end
12
13
 
13
14
  it "should run a command on a remote server" do
14
- expect(Open3).to receive(:capture3).with("ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR user@example.com 'cd /path/to && ls -l'").and_return(["output", "", 0])
15
+ expected_cmd = "ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR user@example.com #{Shellwords.shellescape("cd /path/to && ls -l")}"
16
+ expect(Open3).to receive(:capture3).with(expected_cmd).and_return(["output", "", 0])
15
17
  Bard::Command.run "ls -l", on: remote
16
18
  end
17
19
  end
@@ -4,7 +4,7 @@ require "bard/provision/logrotation"
4
4
 
5
5
  describe Bard::Provision::LogRotation do
6
6
  let(:server) { double("server", project_name: "test_app") }
7
- let(:config) { { production: server } }
7
+ let(:config) { double("config", project_name: "test_app", :[] => server) }
8
8
  let(:ssh_url) { "user@example.com" }
9
9
  let(:provision_server) { double("provision_server") }
10
10
  let(:logrotation) { Bard::Provision::LogRotation.new(config, ssh_url) }
@@ -4,7 +4,7 @@ require "bard/provision/passenger"
4
4
 
5
5
  describe Bard::Provision::Passenger do
6
6
  let(:server) { double("server", project_name: "test_app") }
7
- let(:config) { { production: server } }
7
+ let(:config) { double("config", project_name: "test_app", :[] => server) }
8
8
  let(:ssh_url) { "user@example.com" }
9
9
  let(:provision_server) { double("provision_server") }
10
10
  let(:passenger) { Bard::Provision::Passenger.new(config, ssh_url) }
@@ -5,7 +5,7 @@ require "bard/provision/repo"
5
5
  describe Bard::Provision::Repo do
6
6
  let(:ssh_uri) { double("ssh_uri", user: "deploy", host: "example.com") }
7
7
  let(:server) { double("server", ssh_uri: ssh_uri, project_name: "test_project") }
8
- let(:config) { { production: server } }
8
+ let(:config) { double("config", project_name: "test_project", :[] => server) }
9
9
  let(:ssh_url) { "deploy@example.com" }
10
10
  let(:provision_server) { double("provision_server") }
11
11
  let(:github_api) { double("github_api") }
@@ -16,7 +16,8 @@ describe Bard::Provision::Swapfile do
16
16
 
17
17
  describe "#call" do
18
18
  it "sets up swapfile on the server" do
19
- expect(provision_server).to receive(:run!).with(/if \[ ! -f \/swapfile \]/)
19
+ expect(provision_server).to receive(:run!).with(/if \[ ! -f \/swapfile \]/, home: true).ordered
20
+ expect(provision_server).to receive(:run!).with("sudo swapon --show | grep -q /swapfile", home: true).ordered
20
21
 
21
22
  swapfile.call
22
23
  end
@@ -81,7 +81,7 @@ describe Bard::SSHServer do
81
81
 
82
82
  it "executes command via SSH" do
83
83
  expect(Open3).to receive(:capture3)
84
- .with(/ssh.*deploy@example.com.*cd \/app && ls/)
84
+ .with(/ssh.*deploy@example.com.*cd.+\/app.+ls/)
85
85
  .and_return(["output", "", 0])
86
86
 
87
87
  server.run("ls")
@@ -94,7 +94,7 @@ describe Bard::SSHServer do
94
94
  )
95
95
 
96
96
  expect(Open3).to receive(:capture3)
97
- .with(/RAILS_ENV=production/)
97
+ .with(/RAILS_ENV.*production/)
98
98
  .and_return(["output", "", 0])
99
99
 
100
100
  server_with_env.run("ls")
@@ -108,7 +108,7 @@ describe Bard::SSHServer do
108
108
 
109
109
  it "executes command via SSH" do
110
110
  expect(Open3).to receive(:capture3)
111
- .with(/ssh.*deploy@example.com.*cd \/app && ls/)
111
+ .with(/ssh.*deploy@example.com.*cd.+\/app.+ls/)
112
112
  .and_return(["output", "", 0])
113
113
 
114
114
  server.run!("ls")
@@ -129,7 +129,7 @@ describe Bard::SSHServer do
129
129
 
130
130
  it "replaces current process with SSH command" do
131
131
  expect(server).to receive(:exec)
132
- .with(/ssh.*deploy@example.com.*cd \/app && ls/)
132
+ .with(/ssh.*deploy@example.com.*cd.+\/app.+ls/)
133
133
 
134
134
  server.exec!("ls")
135
135
  end
@@ -140,7 +140,7 @@ describe Bard::SSHServer do
140
140
  server = described_class.new("deploy@example.com:22", path: "/var/www/app")
141
141
 
142
142
  expect(Open3).to receive(:capture3)
143
- .with(/cd \/var\/www\/app && ls/)
143
+ .with(/cd.+\/var\/www\/app.+ls/)
144
144
  .and_return(["output", "", 0])
145
145
 
146
146
  server.run("ls")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-02-11 00:00:00.000000000 Z
10
+ date: 2026-02-12 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor