-
Notifications
You must be signed in to change notification settings - Fork 583
Improving the Ruby Feature. #764
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e84b552
Parity with the node feature
ThomasOwens 4c05c25
Removed unused variable.
ThomasOwens 3fa3a50
Removed os-provided
ThomasOwens ef83cfc
More specific no versions test case
ThomasOwens 515866a
Version update.
ThomasOwens 6a4536a
Added a scenario to test installing a gem.
ThomasOwens 19e44ae
Remove environment variables
ThomasOwens a4da3d7
Test scenario improvements.
ThomasOwens 7f2df1c
Merge branch 'devcontainers:main' into main
ThomasOwens 4bc43ac
Refactoring RVM install to support options for rbenv and ruby-build.
ThomasOwens fad9634
Merge branch 'devcontainers:main' into main
ThomasOwens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,26 +7,21 @@ | |
| # Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/ruby.md | ||
| # Maintainer: The VS Code and Codespaces Teams | ||
|
|
||
| RUBY_VERSION="${VERSION:-"latest"}" | ||
|
|
||
| USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" | ||
| UPDATE_RC="${UPDATE_RC:-"true"}" | ||
| INSTALL_RUBY_TOOLS="${INSTALL_RUBY_TOOLS:-"true"}" | ||
| export RUBY_VERSION="${VERSION:-"latest"}" | ||
|
|
||
| # Comma-separated list of ruby versions to be installed (with rvm) | ||
| # alongside RUBY_VERSION, but not set as default. | ||
| ADDITIONAL_VERSIONS="${ADDITIONALVERSIONS:-""}" | ||
|
|
||
| # Note: ruby-debug-ide will install the right version of debase if missing and | ||
| # installing debase directly fails on Ruby 3.1.0 as of 1/7/2022, so omitting. | ||
| # installing ruby-debug-ide on debian fails, so omitting. | ||
| DEFAULT_GEMS="rake" | ||
| GPG_KEY_SERVERS="keyserver hkps://keys.openpgp.org | ||
| keyserver hkp://keyserver.pgp.com | ||
| keyserver hkp://pgp.mit.edu | ||
| keyserver hkp://ipv4.pool.sks-keyservers.net | ||
| keyserver hkp://keyserver.ubuntu.com | ||
| keyserver hkp://keyserver.ubuntu.com:80" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the keyservers recommended in the RVM documentation in addition to the ones previously included. |
||
|
|
||
| RVM_GPG_KEYS="409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB" | ||
| GPG_KEY_SERVERS="keyserver hkp://keyserver.ubuntu.com | ||
| keyserver hkp://keyserver.ubuntu.com:80 | ||
| keyserver hkps://keys.openpgp.org | ||
| keyserver hkp://keyserver.pgp.com" | ||
| USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}" | ||
| UPDATE_RC="${UPDATE_RC:-"true"}" | ||
|
|
||
| set -e | ||
|
|
||
|
|
@@ -106,7 +101,7 @@ receive_gpg_keys() { | |
| fi | ||
| } | ||
|
|
||
| # Figure out correct version of a three part version number is not passed | ||
| # Figure out correct version if a three part version number is not passed | ||
| find_version_from_git_tags() { | ||
| local variable_name=$1 | ||
| local requested_version=${!variable_name} | ||
|
|
@@ -169,33 +164,32 @@ fi | |
| check_packages curl ca-certificates software-properties-common build-essential gnupg2 libreadline-dev \ | ||
| procps dirmngr gawk autoconf automake bison libffi-dev libgdbm-dev libncurses5-dev \ | ||
| libsqlite3-dev libtool libyaml-dev pkg-config sqlite3 zlib1g-dev libgmp-dev libssl-dev | ||
|
|
||
| if ! type git > /dev/null 2>&1; then | ||
| check_packages git | ||
| fi | ||
|
|
||
|
|
||
| # Figure out correct version of a three part version number is not passed | ||
| find_version_from_git_tags RUBY_VERSION "https://github.com/ruby/ruby" "tags/v" "_" | ||
|
|
||
| # Just install Ruby if RVM already installed | ||
| if rvm --version > /dev/null; then | ||
| echo "Ruby Version Manager already exists." | ||
| if [[ "$(ruby -v)" = *"${RUBY_VERSION}"* ]]; then | ||
| echo "(!) Ruby is already installed with version ${RUBY_VERSION}. Skipping..." | ||
| echo "(!) Ruby is already installed with version ${RUBY_VERSION}." | ||
| elif [ "${RUBY_VERSION}" != "none" ]; then | ||
| echo "Installing specified Ruby version." | ||
| su ${USERNAME} -c "rvm install ruby ${RUBY_VERSION}" | ||
| fi | ||
| SKIP_GEM_INSTALL="false" | ||
| SKIP_RBENV_RBUILD="true" | ||
| else | ||
| # Install RVM | ||
| RVM_GPG_KEYS="409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB" | ||
| receive_gpg_keys RVM_GPG_KEYS | ||
| # Determine appropriate settings for rvm installer | ||
| if [ "${RUBY_VERSION}" = "none" ]; then | ||
| RVM_INSTALL_ARGS="" | ||
| elif [[ "$(ruby -v)" = *"${RUBY_VERSION}"* ]]; then | ||
| echo "(!) Ruby is already installed with version ${RUBY_VERSION}. Skipping..." | ||
| echo "(!) Ruby is already installed with version ${RUBY_VERSION}." | ||
| RVM_INSTALL_ARGS="" | ||
| else | ||
| if [ "${RUBY_VERSION}" = "latest" ] || [ "${RUBY_VERSION}" = "current" ] || [ "${RUBY_VERSION}" = "lts" ]; then | ||
|
|
@@ -204,31 +198,19 @@ else | |
| else | ||
| RVM_INSTALL_ARGS="--ruby=${RUBY_VERSION}" | ||
| fi | ||
| if [ "${INSTALL_RUBY_TOOLS}" = "true" ]; then | ||
| SKIP_GEM_INSTALL="true" | ||
| else | ||
| DEFAULT_GEMS="" | ||
| fi | ||
| fi | ||
| # Create rvm group as a system group to reduce the odds of conflict with local user UIDs | ||
| if ! cat /etc/group | grep -e "^rvm:" > /dev/null 2>&1; then | ||
| groupadd -r rvm | ||
| fi | ||
| # Install rvm | ||
| curl -sSL https://get.rvm.io | bash -s stable --ignore-dotfiles ${RVM_INSTALL_ARGS} --with-default-gems="${DEFAULT_GEMS}" 2>&1 | ||
| curl -sSL https://get.rvm.io | bash -s stable --ignore-dotfiles ${RVM_INSTALL_ARGS} 2>&1 | ||
| usermod -aG rvm ${USERNAME} | ||
| source /usr/local/rvm/scripts/rvm | ||
| rvm fix-permissions system | ||
| rm -rf ${GNUPGHOME} | ||
| fi | ||
|
|
||
| if [ "${INSTALL_RUBY_TOOLS}" = "true" ]; then | ||
| # Non-root user may not have "gem" in path when script is run and no ruby version | ||
| # is installed by rvm, so handle this by using root's default gem in this case | ||
| ROOT_GEM="$(which gem || echo "")" | ||
| ${ROOT_GEM} install ${DEFAULT_GEMS} | ||
| fi | ||
|
|
||
| # VS Code server usually first in the path, so silence annoying rvm warning (that does not apply) and then source it | ||
| updaterc "if ! grep rvm_silence_path_mismatch_check_flag \$HOME/.rvmrc > /dev/null 2>&1; then echo 'rvm_silence_path_mismatch_check_flag=1' >> \$HOME/.rvmrc; fi\nsource /usr/local/rvm/scripts/rvm > /dev/null 2>&1" | ||
|
|
||
|
|
@@ -246,59 +228,12 @@ if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then | |
| IFS=$OLDIFS | ||
| fi | ||
|
|
||
| # Install rbenv/ruby-build for good measure | ||
| if [ "${SKIP_RBENV_RBUILD}" != "true" ]; then | ||
|
|
||
| if [[ ! -d "/usr/local/share/rbenv" ]]; then | ||
| git clone --depth=1 \ | ||
| -c core.eol=lf \ | ||
| -c core.autocrlf=false \ | ||
| -c fsck.zeroPaddedFilemode=ignore \ | ||
| -c fetch.fsck.zeroPaddedFilemode=ignore \ | ||
| -c receive.fsck.zeroPaddedFilemode=ignore \ | ||
| https://github.com/rbenv/rbenv.git /usr/local/share/rbenv | ||
| fi | ||
|
|
||
| if [[ ! -d "/usr/local/share/ruby-build" ]]; then | ||
| git clone --depth=1 \ | ||
| -c core.eol=lf \ | ||
| -c core.autocrlf=false \ | ||
| -c fsck.zeroPaddedFilemode=ignore \ | ||
| -c fetch.fsck.zeroPaddedFilemode=ignore \ | ||
| -c receive.fsck.zeroPaddedFilemode=ignore \ | ||
| https://github.com/rbenv/ruby-build.git /usr/local/share/ruby-build | ||
| mkdir -p /root/.rbenv/plugins | ||
|
|
||
| ln -s /usr/local/share/ruby-build /root/.rbenv/plugins/ruby-build | ||
| fi | ||
|
|
||
| if [ "${USERNAME}" != "root" ]; then | ||
| mkdir -p /home/${USERNAME}/.rbenv/plugins | ||
|
|
||
| if [[ ! -d "/home/${USERNAME}/.rbenv/plugins/ruby-build" ]]; then | ||
| ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build | ||
| fi | ||
|
|
||
| # Oryx expects ruby to be installed in this specific path, else it breaks the oryx magic for ruby projects. | ||
| if [ ! -f /usr/local/rvm/gems/default/bin/ruby ]; then | ||
| ln -s /usr/local/rvm/rubies/default/bin/ruby /usr/local/rvm/gems/default/bin | ||
| fi | ||
|
|
||
| chown -R "${USERNAME}:rvm" "/home/${USERNAME}/.rbenv/" | ||
| chmod -R g+r+w "/home/${USERNAME}/.rbenv" | ||
| find "/home/${USERNAME}/.rbenv" -type d | xargs -n 1 chmod g+s | ||
| fi | ||
| fi | ||
|
|
||
| chown -R "${USERNAME}:rvm" "/usr/local/rvm/" | ||
| chmod -R g+r+w "/usr/local/rvm/" | ||
| find "/usr/local/rvm/" -type d | xargs -n 1 chmod g+s | ||
|
|
||
| # Clean up | ||
| rvm cleanup all | ||
| ${ROOT_GEM} cleanup | ||
|
|
||
| # Clean up | ||
| rm -rf /var/lib/apt/lists/* | ||
|
|
||
| echo "Done!" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| check "3.0.6 installed" bash -c "rvm list | fgrep 3.0.6" | ||
| check "2.7.8 installed" bash -c "rvm list | fgrep 2.7.8" | ||
|
|
||
| # Report result | ||
| reportResults |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Definition specific tests | ||
| check "version" rvm --version | ||
| check "ruby version" ruby --version | ||
|
|
||
| # Report result | ||
| reportResults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -e | ||
|
|
||
| # Optional: Import test library | ||
| source dev-container-features-test-lib | ||
|
|
||
| # Definition specific tests | ||
| check "ruby installed" bash -c "ruby --version | grep 3.0.6" | ||
|
|
||
| # Report result | ||
| reportResults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,36 @@ | ||
| { | ||
| "install_additional_ruby": { | ||
| "image": "ubuntu:focal", | ||
| "non_root_user": { | ||
| "image": "mcr.microsoft.com/devcontainers/base:bullseye", | ||
ThomasOwens marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "remoteUser": "vscode", | ||
| "features": { | ||
| "ruby": { | ||
| "version": "latest" | ||
| } | ||
| } | ||
| }, | ||
| "additional_versions": { | ||
| "image": "mcr.microsoft.com/devcontainers/base:bullseye", | ||
| "features": { | ||
| "ruby": { | ||
| "version": "3.1.2", | ||
| "additionalVersions": "2.5,3.0.4" | ||
| "version": "latest", | ||
| "additionalVersions": "3.0.6,2.7.8" | ||
| } | ||
| } | ||
| }, | ||
| "ruby_debian": { | ||
| "older_version": { | ||
| "image": "mcr.microsoft.com/devcontainers/base:bullseye", | ||
| "features": { | ||
| "ruby": {} | ||
| "ruby": { | ||
| "version": "3.0.6" | ||
| } | ||
| } | ||
| }, | ||
| "no_version": { | ||
| "image": "mcr.microsoft.com/devcontainers/base:bullseye", | ||
| "features": { | ||
| "ruby": { | ||
| "version": "none" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing an os-provided Ruby is difficult.
The mcr.microsoft.com/devcontainers/base:bullseye image does not include Ruby. The Ruby devcontainer image (
images/src/ruby/.devcontainer/Dockerfilein the devcontainer/images repository) is based upon a Ruby image from the official Ruby Docker images and not an image in the Microsoft container registry, which does include an installed Ruby. This is why my (not yet committed) test and change to handle this os-provided option isn't working.I'm even hesitant to include a "none" option. But I did aim for parity with the Node Feature, and it offers a none option which just installs NVM. So I carried that option over here. I did notice, though, that Node also has the issue where their devcontainer image is based on an official Node docker image and not an image in the MCR.