Skip to content

Instantly share code, notes, and snippets.

@nzoschke
Created September 11, 2011 21:17
Show Gist options
  • Save nzoschke/1210141 to your computer and use it in GitHub Desktop.
Save nzoschke/1210141 to your computer and use it in GitHub Desktop.

Ruby Language Pack

#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
set -eo pipefail
BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
BUILD_DIR=$1
CACHE_DIR=$2
export GEM_HOME=vendor/bundle/ruby/1.9.1
export GEM_PATH=$GEM_HOME
export HOME=$BUILD_DIR
export LANG=en_US.UTF-8
export PATH=$GEM_HOME/bin:$MY_RUBY_HOME/bin:/usr/local/bin:/usr/bin:/bin # MY_RUBY_HOME for rvm silliness
prefer() {
NAME=${!#} # last arg => name of alias/program
BIN=$(which $* | head -1 || true)
eval "$NAME() { $BIN \"\$@\"; }; declare -fx $NAME;"
}
prefer gsed sed
abort() { echo $*; exit 1; }
topic() { echo "----->" $*; }
msg() { echo " " $*; }
err() { echo " ! " $*; }
indent() { sed -u "s/^/ /"; }
cd $BUILD_DIR
NAME=$($BIN_DIR/detect $BUILD_DIR) || { err no Ruby app detected; exit 1; }
topic $NAME app detected
topic Installing bundler using $(ruby -v | cut -d" " -f1-2) and gem $(gem --version)...
gem install bundler --pre --no-rdoc --no-ri 2>&1 | logger -t $LOG_TAG
sed -i -e 's/^#!.*ruby$/#!\/usr\/bin\/env ruby/g' vendor/bundle/ruby/1.9.1/bin/bundle # normalize shebang
topic Installing dependencies using $(bundle --version)
BUNDLE_CMD="bundle install --without development:test --deployment"
msg Running: $BUNDLE_CMD
eval $BUNDLE_CMD | indent
msg Cleaning up the bundler cache
bundle clean
#!/usr/bin/env bash
# bin/detect <build-dir>
BUILD_DIR=$1
abort() { echo $*; exit 1; }
quit() { echo $*; exit 0; }
[ -f $BUILD_DIR/Gemfile ] || abort fatal: no Ruby app detected
[ -f $BUILD_DIR/config/application.rb ] && quit Ruby/Rails3
[ -f $BUILD_DIR/config/environment.rb ] && quit Ruby/Rails2
[ -f $BUILD_DIR/config.ru ] && quit Ruby/Rack
quit Ruby
#!/usr/bin/env bash
# bin/release <build-dir>
BIN_DIR=$(dirname $0)
BUILD_DIR=$1
NAME=$($BIN_DIR/detect $BUILD_DIR) || { err no Ruby app detected; exit 1; }
cat <<EOF
---
language_pack: $NAME
config_vars:
GEM_PATH: vendor/bundle/ruby/1.9.1
LANG: en_US.UTF-8
PATH: bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV: production
process_types:
web: bundle exec rackup config.ru -p \$PORT
console: bundle exec irb
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment