migrate to the new tiered structure
This commit is contained in:
31
example/.safeclaude/hooks/10-ruby.sh
Executable file
31
example/.safeclaude/hooks/10-ruby.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/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
|
||||
15
example/.safeclaude/hooks/15-node.sh.example
Normal file
15
example/.safeclaude/hooks/15-node.sh.example
Normal file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
# OPTIONAL — only needed if your project pins a Node version via .nvmrc (the base
|
||||
# already includes a working Node). Rename to 15-node.sh to turn it on.
|
||||
set -euo pipefail
|
||||
|
||||
if [ ! -s "$NVM_DIR/nvm.sh" ]; then
|
||||
echo "[node] installing nvm..."
|
||||
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh \
|
||||
| NVM_DIR="$NVM_DIR" PROFILE=/dev/null bash
|
||||
fi
|
||||
. "$NVM_DIR/nvm.sh"
|
||||
|
||||
if [ -f /code/.nvmrc ]; then
|
||||
( cd /code && nvm install && nvm use )
|
||||
fi
|
||||
21
example/.safeclaude/hooks/20-bundle.sh
Executable file
21
example/.safeclaude/hooks/20-bundle.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# Installs gems, but only when Gemfile.lock has changed: it remembers the last
|
||||
# version it installed (saved between runs), so an unchanged lockfile is a
|
||||
# near-instant no-op.
|
||||
set -euo pipefail
|
||||
|
||||
[ -f /code/Gemfile ] || exit 0
|
||||
eval "$(rbenv init - bash)"
|
||||
|
||||
LOCK=/code/Gemfile.lock
|
||||
MARKER="$HOME/.safeclaude-deps/gemfile.sha"
|
||||
mkdir -p "$(dirname "$MARKER")"
|
||||
CUR="$( [ -f "$LOCK" ] && sha256sum "$LOCK" | cut -d' ' -f1 || echo no-lock )"
|
||||
|
||||
if [ "$(cat "$MARKER" 2>/dev/null || true)" != "$CUR" ]; then
|
||||
echo "[bundle] installing gems..."
|
||||
# The token below (for a private gem source) comes from .safeclaude/.env — see
|
||||
# .env.example. It's fine to leave unset if your project doesn't need it.
|
||||
( cd /code && BUNDLE_GEMS__GRAPHQL__PRO="${BUNDLE_GEMS__GRAPHQL__PRO:-}" bundle install )
|
||||
echo "$CUR" > "$MARKER"
|
||||
fi
|
||||
15
example/.safeclaude/hooks/30-pg-proxy.sh
Executable file
15
example/.safeclaude/hooks/30-pg-proxy.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
# Makes the host machine's Postgres reachable at the usual 127.0.0.1:5432 inside
|
||||
# the container, so your database settings work the same in or out of Docker.
|
||||
set -euo pipefail
|
||||
|
||||
# If something's already answering on 5432 (like a proxy from a previous launch),
|
||||
# leave it be. We test the port with a built-in bash trick so we don't have to
|
||||
# install extra tools just to check.
|
||||
if (exec 3<>/dev/tcp/127.0.0.1/5432) 2>/dev/null; then
|
||||
exec 3>&- # port answered — already running
|
||||
else
|
||||
echo "[pg] proxying 127.0.0.1:5432 -> host.docker.internal:5432"
|
||||
socat TCP-LISTEN:5432,bind=127.0.0.1,fork,reuseaddr \
|
||||
TCP:host.docker.internal:5432 &
|
||||
fi
|
||||
Reference in New Issue
Block a user