32 lines
1.2 KiB
Bash
Executable File
32 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Sets up rbenv and the project's Ruby. Safe to run every launch — it only does
|
|
# real work the first time, or when the Ruby version changes.
|
|
set -euo pipefail
|
|
|
|
# Grab rbenv (cloned into the home folder so it sticks around between runs).
|
|
if [ ! -d "$RBENV_ROOT/bin" ]; then
|
|
echo "[ruby] installing rbenv..."
|
|
git clone --depth=1 https://github.com/rbenv/rbenv.git "$RBENV_ROOT"
|
|
git clone --depth=1 https://github.com/rbenv/ruby-build.git "$RBENV_ROOT/plugins/ruby-build"
|
|
fi
|
|
eval "$(rbenv init - bash)"
|
|
|
|
# Pick the Ruby version: the project's .ruby-version wins, then whatever rbenv
|
|
# was last set to, then a sensible default.
|
|
if [ -f /code/.ruby-version ]; then
|
|
RUBY_VERSION="$(tr -d '[:space:]' < /code/.ruby-version)"
|
|
elif [ -f "$RBENV_ROOT/version" ]; then
|
|
RUBY_VERSION="$(cat "$RBENV_ROOT/version")"
|
|
else
|
|
RUBY_VERSION="3.3.6"
|
|
fi
|
|
|
|
if ! rbenv versions --bare 2>/dev/null | grep -qx "$RUBY_VERSION"; then
|
|
echo "[ruby] installing Ruby $RUBY_VERSION (first time only — takes a few minutes)..."
|
|
rbenv install "$RUBY_VERSION"
|
|
fi
|
|
rbenv global "$RUBY_VERSION"
|
|
|
|
# Make sure bundler is installed for this Ruby.
|
|
gem list bundler -i &>/dev/null || gem install bundler --no-document
|