I’ve setup a post-update hook for my project. I have a bare repository (/var/git/myproject) which I push to, and a live repository (/var/www/myproject) where my app is running. I also included bundle install
and bundle exec rake db:migrate
to install gems and update db.
Below is my post-update hook
#!/bin/bash echo "Pulling changes into Live..." cd /var/www/myproject || exit unset GIT_DIR git pull origin master # check if ruby app if [ -f /var/www/myproject/Gemfile ]; then echo " Ruby app detected..." bundle install --without development test bundle exec rake db:migrate # migrate database fi exec git-update-server-info
When I push my changes though I get the following message (notice the “bundle command not found” error):
martyn@localhost:~/www/myproject$ git push -u origin master martyn@192.168.0.100's password: Counting objects: 832, done. Delta compression using up to 4 threads. Compressing objects: 100% (783/783), done. Writing objects: 100% (832/832), 487.70 KiB, done. Total 832 (delta 434), reused 0 (delta 0) remote: Pulling changes into Live... remote: From /var/git/myproject remote: * branch master -> FETCH_HEAD remote: Ruby app detected... remote: hooks/post-update: line 13: bundle: command not found remote: hooks/post-update: line 14: bundle: command not found To 192.168.24.100:/var/git/myproject.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
Why is bundle not running? I cd
to the live app directory in the script. When I’m in terminal myself and I cd
to the live directory and run bundle install
it works so bundle is there.
Advertisement
Answer
Your hook shell ins’t the same than the one you logged in (and which has the proper PATH
)
You can try using at the beginning your your hook script:
#!/bin/bash -l
(See this answer
The
-l
parameter executes the command in a login shell, which means that it inherits your path and other settings from your shell profile.
)
Or you can make sure your script gets the same environment than your current session, by adding in the first lines of your hook:
$ source $HOME/.bash_profile # single user RVM setup $ source /etc/profile # multi user RVM setup
Or (final alternative) you can add (before calling bundle
) (for a single-user rvm installation)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"