|
#!/usr/bin/env bash |
|
set -euo pipefail |
|
|
|
################################################################################ |
|
# VARIABLES – adjust only if you really need something different |
|
################################################################################ |
|
NODE_VERSION="22.12.0" # must match Dockerfile |
|
PNPM_VERSION="latest" # use a specific version if you prefer |
|
PARALLEL_JOBS="$(nproc)" # bundler / compile jobs |
|
|
|
################################################################################ |
|
# APT PACKAGES – runtime + build deps needed by the Rails stack |
|
################################################################################ |
|
apt-get update -qq |
|
DEBIAN_FRONTEND=noninteractive apt-get install -yqq --no-install-recommends \ |
|
build-essential \ |
|
git curl wget ca-certificates gnupg2 dirmngr xz-utils vim unzip \ |
|
libssl-dev libreadline-dev zlib1g-dev libyaml-dev \ |
|
libjemalloc2 libjemalloc-dev \ |
|
libvips-dev libheif-dev libde265-dev \ |
|
libpq-dev libpq5 postgresql-client \ |
|
default-libmysqlclient-dev \ |
|
freetds-dev freetds-bin tdsodbc unixodbc unixodbc-dev \ |
|
libsqlite3-dev \ |
|
python-is-python3 pkg-config \ |
|
postgresql-16 postgresql-common |
|
|
|
rm -rf /var/lib/apt/lists/* # keep the image lean |
|
|
|
################################################################################ |
|
# NODE + PNPM – mirrors the Dockerfile (node-build via NVM is the lightest path) |
|
################################################################################ |
|
echo "▶ Building Node ${NODE_VERSION}…" |
|
curl -fsSL https://github.com/nodenv/node-build/archive/refs/heads/master.tar.gz | tar -xz -C /tmp/ |
|
NODE_BUILD_DIR="$(find /tmp -maxdepth 1 -type d -name 'node-build-*' | head -n 1)" |
|
"$NODE_BUILD_DIR/bin/node-build" "${NODE_VERSION}" /usr/local/node |
|
rm -rf "$NODE_BUILD_DIR" |
|
export PATH="/usr/local/node/bin:$PATH" |
|
|
|
npm install -g "pnpm@${PNPM_VERSION}" |
|
|
|
################################################################################ |
|
# RUBYGEMS – system & bundler (Ruby 3.4.4 already pre-installed on Codex) |
|
################################################################################ |
|
gem update --system --no-document |
|
gem install bundler --no-document |
|
|
|
################################################################################ |
|
# PROJECT DEPENDENCIES |
|
################################################################################ |
|
bundle config set jobs "${PARALLEL_JOBS}" |
|
bundle install --retry 3 |
|
|
|
if [[ -f pnpm-lock.yaml ]]; then |
|
pnpm install --frozen-lockfile |
|
else |
|
npm install |
|
fi |
|
|
|
################################################################################ |
|
# PLAYWRIGHT BROWSERS – used for system tests |
|
################################################################################ |
|
echo "▶ Installing Playwright Chromium…" |
|
npx playwright install chromium |
|
|
|
################################################################################ |
|
# DATABASE & BOOTSTRAP |
|
################################################################################ |
|
############################################################################### |
|
# PostgreSQL local cluster + “dev” superuser |
|
############################################################################### |
|
pg_ctlcluster --skip-systemctl-redirect 16 main start |
|
|
|
PG_USER="dev" |
|
PG_PASS="devsecret" |
|
|
|
sudo -u postgres psql -v ON_ERROR_STOP=1 <<SQL |
|
DO \$\$ BEGIN |
|
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '${PG_USER}') THEN |
|
CREATE ROLE ${PG_USER} SUPERUSER LOGIN PASSWORD '${PG_PASS}'; |
|
ELSE |
|
ALTER ROLE ${PG_USER} WITH PASSWORD '${PG_PASS}'; |
|
END IF; |
|
END \$\$; |
|
SQL |
|
|
|
# Correct exports |
|
export DB_USER="${PG_USER}" |
|
export DB_PASSWORD="${PG_PASS}" |
|
export DB_HOST="localhost" |
|
export DB_PORT="5432" |
|
|
|
############################################################################### |
|
# Rails tasks |
|
############################################################################### |
|
bundle exec bootsnap precompile --gemfile |
|
bin/rails db:prepare # now uses dev / devsecret |
|
|
|
echo "✅ Codex environment ready for Ruby 3.4.4 Rails application!" |
Reference: https://gist.github.com/FrancescoK/74e1c6d0ed01011ebeffc11797d19198