Skip to content

Commit 4906b34

Browse files
committed
Create a docker mod to add rbenv to code-server
This mod adds rbenv to code-server, to be installed/updated during container start. rbenv is a version manager tool for the Ruby programming language on Unix-like systems. It is useful for switching between multiple Ruby versions on the same machine and for ensuring that each project you are working on always runs on the correct Ruby version. This mod includes adding shell completions for rbenv in bash and zsh. Includes ruby-build, which allows you to run the rbenv install command. If it's already installed, make sure to upgrade it by pulling the latest changes from the git repo Adds the required packages of the build environment Need these pre-requisites in order to install ruby in rbenv Set permissions for ~/.rbenv It needs to be able to write into that directory when installing new versions of Ruby
1 parent 6360fcf commit 4906b34

File tree

24 files changed

+137
-102
lines changed

24 files changed

+137
-102
lines changed

.github/workflows/BuildImage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212
env:
1313
GITHUB_REPO: "linuxserver/docker-mods" #don't modify
1414
ENDPOINT: "linuxserver/mods" #don't modify
15-
BASEIMAGE: "replace_baseimage" #replace
16-
MODNAME: "replace_modname" #replace
15+
BASEIMAGE: "code-server" #replaced
16+
MODNAME: "rbenv" #replaced
1717
MOD_VERSION: ${{ inputs.mod_version }} #don't modify
18-
MULTI_ARCH: "true" #set to false if not needed
18+
MULTI_ARCH: "false" #set to false if not needed
1919

2020
jobs:
2121
set-vars:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
FROM scratch
44

5-
LABEL maintainer="username"
5+
LABEL maintainer="somewatson"
66

77
# copy local files
88
COPY root/ /

Dockerfile.complex

Lines changed: 0 additions & 33 deletions
This file was deleted.

README.md

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,54 @@
1-
# Rsync - Docker mod for openssh-server
1+
# Rbenv - Docker mod for code-server
22

