У меня есть похожая настройка, где основная ветвь автоматически развертывается как промежуточная, используя capistrano на git push.Производство развертывается вручную из производственной ветви.
Для настройки требуется, чтобы вы использовали set :deploy_via, :remote_cache
в deploy.rb
, чтобы иметь копию локального кэша на сервере.Это позволяет запускать capistrano с последней конфигурацией, если она была изменена с момента последнего развертывания.
post-receive
сценарий подключения:
#!/bin/bash
while read oldrev newrev ref
do
if [ "$ref" = "refs/heads/master" ] ; then
echo "Master branch pushed, deploying to staging"
# seams to be set to "." for hooks, unset to make things more normal
unset GIT_DIR
# deploy path, where "current", "releases", "shared" etc are
DEPLOYDIR="/home/user/deploy/staging"
# default path for :deploy_via :remote_cache is shared/cached-copy
cd "$DEPLOYDIR/shared/cached-copy"
# update cache to pushed revision, will be done by capistrano too
git fetch origin && git fetch --tags origin && git reset --hard "$newrev"
# load rvm
source ~/.rvm/scripts/rvm
rvm use 1.9.2
# make sure correct gems are installed
# this will also create a .bundle directory
bundle install --gemfile Gemfile --path "$DEPLOYDIR/shared/bundle" --deployment --without development test
# run capistrano
# if you use deploy:migrations instead of deploy you should probably add
# after "deploy:migrations", "deploy:cleanup"
# to your deploy.rb
bundle exec cap staging deploy:migrations
fi
done
Более простая установка без :remote_cache
также возможно, но он будет запускаться capistrano с предыдущей (развернутой) конфигурацией и швы будут немного более хрупкими.
post-receive
hook script:
#!/bin/bash
while read oldrev newrev ref
do
if [ "$ref" = "refs/heads/master" ] ; then
echo "Master branch pushed, deploying to staging"
# seams to be set to "." for hooks, unset to make things more normal
unset GIT_DIR
source ~/.rvm/scripts/rvm
rvm use 1.9.2
cd /home/user/deploy/staging/current && bundle exec cap staging deploy:migrations
fi
done