Skip to content

Instantly share code, notes, and snippets.

@tadas-s
Created March 1, 2023 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadas-s/eab673f237ff5384027bb3e21e641cf9 to your computer and use it in GitHub Desktop.
Save tadas-s/eab673f237ff5384027bb3e21e641cf9 to your computer and use it in GitHub Desktop.
git post-update hook for building Rails app pushed over ssh into a bare VM
#!/usr/bin/sh
project_name="project-name-here"
project_root="${HOME}"
refname=${1}
rev=$(git rev-parse --short ${1})
this_release="${project_root}/${project_name}-${rev}"
mkdir -p ${this_release}
git archive ${refname} | tar -x -C ${this_release}
echo "${project_name}-${rev}" > "${this_release}/.ruby-gemset"
pushd ${this_release}
rvm gemset globalcache enable
rvm-shell -c "gem install bundler"
rvm-shell -c "bundle config set --local without 'development test'"
rvm-shell -c "bundle install"
cp --recursive "${project_root}/${project_name}/public/assets" "${this_release}/public/"
rvm-shell -c "bundle exec rake assets:precompile"
rvm-shell -c "rails assets:clean[5]"
popd
ln -sfn ${this_release} "${project_root}/${project_name}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment