Skip to content

Commit 2a14ea7

Browse files
authored
Merge pull request #119 from rafaelfranca/precompiled
Add opt-in precompiled Ruby installs via mise
2 parents 1b6b4f1 + dbbdffa commit 2a14ea7

15 files changed

Lines changed: 161 additions & 49 deletions

‎AGENTS.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Project Guidelines
2+
3+
## Architecture
4+
- This repo has two main testing domains:
5+
- Ruby tooling code in `lib/` with tests in `test/` (Minitest).
6+
- Dev Container Features in `features/src/*` with integration tests in `features/test/*` (devcontainer CLI + shell scripts/scenarios).
7+
- Entry-point scripts in `bin/` usually orchestrate updates that must be validated by Ruby tests and feature tests.
8+
9+
## Build and Test
10+
- Prefer running the smallest relevant test set first, then broader suites.
11+
12+
### Ruby tests (root)
13+
- Install deps: `bundle install`
14+
- Run all Ruby tests: `bundle exec rake test`
15+
- Equivalent: `rake test`
16+
17+
### Feature tests (from repo root)
18+
- Install Node deps (if needed): `npm install`
19+
- Run all feature tests via package script: `npm test`
20+
- Preferred shortcut via Rake: `rake features:test`
21+
22+
### Feature tests (targeted, from repo root)
23+
- Prerequisite: install project deps from repo root (`npm install`) to get the devcontainer CLI from `package.json`.
24+
- Autogenerated tests for one feature:
25+
- `rake features:autogenerated FEATURE=ruby IMAGE=ubuntu:latest`
26+
- Scenario tests for one feature:
27+
- `rake features:scenarios FEATURE=ruby`
28+
- Direct CLI equivalents (run from `features/`):
29+
- `npx devcontainer features test --skip-scenarios -f ruby -i ubuntu:latest .`
30+
- `npx devcontainer features test -f ruby --skip-autogenerated --skip-duplicated .`
31+
32+
### Shell script linting (from `features/`)
33+
- `find . -name "*.sh" -type f -exec shellcheck {} +`
34+
35+
## Conventions
36+
- Keep tests close to the affected area:
37+
- `lib/**` changes should include/adjust `test/**/*_test.rb`.
38+
- `features/src/<name>/**` changes should include/adjust `features/test/<name>/**`.
39+
- Preserve current patterns in existing tests:
40+
- Ruby tests use Minitest style and temp-directory isolation.
41+
- Feature tests use `dev-container-features-test-lib` assertions (`check`, `reportResults`) and scenario matrices in `scenarios.json`.

‎Rakefile‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "rake/testtask"
4+
require "shellwords"
45

56
Rake::TestTask.new(:test) do |t|
67
t.libs << "test"
@@ -9,3 +10,27 @@ Rake::TestTask.new(:test) do |t|
910
end
1011

1112
task default: :test
13+
14+
namespace :features do
15+
desc "Run all devcontainer feature tests via npm"
16+
task :test do
17+
sh "npm test"
18+
end
19+
20+
desc "Run autogenerated tests for one feature (FEATURE=ruby IMAGE=ubuntu:latest)"
21+
task :autogenerated do
22+
feature = ENV["FEATURE"]
23+
abort "Set FEATURE, for example: rake features:autogenerated FEATURE=ruby" if feature.nil? || feature.empty?
24+
25+
image = ENV.fetch("IMAGE", "ubuntu:latest")
26+
sh "cd features && npx devcontainer features test --skip-scenarios -f #{Shellwords.escape(feature)} -i #{Shellwords.escape(image)} ."
27+
end
28+
29+
desc "Run scenario tests for one feature (FEATURE=ruby)"
30+
task :scenarios do
31+
feature = ENV["FEATURE"]
32+
abort "Set FEATURE, for example: rake features:scenarios FEATURE=ruby" if feature.nil? || feature.empty?
33+
34+
sh "cd features && npx devcontainer features test -f #{Shellwords.escape(feature)} --skip-autogenerated --skip-duplicated ."
35+
end
36+
end

‎features/src/ruby/NOTES.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,16 @@ This Feature should work on recent versions of Debian/Ubuntu-based distributions
2121
}
2222
}
2323
```
24+
25+
## Opting In to Precompiled Rubies with mise
26+
27+
```json
28+
"features": {
29+
"ghcr.io/rails/devcontainer/features/ruby:1": {
30+
"versionManager": "mise",
31+
"usePrecompiledRubies": true
32+
}
33+
}
34+
```
35+
36+
When using `mise`, this feature keeps `ruby.compile=true` by default so Ruby is compiled from source. Set `usePrecompiledRubies` to `true` to make mise prefer precompiled Rubies when they are available.

‎features/src/ruby/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,27 @@ Installs Ruby and a version manager (mise or rbenv) along with the dependencies
3636
}
3737
```
3838

39+
### Opting in to precompiled Rubies with mise
40+
41+
```json
42+
"features": {
43+
"ghcr.io/rails/devcontainer/features/ruby:1": {
44+
"version": "3.3.0",
45+
"versionManager": "mise",
46+
"usePrecompiledRubies": true
47+
}
48+
}
49+
```
50+
51+
When using `mise`, this feature keeps `ruby.compile=true` by default so Ruby is compiled from source. Set `usePrecompiledRubies` to `true` to make mise prefer precompiled Rubies when they are available.
52+
3953
## Options
4054

4155
| Options Id | Description | Type | Default Value |
4256
|-----|-----|-----|-----|
4357
| version | The version of ruby to be installed | string | 4.0.2 |
4458
| versionManager | The version manager to use for Ruby (mise or rbenv) | string | mise |
59+
| usePrecompiledRubies | Use precompiled Rubies with mise when available | boolean | false |
4560

4661
## Customizations
4762

‎features/src/ruby/devcontainer-feature.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "ruby",
3-
"version": "2.1.4",
3+
"version": "2.2.0",
44
"name": "Ruby",
55
"description": "Installs Ruby and a version manager (mise or rbenv) along with libraries needed to build Ruby.",
66
"documentationURL": "https://github.com/rails/devcontainer/tree/main/features/src/ruby",
@@ -30,6 +30,11 @@
3030
],
3131
"default": "mise",
3232
"description": "The version manager to use for Ruby (mise or rbenv)"
33+
},
34+
"usePrecompiledRubies": {
35+
"type": "boolean",
36+
"default": false,
37+
"description": "Use precompiled Rubies with mise when available"
3338
}
3439
}
3540
}

‎features/src/ruby/install.sh‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -e
33

44
USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
55
VERSION_MANAGER="${VERSIONMANAGER:-"mise"}"
6+
USE_PRECOMPILED_RUBIES="${USEPRECOMPILEDRUBIES:-"false"}"
67

78
# Function to install dependencies needed for building Ruby
89
install_dependencies() {
@@ -83,8 +84,20 @@ install_ruby_rbenv() {
8384
# Function to setup mise
8485
setup_mise() {
8586
_user="$1"
87+
_use_precompiled_rubies="$2"
88+
89+
if [ "$_user" = "root" ]; then
90+
_home_dir="/root"
91+
else
92+
_home_dir="/home/$_user"
93+
fi
8694

8795
su "$_user" -c "curl https://mise.run | sh"
96+
if [ "$_use_precompiled_rubies" = "true" ]; then
97+
su "$_user" -c "$_home_dir/.local/bin/mise settings ruby.compile=false"
98+
else
99+
su "$_user" -c "$_home_dir/.local/bin/mise settings ruby.compile=true"
100+
fi
88101

89102
# shellcheck disable=SC2016
90103
add_to_shell_init "$_user" 'eval "$(~/.local/bin/mise activate bash)"' 'eval "$(~/.local/bin/mise activate zsh)"'
@@ -113,7 +126,7 @@ if [ "$VERSION_MANAGER" = "rbenv" ]; then
113126
setup_rbenv "$USERNAME"
114127
install_ruby_rbenv "$USERNAME" "$VERSION"
115128
else
116-
setup_mise "$USERNAME"
129+
setup_mise "$USERNAME" "$USE_PRECOMPILED_RUBIES"
117130
install_ruby_mise "$USERNAME" "$VERSION"
118131
fi
119132

‎features/test/ruby/scenarios.json‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"image": "mcr.microsoft.com/devcontainers/base:2-trixie",
44
"features": {
55
"ruby": {
6-
"version": "3.3.0"
6+
"version": "3.3.0",
7+
"usePrecompiledRubies": true
78
}
89
}
910
},
@@ -14,5 +15,13 @@
1415
"versionManager": "rbenv"
1516
}
1617
}
18+
},
19+
"with_precompiled_rubies": {
20+
"image": "mcr.microsoft.com/devcontainers/base:2-trixie",
21+
"features": {
22+
"ruby": {
23+
"usePrecompiledRubies": true
24+
}
25+
}
1726
}
1827
}

‎features/test/ruby/test.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ source dev-container-features-test-lib
66

77
check "mise is installed" bash -c "mise --version"
88
check "mise init is sourced in the bashrc" bash -c "grep 'eval \"\$(~/.local/bin/mise activate bash)\"' $HOME/.bashrc"
9+
check "mise is configured to compile Ruby from source by default" bash -c "mise settings | grep ruby.compile | grep true"
910
check "mise idiomatic version file is enabled for ruby" bash -c "mise settings | grep idiomatic_version_file_enable_tools | grep ruby"
1011
check "Ruby is installed with YJIT" bash -c "RUBY_YJIT_ENABLE=1 ruby -v | grep +YJIT"
1112
check "Ruby version is set to 4.0.2" bash -c "mise use -g ruby | grep 4.0.2"

‎features/test/ruby/version_3_3_0.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ source dev-container-features-test-lib
77
check "mise is installed" bash -c "mise --version"
88
check "mise init is sourced in the bashrc" bash -c "grep 'eval \"\$(~/.local/bin/mise activate bash)\"' $HOME/.bashrc"
99
check "mise init is sourced in the zshrc" bash -c "grep 'eval \"\$(~/.local/bin/mise activate zsh)\"' $HOME/.zshrc"
10+
check "mise uses precompiled Rubies when enabled" bash -c "mise settings | grep ruby.compile | grep false"
1011
check "mise idiomatic version file is enabled for ruby" bash -c "mise settings | grep idiomatic_version_file_enable_tools | grep ruby"
1112
check "Ruby is installed with YJIT" bash -c "RUBY_YJIT_ENABLE=1 ruby -v | grep +YJIT"
1213
check "Ruby version is set to 3.3.0" bash -c "mise use -g ruby | grep 3.3.0"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# shellcheck source=/dev/null
5+
source dev-container-features-test-lib
6+
7+
check "mise is installed" bash -c "mise --version"
8+
check "mise uses precompiled Rubies when enabled" bash -c "mise settings | grep ruby.compile | grep false"
9+
check "mise idiomatic version file is enabled for ruby" bash -c "mise settings | grep idiomatic_version_file_enable_tools | grep ruby"
10+
check "Ruby is installed with YJIT" bash -c "RUBY_YJIT_ENABLE=1 ruby -v | grep +YJIT"
11+
check "Ruby version is set to 4.0.2" bash -c "mise use -g ruby | grep 4.0.2"
12+
13+
reportResults

0 commit comments

Comments
 (0)