Skip to content

Commit 7c231a8

Browse files
committed
Recover from corrupted shared bundle during Capistrano deploys
1 parent 60bfd06 commit 7c231a8

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
namespace :bundler do
4+
desc "Clear a corrupted shared bundle when bundle check reports broken native extensions"
5+
task :recover_shared_bundle do
6+
on fetch(:bundle_servers) do
7+
within release_path do
8+
with fetch(:bundle_env_variables) do
9+
invoke "bundler:config"
10+
11+
check_output = capture(
12+
:bash,
13+
"-lc",
14+
<<~BASH
15+
set +e
16+
output="$(bundle check 2>&1)"
17+
status=$?
18+
printf '%s\n__BUNDLE_CHECK_STATUS__=%s\n' "$output" "$status"
19+
BASH
20+
)
21+
22+
broken_extensions = check_output.include?("because its extensions are not built")
23+
missing_gems = check_output.include?("Bundler::GemNotFound")
24+
25+
next unless broken_extensions || missing_gems
26+
27+
warn "Bundler reported a corrupted shared bundle. Removing #{fetch(:bundle_path)} before reinstalling gems."
28+
execute :rm, "-rf", fetch(:bundle_path)
29+
end
30+
end
31+
end
32+
end
33+
end
34+
35+
before "bundler:install", "bundler:recover_shared_bundle"

0 commit comments

Comments
 (0)