Skip to content

Commit 07da3ec

Browse files
authored
Merge pull request #1091 from somewatson/code-server-rbenv
Create mod to include rbenv in code-server
2 parents 6360fcf + 4b405be commit 07da3ec

File tree

24 files changed

+143
-102
lines changed

24 files changed

+143
-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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 /config/.rbenv ]; then
8+
echo 'rbenv already cloned, skipping'
9+
else
10+
echo 'Cloning rbenv repo'
11+
git clone https://github.com/rbenv/rbenv.git /config/.rbenv
12+
fi
13+
14+
if [ -d /config/.rbenv/plugins/ruby-build ]; then
15+
echo 'ruby-build plugin already cloned, skipping'
16+
17+
# On a docker start, even if this folder exists, we need to own it first for git to be able to pull
18+
echo 'Setting permissions for ~/.rbenv'
19+
lsiown -R abc:abc \
20+
/config/.rbenv
21+
22+
echo 'Upgrading ruby-build plugin'
23+
git config --global --add safe.directory /config/.rbenv/plugins/ruby-build
24+
git -C /config/.rbenv/plugins/ruby-build pull
25+
else
26+
echo 'Cloning ruby-build plugin repo'
27+
git clone https://github.com/rbenv/ruby-build.git /config/.rbenv/plugins/ruby-build
28+
fi
29+
30+
# This will add `eval "$(~/.rbenv/bin/rbenv init - --no-rehash bash)"` to the ~/.bashrc or ~/.bash_profile file
31+
echo 'Initializing rbenv for bash'
32+
/config/.rbenv/bin/rbenv init
33+
34+
if ! command -v zsh >/dev/null 2>&1; then
35+
echo "**** zsh not installed, skipping shell completions setup ****"
36+
else
37+
# This will add `eval "$(~/.rbenv/bin/rbenv init - --no-rehash zsh)"` to the ~/.zshrc file
38+
echo 'Initializing rbenv for zsh'
39+
/config/.rbenv/bin/rbenv init zsh
40+
41+
if [ -f /config/.zshrc ]; then
42+
if ! grep -q 'FPATH=~/.rbenv/completions:"$FPATH"' /config/.zshrc; then
43+
echo 'Adding shell completions to zsh for rbenv'
44+
45+
echo '' >> /config/.zshrc
46+
echo '# For rbenv shell completions' >> /config/.zshrc
47+
echo 'FPATH=~/.rbenv/completions:"$FPATH"' >> /config/.zshrc
48+
echo 'autoload -U compinit' >> /config/.zshrc
49+
echo 'compinit' >> /config/.zshrc
50+
else
51+
echo 'rbenv shell completions already exist in zsh, skipping'
52+
fi
53+
else
54+
echo '/config/.zshrc not found, creating one with the shell completions'
55+
56+
echo '' >> /config/.zshrc
57+
echo '# For rbenv shell completions' >> /config/.zshrc
58+
echo 'FPATH=~/.rbenv/completions:"$FPATH"' >> /config/.zshrc
59+
echo 'autoload -U compinit' >> /config/.zshrc
60+
echo 'compinit' >> /config/.zshrc
61+
fi
62+
fi
63+
64+
echo 'Setting permissions for ~/.rbenv'
65+
lsiown -R abc:abc \
66+
/config/.rbenv

0 commit comments

Comments
 (0)