bard 2.0.0 → 2.0.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: 24a9ee78c591a6446ac1bb749225497c75470e12e4fe822d96e975870ac88152
4
- data.tar.gz: 2b8ae0acbf1237b3312957128130f399a516a3a19d52d45f63c7b0677952e4f2
3
+ metadata.gz: a1541cf273c6f77dc3fe0910f17aff570de984eb1858ffb97267c5fc6be80709
4
+ data.tar.gz: a02d6f359c62fa2bddd91dcd5052069d9901414011107fa0c98dbfcf674f7323
5
5
  SHA512:
6
- metadata.gz: 55a1a4f6fcf3bf12201105974a619be5178c3c9c6367d8dccf2eef1e7e504880a869a6291dfb5024930e025f63d8cf2f22c8925cf5fc24f9e83d2aa85ed047ed
7
- data.tar.gz: 5da5d707ceed5ca663e4a68cd4a2ba2afbb232052e4a0542a4e41a1badc0161ba4eda410195b717d21f8fdaea299af771afa6a19310d93b66915996e8579b5fa
6
+ metadata.gz: 788e7863ff3543dc464dbe7f84ae70e8931017a99feed5bfcb00492204afeec60ead608cbaec06be2a4521055021d27577ef75abfa17ee688c6790d4a51b6d0f
7
+ data.tar.gz: e726331d4aec855d5ee6727a2ce09435f92ae42d083ee38afe4d08685da23c6f45a173e1d4b58f10a2803d7bbe92f2927ec1fc632e9d1ef2507299d62fe107f0
@@ -1,6 +1,7 @@
1
1
  require "bard/plugins/deploy/strategy"
2
2
  require "bard/plugins/git"
3
3
  require "fileutils"
4
+ require "socket"
4
5
  require "uri"
5
6
 
6
7
  module Bard
@@ -19,6 +20,7 @@ module Bard
19
20
  @build_dir = "tmp/github-build-#{@sha}"
20
21
  @branch = "gh-pages"
21
22
  @domain = extract_domain
23
+ @port = pick_free_port
22
24
 
23
25
  puts "Starting deployment to GitHub Pages..."
24
26
 
@@ -37,27 +39,46 @@ module Bard
37
39
  domain
38
40
  end
39
41
 
42
+ def pick_free_port
43
+ server = TCPServer.new("127.0.0.1", 0)
44
+ port = server.addr[1]
45
+ server.close
46
+ port
47
+ end
48
+
40
49
  def build_site
41
50
  system "rm -rf #{@build_dir.sub(@sha, "*")}"
42
51
  run! <<~SH
43
52
  set -e
44
- RAILS_ENV=production bundle exec rails s -p 3000 -d --pid tmp/pids/server.pid
53
+ PORT=#{@port}
54
+
45
55
  OUTPUT=$(bundle exec rake assets:clean assets:precompile 2>&1) || echo "$OUTPUT"
46
56
 
47
- # Create the output directory and enter it
48
57
  BUILD=#{@build_dir}
49
58
  rm -rf $BUILD
50
59
  mkdir -p $BUILD
51
60
  cp -R public/assets $BUILD/
52
- cd $BUILD
53
61
 
54
- # wait until server responds
62
+ # Start rails in the foreground, backgrounded — NOT as a daemon —
63
+ # so a port-bind failure surfaces instead of being swallowed by fork.
64
+ rm -f tmp/pids/server.pid
65
+ RAILS_ENV=production bundle exec rails s -p $PORT -P tmp/pids/server.pid >tmp/pids/server.log 2>&1 &
66
+ RAILS_PID=$!
67
+
55
68
  echo waiting...
56
- curl -s --retry 5 --retry-delay 2 http://localhost:3000 >/dev/null 2>&1
69
+ for i in $(seq 1 30); do
70
+ if ! kill -0 $RAILS_PID 2>/dev/null; then
71
+ echo "Rails server failed to start on port $PORT:"
72
+ cat tmp/pids/server.log
73
+ exit 1
74
+ fi
75
+ curl -sf http://localhost:$PORT >/dev/null 2>&1 && break
76
+ sleep 1
77
+ done
57
78
 
79
+ cd $BUILD
58
80
  echo copying...
59
- # Mirror the site to the build folder, ignoring links with query params
60
- wget -nv -r -l inf --no-remove-listing -FEnH --reject-regex "(\\.*)\\?(.*)" http://localhost:3000/ 2>&1
81
+ wget -nv -r -l inf --no-remove-listing -FEnH --reject-regex "(\\.*)\\?(.*)" http://localhost:$PORT/ 2>&1
61
82
 
62
83
  echo #{@domain} > CNAME
63
84
  SH
@@ -5,35 +5,7 @@ class Bard::CLI
5
5
  desc "setup", "installs app in nginx"
6
6
  def setup
7
7
  path = "/etc/nginx/sites-available/#{project_name}"
8
- system "sudo tee #{path} >/dev/null <<-'EOF'
9
- upstream puma {
10
- server 127.0.0.1:3000 fail_timeout=5;
11
- }
12
-
13
- server {
14
- listen 80;
15
- server_name #{nginx_server_name};
16
- root #{Dir.pwd}/public;
17
-
18
- try_files $uri @app;
19
-
20
- location @app {
21
- proxy_pass http://puma;
22
- proxy_set_header Host $host;
23
- proxy_set_header X-Real-IP $remote_addr;
24
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
25
- proxy_set_header X-Forwarded-Proto $scheme;
26
- }
27
-
28
- location ~* \\-[0-9a-f]\\{64\\}\\.(ico|css|js|gif|jpe?g|png|webp)$ {
29
- access_log off;
30
- expires max;
31
- add_header Cache-Control public;
32
- }
33
-
34
- gzip_static on;
35
- }
36
- EOF"
8
+ system "sudo tee #{path} >/dev/null <<-'EOF'\n#{nginx_config}EOF"
37
9
 
38
10
  dest_path = path.sub("sites-available", "sites-enabled")
39
11
  system "sudo ln -sf #{path} #{dest_path}" if !File.exist?(dest_path)
@@ -42,6 +14,55 @@ EOF"
42
14
  end
43
15
 
44
16
  no_commands do
17
+ def nginx_config
18
+ case ENV["RAILS_ENV"]
19
+ when "production", "staging" then nginx_production_config
20
+ else nginx_development_config
21
+ end
22
+ end
23
+
24
+ def nginx_development_config
25
+ <<~EOF
26
+ server {
27
+ include /etc/nginx/snippets/common.conf;
28
+ server_name #{nginx_server_name};
29
+ root #{Dir.pwd}/public;
30
+ }
31
+ EOF
32
+ end
33
+
34
+ def nginx_production_config
35
+ <<~EOF
36
+ upstream puma {
37
+ server 127.0.0.1:3000 fail_timeout=5;
38
+ }
39
+
40
+ server {
41
+ listen 80;
42
+ server_name #{nginx_server_name};
43
+ root #{Dir.pwd}/public;
44
+
45
+ try_files $uri @app;
46
+
47
+ location @app {
48
+ proxy_pass http://puma;
49
+ proxy_set_header Host $host;
50
+ proxy_set_header X-Real-IP $remote_addr;
51
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
52
+ proxy_set_header X-Forwarded-Proto $scheme;
53
+ }
54
+
55
+ location ~* \\-[0-9a-f]\\{64\\}\\.(ico|css|js|gif|jpe?g|png|webp)$ {
56
+ access_log off;
57
+ expires max;
58
+ add_header Cache-Control public;
59
+ }
60
+
61
+ gzip_static on;
62
+ }
63
+ EOF
64
+ end
65
+
45
66
  def nginx_server_name
46
67
  case ENV["RAILS_ENV"]
47
68
  when "production"
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.2"
3
3
  end
4
4
 
@@ -12,16 +12,40 @@ describe "bard setup" do
12
12
  end
13
13
 
14
14
  describe "#setup" do
15
+ before { allow(cli).to receive(:nginx_server_name).and_return("test_project.localhost") }
16
+
15
17
  it "should have a setup command" do
16
18
  expect(cli).to respond_to(:setup)
17
19
  end
18
20
 
19
- it "should create nginx reverse proxy config" do
20
- expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project.*proxy_pass http:\/\/puma/m)
21
- expect(cli).to receive(:system).with(/sudo ln -sf/)
22
- expect(cli).to receive(:system).with("sudo service nginx restart")
21
+ context "in production" do
22
+ before do
23
+ allow(ENV).to receive(:[]).and_call_original
24
+ allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("production")
25
+ end
26
+
27
+ it "creates an nginx reverse proxy config" do
28
+ expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project.*proxy_pass http:\/\/puma/m)
29
+ expect(cli).to receive(:system).with(/sudo ln -sf/)
30
+ expect(cli).to receive(:system).with("sudo service nginx restart")
31
+
32
+ cli.setup
33
+ end
34
+ end
35
+
36
+ context "in development" do
37
+ before do
38
+ allow(ENV).to receive(:[]).and_call_original
39
+ allow(ENV).to receive(:[]).with("RAILS_ENV").and_return("development")
40
+ end
23
41
 
24
- cli.setup
42
+ it "creates an nginx config that includes the shared dev snippet" do
43
+ expect(cli).to receive(:system).with(/sudo tee \/etc\/nginx\/sites-available\/test_project.*include \/etc\/nginx\/snippets\/common\.conf/m)
44
+ expect(cli).to receive(:system).with(/sudo ln -sf/)
45
+ expect(cli).to receive(:system).with("sudo service nginx restart")
46
+
47
+ cli.setup
48
+ end
25
49
  end
26
50
  end
27
51
 
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: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-05-17 00:00:00.000000000 Z
10
+ date: 2026-07-01 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor