Skip to content

Commit dd8b418

Browse files
authored
Make devcontainer work with ancient Ruby/Rails (#2679)
* [rails] fix bundling for older rubies * [e2e] completely relax rails version requirement This is just for convenience so that it can bundle under various rubies * [.devcontainer] add libsqlite3-dev Needed by sqlite3 1.4.0 gem * [.devcontainer] fix git command for older git * [.devcontainer] make it work under ancient rubies Notice that it now removes locks, a cleaner solution would be to go multi-lock - and I tried - and then gave up due to time constraints. Something to revisit in the future.
1 parent 9b37693 commit dd8b418

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2020
libffi-dev \
2121
libgdbm-dev \
2222
sqlite3 \
23+
libsqlite3-dev \
2324
nodejs \
2425
npm \
2526
chromium \

.devcontainer/run

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ cd /workspace/sentry
77
sudo mkdir -p vendor/gems
88
sudo chown -R sentry:sentry vendor/gems
99

10-
git config --global --add safe.directory /workspace/sentry
11-
git config --global --add safe.directory /workspace/sentry/vendor/gems/*
10+
git config --global safe.directory /workspace/sentry
11+
git config --global safe.directory /workspace/sentry/vendor/gems/*
1212

1313
sudo chown -R sentry:sentry .
1414

.devcontainer/setup

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SetupScript
3535

3636
if should_run_bundle?
3737
cleanup_ruby_lsp_directories
38+
update_rubygems_and_bundler
3839
install_bundle_dependencies
3940
install_foreman_gem if @options[:with_foreman]
4041
end
@@ -121,7 +122,8 @@ class SetupScript
121122
if Dir.exist?(folder_path) && File.exist?(gemfile_path)
122123
Dir.chdir(folder_path) do
123124
puts " Installing dependencies for #{folder_path}..."
124-
unless system('bundle install')
125+
126+
unless system("[ -f Gemfile.lock ] && rm Gemfile.lock; bundle install")
125127
puts "❌ Bundle install failed for #{folder}"
126128
exit 1
127129
end
@@ -134,6 +136,28 @@ class SetupScript
134136
end
135137
end
136138

139+
def update_rubygems_and_bundler
140+
puts "📦 Updating RubyGems and Bundler..."
141+
142+
if RUBY_VERSION >= "3.0"
143+
unless system("sudo gem update --system --silent")
144+
puts "❌ RubyGems update failed"
145+
exit 1
146+
end
147+
else
148+
unless system("sudo gem update --silent --system 3.4.22")
149+
puts "❌ RubyGems update failed"
150+
exit 1
151+
end
152+
153+
# sentry-sidekiq does not bundle with Bundler 2.5.x that ships with RubyGems 3.4.22
154+
unless system("sudo gem install bundler -v 2.4.22")
155+
puts "❌ Bundler installation failed"
156+
exit 1
157+
end
158+
end
159+
end
160+
137161
def install_foreman_gem
138162
unless system('gem install foreman')
139163
puts "❌ Foreman gem installation failed"

sentry-rails/Gemfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ end
1616

1717
ruby_version = Gem::Version.new(RUBY_VERSION)
1818

19-
rails_version = ENV["RAILS_VERSION"]
20-
rails_version = "8.0.0" if rails_version.nil?
19+
rails_version = ENV.fetch("RAILS_VERSION") do
20+
if ruby_version >= Gem::Version.new("3.2")
21+
"8.0"
22+
elsif ruby_version >= Gem::Version.new("3.1")
23+
"7.2"
24+
elsif ruby_version >= Gem::Version.new("2.7")
25+
"7.1"
26+
elsif ruby_version >= Gem::Version.new("2.4")
27+
"5.2"
28+
end
29+
end
30+
2131
rails_version = Gem::Version.new(rails_version)
2232

2333
gem "rails", "~> #{rails_version}"

spec/apps/rails-mini/Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
44

55
gem "rake"
66
gem "puma"
7-
gem 'railties', '~> 8.0'
8-
gem 'actionpack', '~> 8.0'
7+
gem 'railties'
8+
gem 'actionpack'
99
gem 'sentry-ruby', path: Pathname(__dir__).join("../../..").realpath
1010
gem 'sentry-rails', path: Pathname(__dir__).join("../../..").realpath

0 commit comments

Comments
 (0)