3-
This mod adds rsync to openssh-server, to be installed/updated during container start.
3+
This mod adds [rbenv](https://github.com/rbenv/rbenv) to code-server, to be installed/updated during container start.
44

5-
In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync`
5+
rbenv is a version manager tool for the Ruby programming language on Unix-like systems. It is useful for switching between multiple Ruby versions on the same machine and for ensuring that each project you are working on always runs on the correct Ruby version.
66

7-
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2`
7+
In code-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:code-server-rbenv`
88

9-
# Mod creation instructions
9+
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:code-server-rbenv|linuxserver/mods:openssh-server-mod2`
1010

11-
* Fork the repo, create a new branch based on the branch `template`.
12-
* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done.
13-
* Inspect the `root` folder contents. Edit, add and remove as necessary.
14-
* After all init scripts and services are created, run `find ./ -path "./.git" -prune -o \( -name "run" -o -name "finish" -o -name "check" \) -not -perm -u=x,g=x,o=x -print -exec chmod +x {} +` to fix permissions.
15-
* Edit this readme with pertinent info, delete these instructions.
16-
* Finally edit the `.github/workflows/BuildImage.yml`. Customize the vars for `BASEIMAGE` and `MODNAME`. Set the versioning logic and `MULTI_ARCH` if needed.
17-
* Ask the team to create a new branch named `<baseimagename>-<modname>`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch.
18-
* Submit PR against the branch created by the team.
11+
### Shell completions
1912

13+
This mod includes adding [shell completions](https://github.com/rbenv/rbenv?tab=readme-ov-file#shell-completions) for `rbenv` in `bash` and `zsh`.
2014

21-
## Tips and tricks
15+
The zsh completion script ships with the project, but needs to be added to FPATH in zsh before it can be discovered by the shell. So, the mod will automatically detect and update the `~/.zshrc` file:
2216

23-
* Some images have helpers built in, these images are currently:
24-
* [Openvscode-server](https://github.com/linuxserver/docker-openvscode-server/pull/10/files)
25-
* [Code-server](https://github.com/linuxserver/docker-code-server/pull/95)
17+
```
18+
FPATH=~/.rbenv/completions:"$FPATH"
19+
autoload -U compinit
20+
compinit
21+
```
22+
23+
### Ruby-build
24+
25+
This mod includes [ruby-build](https://github.com/rbenv/ruby-build), which allows you to run the `rbenv install` command.
26+
27+
It will automatically check for an existing `ruby-build` installation upon `docker build`. If it detects `ruby-build`, it will upgrade it.
28+
29+
You can also manually upgrade `ruby-build`, as described in the [documentation](https://github.com/rbenv/ruby-build?tab=readme-ov-file#clone-as-rbenv-plugin-using-git), without bringing down the docker instance by running:
30+
31+
```
32+
git -C "$(rbenv root)"/plugins/ruby-build pull
33+
```
34+
35+
### Build environment
36+
37+
In order to compile Ruby, you need the proper toolchain and build environment. The required system packages can be found in the [documentation](https://github.com/rbenv/ruby-build/wiki#ubuntudebianmint).
38+
39+
This mod will install these requirements for you:
40+
41+
* autoconf
42+
* build-essential
43+
* libffi-dev
44+
* libgmp-dev
45+
* libssl-dev
46+
* libyaml-dev
47+
* rustc
48+
* zlib1g-dev
49+
50+
With these installed, you should be able to compile any of the latest stable Ruby versions, which you can find by running the command `rbenv install --list`.
51+
52+
### Installed Ruby versions
53+
54+
By default, `rbenv` is installed in `~/.rbenv`. This mod will update the permissions of that folder to ensure that your user can install new versions of Ruby into it.

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-add-package/dependencies.d/init-mods renamed to root/etc/s6-overlay/s6-rc.d/init-mod-code-server-rbenv-add-package/dependencies.d/init-mods

File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# This is the init file used for adding os or pip packages to install lists.
4+
# It takes advantage of the built-in init-mods-package-install init script that comes with the baseimages.
5+
# If using this, we need to make sure we set this init as a dependency of init-mods-package-install so this one runs first
6+
#!/usr/bin/with-contenv bash
7+
8+
if ! dpkg -s git >/dev/null 2>&1; then
9+
echo "**** Adding git to package install list ****"
10+
echo "git" >> /mod-repo-packages-to-install.list
11+
else
12+
echo "**** git already installed, skipping ****"
13+
fi
14+
15+
# List comes from: https://github.com/rbenv/ruby-build/wiki#ubuntudebianmint
16+
echo "Adding the required packages of the build environment for rbenv ruby-build "
17+
echo "\
18+
autoconf \
19+
build-essential \
20+
libffi-dev \
21+
libgmp-dev \
22+
libssl-dev \
23+
libyaml-dev \
24+
rustc \
25+
zlib1g-dev" >> /mod-repo-packages-to-install.list

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-add-package/type renamed to root/etc/s6-overlay/s6-rc.d/init-mod-code-server-rbenv-add-package/type

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/init-mod-code-server-rbenv-add-package/run

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-install/dependencies.d/init-mods-package-install renamed to root/etc/s6-overlay/s6-rc.d/init-mod-code-server-rbenv-install/dependencies.d/init-mods-package-install

File renamed without changes.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# This is an install script that is designed to run after init-mods-package-install
4+
# so it can take advantage of packages installed
5+
# init-mods-end depends on this script so that later init and services wait until this script exits
6+
7+
if [ -d ~/.rbenv ]; then
8+
echo 'rbenv already cloned, skipping'
9+
else
10+
echo 'Cloning rbenv repo'
11+
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
12+
fi
13+
14+
if [ -d ~/.rbenv/plugins/ruby-build ]; then
15+
echo 'ruby-build plugin already cloned, skipping'
16+
17+
echo 'Upgrading ruby-build plugin'
18+
git -C ~/.rbenv/plugins/ruby-build pull
19+
else
20+
echo 'Cloning ruby-build plugin repo'
21+
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
22+
fi
23+
24+
# This will add `eval "$(~/.rbenv/bin/rbenv init - --no-rehash bash)"` to the ~/.bashrc or ~/.bash_profile file
25+
echo 'Initializing rbenv for bash'
26+
~/.rbenv/bin/rbenv init
27+
28+
if ! command -v zsh >/dev/null 2>&1; then
29+
echo "**** zsh not installed, skipping shell completions setup ****"
30+
else
31+
# This will add `eval "$(~/.rbenv/bin/rbenv init - --no-rehash zsh)"` to the ~/.zshrc file
32+
echo 'Initializing rbenv for zsh'
33+
~/.rbenv/bin/rbenv init zsh
34+
35+
if [ -f ~/.zshrc ]; then
36+
if ! grep -q 'FPATH=~/.rbenv/completions:"$FPATH"' ~/.zshrc; then
37+
echo 'Adding shell completions to zsh for rbenv'
38+
39+
echo '' >> ~/.zshrc
40+
echo '# For rbenv shell completions' >> ~/.zshrc
41+
echo 'FPATH=~/.rbenv/completions:"$FPATH"' >> ~/.zshrc
42+
echo 'autoload -U compinit' >> ~/.zshrc
43+
echo 'compinit' >> ~/.zshrc
44+
else
45+
echo 'rbenv shell completions already exist in zsh, skipping'
46+
fi
47+
else
48+
echo '~/.zshrc not found, creating one with the shell completions'
49+
50+
echo '' >> ~/.zshrc
51+
echo '# For rbenv shell completions' >> ~/.zshrc
52+
echo 'FPATH=~/.rbenv/completions:"$FPATH"' >> ~/.zshrc
53+
echo 'autoload -U compinit' >> ~/.zshrc
54+
echo 'compinit' >> ~/.zshrc
55+
fi
56+
fi
57+
58+
echo 'Setting permissions for ~/.rbenv'
59+
lsiown -R abc:abc \
60+
/config/.rbenv

0 commit comments

Comments
 (0)