Skip to content

feat: allow easier selection of the ruby run in the container #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,42 @@ Other environment variables can be set or passed through to the container like t
RakeCompilerDock.sh "rake cross native gem OPENSSL_VERSION=#{ENV['OPENSSL_VERSION']}"
```

### Choosing the version of ruby to run in the build container

There are [multiple versions of Ruby installed in the build container](https://github.com/rake-compiler/rake-compiler-dock/blob/d3e6b44916d9d63d4c431b8c749a2c58bf1fe8e8/Dockerfile.mri.erb#L77). The latest version will be the default, but you may need to choose a different version to run during your build process.

You can do this by passing a `ruby:` keyword argument to `RakeCompilerDock.sh`:

```ruby
RakeCompilerDock.sh "ruby -v"
# => ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]

RakeCompilerDock.sh "ruby -v", ruby: "3.1.6"
# => ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]48d4efcb85) +PRISM [x86_64-linux]
```

Or by setting the environment variable `RCD_RUBY_VERSION`:

``` sh
$ rake-compiler-dock bash -c "ruby -v"
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]

$ RCD_RUBY_VERSION=3.1.6 rake-compiler-dock bash -c "ruby -v"
ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]
```

Or by running `rbenv shell` in the command:

``` ruby
RakeCompilerDock.sh "rbenv shell 3.1.6 && ruby -v", platform: "x86_64-linux-gnu"
# => ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]
```

``` sh
$ rake-compiler-dock bash -c "rbenv shell 3.1.6 && ruby -v"
ruby 3.1.6p260 (2024-05-29 revision a777087be6) [x86_64-linux]
```

### Choosing specific Ruby versions to support

If you only want to precompile for certain Ruby versions, you can specify those versions by overwriting the `RUBY_CC_VERSION` environment variable.
Expand Down
2 changes: 1 addition & 1 deletion build/sudoers
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Defaults env_keep += "http_proxy https_proxy ftp_proxy GEM_PRIVATE_KEY_PASSPHRASE RCD_HOST_RUBY_PLATFORM RCD_HOST_RUBY_VERSION RCD_IMAGE RUBY_CC_VERSION LD_LIBRARY_PATH DEVTOOLSET_ROOTPATH SOURCE_DATE_EPOCH"
Defaults env_keep += "http_proxy https_proxy ftp_proxy GEM_PRIVATE_KEY_PASSPHRASE RCD_HOST_RUBY_PLATFORM RCD_HOST_RUBY_VERSION RCD_IMAGE RUBY_CC_VERSION LD_LIBRARY_PATH DEVTOOLSET_ROOTPATH SOURCE_DATE_EPOCH RBENV_VERSION"
6 changes: 6 additions & 0 deletions lib/rake_compiler_dock/starter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def exec(*args)
user = options.fetch(:username){ current_user }
group = options.fetch(:groupname){ current_group }

ruby_version = options[:ruby] || ENV['RCD_RUBY_VERSION']
rbenv_opts = if ruby_version
["-e", "RBENV_VERSION=#{ruby_version}"]
end

platforms(options).split(" ").each do |platform|
image_name = container_image_name(options.merge(platform: platform))

Expand Down Expand Up @@ -73,6 +78,7 @@ def exec(*args)
"-e", "RCD_HOST_RUBY_PLATFORM=#{RUBY_PLATFORM}",
"-e", "RCD_HOST_RUBY_VERSION=#{RUBY_VERSION}",
"-e", "RCD_IMAGE=#{image_name}",
*rbenv_opts,
"-w", make_valid_path(workdir),
*docker_opts,
image_name,
Expand Down
13 changes: 13 additions & 0 deletions test/test_environment_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ def test_SOURCE_DATE_EPOCH
end
end

class UsingWrapperSpecifyingRuby < UsingWrapper
include Common

def invocation(command)
idir = File.join(File.dirname(__FILE__), '../lib')
"RCD_RUBY_VERSION=3.1.6 RCD_PLATFORM=#{TEST_PLATFORM} RCD_RUBYVM=#{IS_JRUBY ? 'jruby' : 'mri'} #{RbConfig::CONFIG['RUBY_INSTALL_NAME']} -I#{idir.inspect} bin/rake-compiler-dock bash -c '#{command}'"
end

def test_RUBY_VERSION
assert_equal "3.1.6", rcd_env['RBENV_VERSION']
end
end

class AsIfContinuousIntegration < Test::Unit::TestCase
include Common

Expand Down
Loading