bard-api 0.6.3 → 0.6.4

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: e51131122902484d133bcaaf0ca3f01abea607acf01b6b89a7459ad99a5afe45
4
- data.tar.gz: 713e9aac75181d545f6807259a8031c96064b58fc6c02d32e1bdea5f870cc154
3
+ metadata.gz: d007a479b7de5d4e3508479577848275fc7a9cdf50b73df55767eb09d1318f6c
4
+ data.tar.gz: 3f5580a11475da6bfe7676027a4e571599731f325acc92a19f8afff134babcb5
5
5
  SHA512:
6
- metadata.gz: 8294f16c4750b0e560ecb26477a24527dbb29a229cec6e200fd6494d2d31b88bccbd3f0041516aeb1db87d36c1361e7bae678a0d66035aead9d92e86983f2716
7
- data.tar.gz: 445de7f208e078a97efe9ec981556d585540003828c60d07de236ea736edae2433e6f9bc0afee3949a1c56267c407761822186328f427fb157cb05ee4780c75d
6
+ metadata.gz: a6e68bfb8c288f7c8dd4a1027bd44b511a30917f1e60cdbee3f5df7d05cbab6ca566e3eb94a7affd433924c15b2b808e4a95ebbbd88e1eef8d42335b7e396e19
7
+ data.tar.gz: 40d72eaa6bc942c5aa16f1afc2d325012afd18d2effb4cc085a016b28d29da0d1721e0da0c8034af9b9684311dd8f7dd1f34ce685b822b3ac97381808a6cb7e0
data/lib/bard/api/app.rb CHANGED
@@ -26,22 +26,32 @@ module Bard
26
26
  @deploy_runner ||= method(:spawn_detached_deploy)
27
27
  end
28
28
 
29
- # with_unbundled_env is essential: this worker runs under the app's bundle
29
+ # The deploy must start from a clean env: this worker runs under the app's bundle
30
30
  # (RUBYOPT=-rbundler/setup, BUNDLE_GEMFILE). Inherited into the deploy, that makes every
31
- # ruby command — bundle install included — crash at startup the moment git pull lands a
32
- # lockfile with not-yet-installed gems. The deploy must start from a clean env.
31
+ # ruby command — bin/setup and bundle install included — crash at startup the moment
32
+ # git pull lands a lockfile with not-yet-installed gems.
33
33
  def spawn_detached_deploy(command)
34
34
  Bundler.with_unbundled_env do
35
- # A Passenger web worker is spawned without a login session, so it has no XDG_RUNTIME_DIR;
36
- # systemd-run --user needs it to find the (linger-backed) user bus at $XDG_RUNTIME_DIR/bus.
37
35
  pid = Process.spawn(
38
- { "XDG_RUNTIME_DIR" => "/run/user/#{Process.uid}" },
36
+ deploy_env,
39
37
  "systemd-run", "--user", "--scope", "--collect", "--quiet", "bash", "-lc", command,
40
38
  :in => "/dev/null", %i[out err] => ["log/bard-deploy.log", "a"],
41
39
  )
42
40
  Process.detach(pid)
43
41
  end
44
42
  end
43
+
44
+ # with_unbundled_env alone isn't enough: it restores Bundler::ORIGINAL_ENV, and under
45
+ # Passenger RUBYOPT=-rbundler/setup is injected before the app boots, so it's part of
46
+ # ORIGINAL_ENV and survives the scrub (took brianporter.com down on 2026-07-15). Strip
47
+ # the bundler vars explicitly — nil values remove them from the spawned env.
48
+ # XDG_RUNTIME_DIR: a Passenger web worker is spawned without a login session, so it's
49
+ # unset; systemd-run --user needs it to find the (linger-backed) user bus.
50
+ def deploy_env
51
+ bundler_vars = ENV.keys.grep(/\A(BUNDLE_|BUNDLER_)/) + %w[RUBYOPT RUBYLIB]
52
+ bundler_vars.to_h { |key| [key, nil] }
53
+ .merge("XDG_RUNTIME_DIR" => "/run/user/#{Process.uid}")
54
+ end
45
55
  end
46
56
 
47
57
  DEPLOY_LOCK = "tmp/bard-deploy.lock"
@@ -56,11 +66,15 @@ module Bard
56
66
  # HEAD before the bundle/migrate/restart run, so HEAD alone would read as "done" too early.
57
67
  # On any failure, stamp the attempted sha so we don't re-spawn (and restart Puma) on every
58
68
  # poll; the marker is written inside the flock, so it's on disk before the lock releases.
69
+ # Then roll the tree back to the pre-pull sha: code sitting ahead of its installed gems is
70
+ # a time bomb — the next app-process respawn (e.g. an nginx reload) can't boot and the
71
+ # site 500s until someone intervenes. Better to keep running the old code.
59
72
  DEPLOY_COMMAND =
60
73
  "flock -n #{DEPLOY_LOCK} -c '" \
61
74
  "rm -f #{FAILED_SHA}; " \
75
+ "before=$(git rev-parse HEAD); " \
62
76
  "git pull --ff-only origin master && bin/setup && git rev-parse HEAD > #{DEPLOYED_SHA} " \
63
- "|| git rev-parse origin/master > #{FAILED_SHA}'"
77
+ "|| { git rev-parse origin/master > #{FAILED_SHA}; git reset --hard \"$before\"; }'"
64
78
 
65
79
  def call(env)
66
80
  request = Rack::Request.new(env)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bard
4
4
  module Api
5
- VERSION = "0.6.3"
5
+ VERSION = "0.6.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-07-10 00:00:00.000000000 Z
10
+ date: 2026-07-15 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: jwt