Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Issue 704: Adding enabling and disabling of RBENV and RVM packages #1333

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 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
5 changes: 5 additions & 0 deletions containers/ruby/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
}
},

"containerEnv": {
"RBENV_ENABLED": "true",
"RVM_ENABLED": "true"
},

// Set *default* container specific settings.json values on container create.
"settings": {},

Expand Down
43 changes: 33 additions & 10 deletions containers/ruby/.devcontainer/library-scripts/ruby-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ else
# Install rvm
curl -sSL https://get.rvm.io | bash -s stable --ignore-dotfiles ${RVM_INSTALL_ARGS} --with-default-gems="${DEFAULT_GEMS}" 2>&1
usermod -aG rvm ${USERNAME}
su ${USERNAME} -c ". /usr/local/rvm/scripts/rvm && rvm fix-permissions system"
su ${USERNAME} -c "/usr/local/rvm/scripts/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 "")'
su ${USERNAME} -c ". /usr/local/rvm/scripts/rvm && \"$(which gem || echo ${ROOT_GEM})\" install ${DEFAULT_GEMS}"
su ${USERNAME} -c "\"$(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"
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"

# Install rbenv/ruby-build for good measure
git clone --depth=1 \
Expand All @@ -247,25 +247,48 @@ git clone --depth=1 \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
https://github.com/rbenv/rbenv.git /usr/local/share/rbenv
ln -s /usr/local/share/rbenv/bin/rbenv /usr/local/bin
updaterc 'eval "$(rbenv init -)"'

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
KanishkT123 marked this conversation as resolved.
Show resolved Hide resolved

if [ "${USERNAME}" != "root" ]; then
mkdir -p /home/${USERNAME}/.rbenv/plugins
chown -R ${USERNAME} /home/${USERNAME}/.rbenv
ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build
KanishkT123 marked this conversation as resolved.
Show resolved Hide resolved
fi

# Update bashrc and zshrc with conditionals
# We use "not false" so that the default state is true, i.e., enabled
updaterc 'if [ "${RVM_ENABLED}" != "false" ]; then
source /usr/local/rvm/scripts/rvm
fi'

# All commands have the output redirected to /dev/null so that there is no output on shell startup.
if [ "${USERNAME}" != "root" ]; then
mkdir -p /home/${USERNAME}/.rbenv/plugins
updaterc 'if [ "${RBENV_ENABLED}" != "false" ]; then
chown -R ${USERNAME} /home/${USERNAME}/.rbenv
ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build > /dev/null 2>&1
else
rm -f /home/${USERNAME}/.rbenv/plugins/ruby-build > /dev/null 2>&1
fi'
fi

updaterc 'if [ "${RBENV_ENABLED}" != "false" ]; then
sudo ln -s /usr/local/share/rbenv/bin/rbenv /usr/local/bin > /dev/null 2>&1
KanishkT123 marked this conversation as resolved.
Show resolved Hide resolved
eval "$(rbenv init -)"
sudo ln -s /usr/local/share/ruby-build /root/.rbenv/plugins/ruby-build > /dev/null 2>&1
else
rm -f /root/.rbenv/plugins/ruby-build > /dev/null 2>&1
rm -f /usr/local/bin/rbenv > /dev/null 2>&1
KanishkT123 marked this conversation as resolved.
Show resolved Hide resolved
fi'

# Clean up
source /usr/local/rvm/scripts/rvm
rvm cleanup all
/usr/local/rvm/scripts/rvm cleanup all
gem cleanup
echo "Done!"
27 changes: 27 additions & 0 deletions containers/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ Given JavaScript front-end web client code written for use in conjunction with a
}
```

### Enabling and Disabling Ruby Version Managers (RVM and RBENV)

This Dev Container comes pre-packaged with a `ruby-debian.sh` shell script which installs `rbenv` and `rvm`. Both tools and their configuration files are enabled in the devcontainer by default. If you want to use them, simply start the container as normal. You can test the `rbenv` installation by running:

```bash
rbenv -v
```

And the `rvm` installation by running:

```bash
rvm -v
```

These commands can be run in the integrated terminal.

To disable these tools, change the `containerEnv` variables in `devcontainer.json`:

```jsonc
"containerEnv": {
"RBENV_ENABLED": "false",
"RVM_ENABLED": "false"
},
```

These variables need to be explicitly set to `false` for the tools to be disabled. Any other input will result in `rvm` and `rbenv` being enabled for the container.

### Adding the definition to your folder

1. If this is your first time using a development container, please see getting started information on [setting up](https://aka.ms/vscode-remote/containers/getting-started) Remote-Containers or [creating a codespace](https://aka.ms/ghcs-open-codespace) using GitHub Codespaces.
Expand Down
37 changes: 27 additions & 10 deletions script-library/ruby-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ else
# Install rvm
curl -sSL https://get.rvm.io | bash -s stable --ignore-dotfiles ${RVM_INSTALL_ARGS} --with-default-gems="${DEFAULT_GEMS}" 2>&1
usermod -aG rvm ${USERNAME}
su ${USERNAME} -c ". /usr/local/rvm/scripts/rvm && rvm fix-permissions system"
su ${USERNAME} -c "/usr/local/rvm/scripts/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 "")'
su ${USERNAME} -c ". /usr/local/rvm/scripts/rvm && \"$(which gem || echo ${ROOT_GEM})\" install ${DEFAULT_GEMS}"
su ${USERNAME} -c "\"$(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"
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"

# Install rbenv/ruby-build for good measure
git clone --depth=1 \
Expand All @@ -247,25 +247,42 @@ git clone --depth=1 \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
https://github.com/rbenv/rbenv.git /usr/local/share/rbenv
ln -s /usr/local/share/rbenv/bin/rbenv /usr/local/bin
updaterc 'eval "$(rbenv init -)"'

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

if [ "${USERNAME}" != "root" ]; then
mkdir -p /home/${USERNAME}/.rbenv/plugins
chown -R ${USERNAME} /home/${USERNAME}/.rbenv
ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build
fi

# Update bashrc and zshrc with conditionals
# We use "not false" so that the default state is true, i.e., enabled
updaterc 'if [ "${RVM_ENABLED}" != "false" ]; then
source /usr/local/rvm/scripts/rvm
fi'

if [ "${USERNAME}" != "root" ]; then
mkdir -p /home/${USERNAME}/.rbenv/plugins
updaterc 'if [ "${RBENV_ENABLED}" != "false" ]; then
chown -R ${USERNAME} /home/${USERNAME}/.rbenv
ln -s /usr/local/share/ruby-build /home/${USERNAME}/.rbenv/plugins/ruby-build
fi'
fi

updaterc 'if [ "${RBENV_ENABLED}" != "false" ]; then
sudo ln -s /usr/local/share/rbenv/bin/rbenv /usr/local/bin
eval "$(rbenv init -)"
sudo ln -s /usr/local/share/ruby-build /root/.rbenv/plugins/ruby-build
fi'

# Clean up
source /usr/local/rvm/scripts/rvm
rvm cleanup all
/usr/local/rvm/scripts/rvm cleanup all
gem cleanup
echo "Done!"