捆绑安装不从我的post-update钩子运行 [英] bundle install not running from my post-update hook
问题描述
我为我的项目设置了更新后的挂钩。我有一个我推送到的裸仓库(/ var / git / myproject)和一个运行我应用程序的实时仓库(/ var / www / myproject)。我还包括 bundle install
和 bundle exec rake db:migrate
来安装gems和更新db。
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
(注意bundle命令未找到错误):
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.
为什么bundle没有运行?我将 cd
添加到脚本中的实时应用程序目录中。当我在终端我自己和我 cd
到实时目录并运行 bundle install
它的工作原理如此捆绑。
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.
推荐答案
您的钩子外壳不会与您登录的外壳相同(并且具有正确的 PATH
)
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
(请参阅此答案
-l </ code>参数在登录shell中执行命令,这意味着它从您的shell配置文件继承了您的路径和其他设置。
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
或者(最终选择)您可以添加(在调用 bundle
)(对于单用户rvm安装)
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"
这篇关于捆绑安装不从我的post-update钩子运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!